aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2020-10-19 06:18:46 -0400
committerAldy Hernandez <aldyh@redhat.com>2020-10-19 08:34:01 -0400
commit2d2f4ffc97a8510e72a99ee106159aeae2627a42 (patch)
tree0efeb2ede672aeaa79841811a21a8439a2882fe2
parent11b8cca0831ee37cc534ff27cd8d32ac5aace6f7 (diff)
downloadgcc-2d2f4ffc97a8510e72a99ee106159aeae2627a42.zip
gcc-2d2f4ffc97a8510e72a99ee106159aeae2627a42.tar.gz
gcc-2d2f4ffc97a8510e72a99ee106159aeae2627a42.tar.bz2
Gracefully handle right shifts larger than the precision.
gcc/ChangeLog: PR tree-optimization/97488 * range-op.cc (operator_lshift::op1_range): Handle large right shifts. gcc/testsuite/ChangeLog: * gcc.dg/pr97488.c: New test.
-rw-r--r--gcc/range-op.cc4
-rw-r--r--gcc/testsuite/gcc.dg/pr97488.c11
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 30d2a4d..21d98de 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1579,6 +1579,10 @@ operator_lshift::op1_range (irange &r,
wide_int shift = wi::to_wide (shift_amount);
if (wi::lt_p (shift, 0, SIGNED))
return false;
+ if (wi::ge_p (shift, wi::uhwi (TYPE_PRECISION (type),
+ TYPE_PRECISION (op2.type ())),
+ UNSIGNED))
+ return false;
if (shift == 0)
{
r = lhs;
diff --git a/gcc/testsuite/gcc.dg/pr97488.c b/gcc/testsuite/gcc.dg/pr97488.c
new file mode 100644
index 0000000..96dc33c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97488.c
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// { dg-options "-O1 -ftree-vrp" }
+
+__int128
+ef (__int128 ms)
+{
+ int dh = 129;
+ int *hj = &dh;
+
+ return ms << *hj ? ms : 0;
+}