tree-optimization/112736 - avoid overread with non-grouped SLP load
commit6d0b0806eb638447c3184c59d996c2f178553d45
authorRichard Biener <rguenther@suse.de>
Mon, 11 Dec 2023 13:39:48 +0000 (11 14:39 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 12 Dec 2023 14:25:25 +0000 (12 15:25 +0100)
tree0817faa5aa47b3ce75d4e8ca91a39778c93282b8
parenteee13a3730bd1d7aa7b40687b1ee49c17d95159f
tree-optimization/112736 - avoid overread with non-grouped SLP load

The following aovids over/under-read of storage when vectorizing
a non-grouped load with SLP.  Instead of forcing peeling for gaps
use a smaller load for the last vector which might access excess
elements.  This builds upon the existing optimization avoiding
peeling for gaps, generalizing it to all gap widths leaving a
power-of-two remaining number of elements (but it doesn't replace
or improve that particular case at this point).

I wonder if the poly relational compares I set up are good enough
to guarantee /* remain should now be > 0 and < nunits.  */.

There is existing test coverage that runs into /* DR will be unused.  */
always when the gap is wider than nunits.  Compared to the
existing gap == nunits/2 case this only adjusts the load that will
cause the overrun at the end, not every load.  Apart from the
poly relational compares it should reliably cover these cases but
I'll leave it for stage1 to remove.

PR tree-optimization/112736
* tree-vect-stmts.cc (vectorizable_load): Extend optimization
to avoid peeling for gaps to handle single-element non-groups
we now allow with SLP.

* gcc.dg/torture/pr112736.c: New testcase.
gcc/testsuite/gcc.dg/torture/pr112736.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc