tree-optimization/110838 - vectorization of widened shifts
commit29370f1387274ad5a35a020db6a5d06c0324e6c1
authorRichard Biener <rguenther@suse.de>
Mon, 31 Jul 2023 12:44:52 +0000 (31 14:44 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 3 Aug 2023 12:52:11 +0000 (3 14:52 +0200)
treee4810a4d72a3a5f89e55383039c607206261131f
parent13dfb01e5c30c3bd09333ac79d6ff96a617fea67
tree-optimization/110838 - vectorization of widened shifts

The following makes sure to limit the shift operand when vectorizing
(short)((int)x >> 31) via (short)x >> 31 as the out of bounds shift
operand otherwise invokes undefined behavior.  When we determine
whether we can demote the operand we know we at most shift in the
sign bit so we can adjust the shift amount.

Note this has the possibility of un-CSEing common shift operands
as there's no good way to share pattern stmts between patterns.
We'd have to separately pattern recognize the definition.

PR tree-optimization/110838
* tree-vect-patterns.cc (vect_recog_over_widening_pattern):
Adjust the shift operand of RSHIFT_EXPRs.

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