re PR tree-optimization/88301 (Optimization regression with undefined unsigned overflow)
authorRichard Biener <rguenther@suse.de>
Mon, 3 Dec 2018 13:38:20 +0000 (13:38 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 3 Dec 2018 13:38:20 +0000 (13:38 +0000)
2018-12-03  Richard Biener  <rguenther@suse.de>

PR tree-optimization/88301
* tree-vrp.c (register_edge_assert_for_2): Handle conversions
that do not change the value by registering the same assert
for the operand.

* gcc.dg/tree-ssa/evrp13.c: New testcase.

From-SVN: r266739

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/evrp13.c [new file with mode: 0644]
gcc/tree-vrp.c

index 9f00aff51d9d39eac97d4e83788fd77641bc836f..626e70239e3131f1d699035ac2c23ba43f965e5f 100644 (file)
@@ -1,3 +1,10 @@
+2018-12-03  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/88301
+       * tree-vrp.c (register_edge_assert_for_2): Handle conversions
+       that do not change the value by registering the same assert
+       for the operand.
+
 2018-12-03  Richard Biener  <rguenther@suse.de>
 
        * tree-vect-loop.c (vect_transform_loop): Properly compute
index 2032b88ab673b38927b8510516056435be4f8027..f38b209ff075893fb22f0f3f3de58f7d62ba1acd 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-03  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/88301
+       * gcc.dg/tree-ssa/evrp13.c: New testcase.
+
 2018-12-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/71109
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp13.c b/gcc/testsuite/gcc.dg/tree-ssa/evrp13.c
new file mode 100644 (file)
index 0000000..cfa4e82
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+#define ADD_NW(A,B) (__extension__({ __typeof(A+B) R; if(__builtin_add_overflow(A,B,&R)) __builtin_unreachable(); R ;}))
+_Bool a_b2(unsigned A,  unsigned B) { return ADD_NW(A,B) >= B; }
+
+/* { dg-final { scan-tree-dump "return 1;" "evrp" } } */
index aa6309e9e7bd11cfead244f8317cdf9c1afba27f..b00eca87c82f018789dd28d9af5f7c34469ebf4a 100644 (file)
@@ -2966,6 +2966,23 @@ register_edge_assert_for_2 (tree name, edge e,
            add_assert_info (asserts, name2, tmp, new_comp_code, new_val);
        }
 
+      /* If we have a conversion that doesn't change the value of the source
+         simply register the same assert for it.  */
+      if (CONVERT_EXPR_CODE_P (rhs_code))
+       {
+         wide_int rmin, rmax;
+         tree rhs1 = gimple_assign_rhs1 (def_stmt);
+         if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
+             && int_fits_type_p (val, TREE_TYPE (rhs1))
+             && ((TYPE_PRECISION (TREE_TYPE (name))
+                  > TYPE_PRECISION (TREE_TYPE (rhs1)))
+                 || (get_range_info (rhs1, &rmin, &rmax) == VR_RANGE
+                     && wi::fits_to_tree_p (rmin, TREE_TYPE (name))
+                     && wi::fits_to_tree_p (rmax, TREE_TYPE (name)))))
+           add_assert_info (asserts, rhs1, rhs1,
+                            comp_code, fold_convert (TREE_TYPE (rhs1), val));
+       }
+
       /* Add asserts for NAME cmp CST and NAME being defined as
         NAME = NAME2 & CST2.