diff mbox series

Fix miscompiles with latest VRP change

Message ID alpine.LSU.2.20.1812041224100.1827@zhemvz.fhfr.qr
State New
Headers show
Series Fix miscompiles with latest VRP change | expand

Commit Message

Richard Biener Dec. 4, 2018, 11:25 a.m. UTC
Jeff noticed that some dfp stuff was miscompiled.  I appearantly
didn't notice the new assert registering isn't guarded by
EQ/NE_EXPR thus the following makes it fancy.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

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.
diff mbox series

Patch

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index b00eca87c82..c01ae591511 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -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)))