diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-01-30 21:28:17 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-01-30 21:28:17 +0100 |
commit | 56b92750f83724177d2c6eae30c208e935a56a37 (patch) | |
tree | 4442d994ad2a140f6904ede7a42d02c80a07ddcc /gcc/testsuite/gcc.c-torture | |
parent | 4dd468a042e19ef0fdbb1c53ca4060d4cb4972c5 (diff) |
combine: Punt on out of range rotate counts [PR93505]
What happens on this testcase is with the out of bounds rotate we get:
Trying 13 -> 16:
13: r129:SI=r132:DI#0<-<0x20
REG_DEAD r132:DI
16: r123:DI=r129:SI<0
REG_DEAD r129:SI
Successfully matched this instruction:
(set (reg/v:DI 123 [ <retval> ])
(const_int 0 [0]))
during combine. So, perhaps we could also change simplify-rtx.c to punt
if it is out of bounds rather than trying to optimize anything.
Or, but probably GCC11 material, if we decide that ROTATE/ROTATERT doesn't
have out of bounds counts or introduce targetm.rotate_truncation_mask,
we should truncate the argument instead of punting.
Punting is better for backports though.
2020-01-30 Jakub Jelinek <jakub@redhat.com>
PR middle-end/93505
* combine.c (simplify_comparison) <case ROTATE>: Punt on out of range
rotate counts.
* gcc.c-torture/compile/pr93505.c: New test.
Diffstat (limited to 'gcc/testsuite/gcc.c-torture')
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr93505.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93505.c b/gcc/testsuite/gcc.c-torture/compile/pr93505.c new file mode 100644 index 00000000000..0627962eae5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr93505.c @@ -0,0 +1,15 @@ +/* PR middle-end/93505 */ + +unsigned a; + +unsigned +foo (unsigned x) +{ + unsigned int y = 32 - __builtin_bswap64 (-a); + /* This would be UB (x << 32) at runtime. Ensure we don't + invoke UB in the compiler because of that (visible with + bootstrap-ubsan). */ + x = x << y | x >> (-y & 31); + x >>= 31; + return x; +} |