]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR102563] Do not clobber range in operator_lshift::op1_range.
authorAldy Hernandez <aldyh@redhat.com>
Sat, 2 Oct 2021 14:59:26 +0000 (16:59 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Sat, 2 Oct 2021 19:50:45 +0000 (21:50 +0200)
We're clobbering the final range before we're done calculating it.

Tested on x86-64 Linux.

gcc/ChangeLog:

PR tree-optimization/102563
* range-op.cc (operator_lshift::op1_range): Do not clobber
range.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr102563.c: New test.

gcc/range-op.cc
gcc/testsuite/gcc.dg/tree-ssa/pr102563.c [new file with mode: 0644]

index 2baca4a197f3a6df1bd6d751741b7e7514e7d6e1..bbf2924f8157645e34ab80098d5ba8437eb1256e 100644 (file)
@@ -2112,8 +2112,6 @@ operator_lshift::op1_range (irange &r,
       else
        op_rshift.fold_range (tmp_range, utype, lhs, op2);
 
-      r.intersect (tmp_range);
-
       // Start with ranges which can produce the LHS by right shifting the
       // result by the shift amount.
       // ie   [0x08, 0xF0] = op1 << 2 will start with
@@ -2128,13 +2126,15 @@ operator_lshift::op1_range (irange &r,
       unsigned low_bits = TYPE_PRECISION (utype)
                          - TREE_INT_CST_LOW (shift_amount);
       wide_int up_mask = wi::mask (low_bits, true, TYPE_PRECISION (utype));
-      wide_int new_ub = wi::bit_or (up_mask, r.upper_bound ());
-      wide_int new_lb = wi::set_bit (r.lower_bound (), low_bits);
+      wide_int new_ub = wi::bit_or (up_mask, tmp_range.upper_bound ());
+      wide_int new_lb = wi::set_bit (tmp_range.lower_bound (), low_bits);
       int_range<2> fill_range (utype, new_lb, new_ub);
-      r.union_ (fill_range);
+      tmp_range.union_ (fill_range);
 
       if (utype != type)
-       range_cast (r, type);
+       range_cast (tmp_range, type);
+
+      r.intersect (tmp_range);
       return true;
     }
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr102563.c b/gcc/testsuite/gcc.dg/tree-ssa/pr102563.c
new file mode 100644 (file)
index 0000000..8871dff
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-O2 -w" }
+
+int _bdf_parse_glyphs_bp;
+long _bdf_parse_glyphs_nibbles;
+
+void _bdf_parse_glyphs_p() 
+{
+  long p_2;
+
+  _bdf_parse_glyphs_nibbles = p_2 << 1;
+
+  for (; 0 < _bdf_parse_glyphs_nibbles;)
+    if (1 < _bdf_parse_glyphs_nibbles)
+      _bdf_parse_glyphs_bp = _bdf_parse_glyphs_p;
+}