diff mbox

[RFC] Check number of uses in simplify_cond_using_ranges().

Message ID 20161103150457.GA11773@linux.vnet.ibm.com
State New
Headers show

Commit Message

Dominik Vogt Nov. 3, 2016, 3:04 p.m. UTC
On Thu, Nov 03, 2016 at 04:03:22PM +0100, Dominik Vogt wrote:
> I've been trying to fix some bad tree-ssa related optimisation for
> s390x and come up with the attached experimental patch.  The patch
> is not really good - it breaks some situations in which the
> optimisation was useful.  With this code:
...

Missing patch attached.

Ciao

Dominik ^_^  ^_^
diff mbox

Patch

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 3c75a0d..e74d935 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -9599,7 +9599,12 @@  simplify_cond_using_ranges (gcond *stmt)
 		 with strict overflow semantics.  */
 	      && ((!is_negative_overflow_infinity (vr->min)
 	           && !is_positive_overflow_infinity (vr->max))
-		  || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (innerop))))
+		  || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (innerop)))
+	      /* If the only use of INNEROP is the cast to OP0, and OP0 is also
+		 used in other places, folding would introduce new uses of the
+		 otherwise dead INNEROP without eliminating OP0, so do not
+		 fold.  */
+	      && (!has_single_use (innerop) || has_single_use (op0)))
 	    {
 	      /* If the range overflowed and the user has asked for warnings
 		 when strict overflow semantics were used to optimize code,