[Bug tree-optimization/87505] Vectorizer generates a lot of code for a small loop

2018-10-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87505

--- Comment #3 from Richard Biener  ---
Both making i std::size_t or casting (base + 4) to int "fixes" this.

[Bug tree-optimization/87505] Vectorizer generates a lot of code for a small loop

2018-10-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87505

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 CC||rguenth at gcc dot gnu.org
 Resolution|--- |INVALID

--- Comment #2 from Richard Biener  ---
Hmm, we compute the loop iterates

((long unsigned int) base_9(D) - (long unsigned int) (int) base_9(D)) + 3

times.  You can probably spot the cases of INT_MAX < base < UINT_MAX
not iterating at all (i is sign-extended to std::size_t for the comparison)
and base > UINT_MAX where it iterates quite a lot (eventually).

We have to account for these cases.  If you make the suggested adjustment
then of course we know the loop always iterates 4 times.

Unless I missed something of course.

[Bug tree-optimization/87505] Vectorizer generates a lot of code for a small loop

2018-10-03 Thread amonakov at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87505

Alexander Monakov  changed:

   What|Removed |Added

 CC||amonakov at gcc dot gnu.org

--- Comment #1 from Alexander Monakov  ---
This is because 'i' is int while 'base' is size_t. Loop init expression 'int i
= base' truncates base to 32 bits, and loop condition first converts i to
size_t and then compares in that unsigned type. It's not exactly obvious how
many iterations this loop has :)

Using the proper type for 'i' results in reasonable code.

Perhaps in principle niter analysis could handle this anyway?