https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85551

--- Comment #2 from Allan Jensen <linux at carewolf dot com> ---
Hmm.. I appear to have made unsafe assumptions in the mod_opt cases.

The first safe optimization version would then be:
void mod_opt(int *a, int count, int stride, unsigned width)
{
    int pos_opt = 0;
    for (int i = 0; i < count; ++i) {
        if (pos_opt < 0 || pos_opt >= width)
            pos_opt = pos_opt % width;
        a[i] = pos_opt;
        pos_opt += stride;
    }
}

To be able to completely get rid of modulo, you need to know or check for the
size of stride compared to width.

Reply via email to