re PR tree-optimization/88301 (Optimization regression with undefined unsigned overflow)
authorRichard Biener <rguenther@suse.de>
Tue, 4 Dec 2018 11:26:14 +0000 (11:26 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 4 Dec 2018 11:26:14 +0000 (11:26 +0000)
2018-12-04  Richard Biener  <rguenther@suse.de>

PR tree-optimization/88301
* tree-vrp.c (register_edge_assert_for_2): Fix sign-conversion
issues in last commit.

From-SVN: r266773

gcc/ChangeLog
gcc/tree-vrp.c

index 335caf63854043fb88fa4f00761759ff8e1e1af2..4bb7187ceb2a30492583b20a73efcebecfd2a45c 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-04  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/88301
+       * tree-vrp.c (register_edge_assert_for_2): Fix sign-conversion
+       issues in last commit.
+
 2018-12-04  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/88315
index b00eca87c82f018789dd28d9af5f7c34469ebf4a..6fd1fd26eefa2758de1882f159ffea7400e40737 100644 (file)
@@ -2973,6 +2973,21 @@ register_edge_assert_for_2 (tree name, edge e,
          wide_int rmin, rmax;
          tree rhs1 = gimple_assign_rhs1 (def_stmt);
          if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
+             /* Make sure the relation preserves the upper/lower boundary of
+                the range conservatively.  */
+             && (comp_code == NE_EXPR
+                 || comp_code == EQ_EXPR
+                 || (TYPE_SIGN (TREE_TYPE (name))
+                     == TYPE_SIGN (TREE_TYPE (rhs1)))
+                 || ((comp_code == LE_EXPR
+                      || comp_code == LT_EXPR)
+                     && !TYPE_UNSIGNED (TREE_TYPE (rhs1)))
+                 || ((comp_code == GE_EXPR
+                      || comp_code == GT_EXPR)
+                     && TYPE_UNSIGNED (TREE_TYPE (rhs1))))
+             /* And the conversion does not alter the value we compare
+                against and all values in rhs1 can be represented in
+                the converted to type.  */
              && int_fits_type_p (val, TREE_TYPE (rhs1))
              && ((TYPE_PRECISION (TREE_TYPE (name))
                   > TYPE_PRECISION (TREE_TYPE (rhs1)))