[Bug rtl-optimization/85551] No strength reduction of modulo and integer vision

2018-04-27 Thread linux at carewolf dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85551

--- Comment #2 from Allan Jensen  ---
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.

[Bug rtl-optimization/85551] No strength reduction of modulo and integer vision

2018-04-27 Thread linux at carewolf dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85551

--- Comment #1 from Allan Jensen  ---
I also stumbled on this old motivating article when I tried googling the
concept: http://publications.csail.mit.edu/lcs/pubs/pdf/MIT-LCS-TM-600.pdf