diff mbox

Fix PR62175, avoid trapping expressions in niters

Message ID alpine.LSU.2.11.1408211304360.20733@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Aug. 21, 2014, 11:06 a.m. UTC
This fixes PR62175 by avoiding trapping expressions in niter
results.  If those appear inside conditionals that are later
re-gimplified the gimplifier will ICE (because it thinks it
has to create control-flow).

Now it seems we should use un-expanded expressions for
code-generation (we use expanded form to eventually simplify
the expression).  But that's an optimization and for another day.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2014-08-21  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/62175
	* tree-ssa-loop-niter.c (expand_simple_operations): Do not
	expand possibly trapping operations.

	* g++.dg/torture/pr62175.C: New testcase.
diff mbox

Patch

Index: gcc/tree-ssa-loop-niter.c
===================================================================
--- gcc/tree-ssa-loop-niter.c	(revision 214258)
+++ gcc/tree-ssa-loop-niter.c	(working copy)
@@ -1633,6 +1633,9 @@  expand_simple_operations (tree expr)
 
     case PLUS_EXPR:
     case MINUS_EXPR:
+      if (TYPE_OVERFLOW_TRAPS (TREE_TYPE (expr)))
+	return expr;
+      /* Fallthru.  */
     case POINTER_PLUS_EXPR:
       /* And increments and decrements by a constant are simple.  */
       e1 = gimple_assign_rhs2 (stmt);
Index: gcc/testsuite/g++.dg/torture/pr62175.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr62175.C	(revision 0)
+++ gcc/testsuite/g++.dg/torture/pr62175.C	(working copy)
@@ -0,0 +1,36 @@ 
+// { dg-do compile }
+// { dg-additional-options "-ftrapv" }
+
+struct B {
+    B(int = 0);
+};
+int c;
+int *d;
+struct G {
+    G();
+    int numProcs_;
+};
+int fn1();
+B fn2() {
+    if (c)
+      return 0;
+    return B();
+}
+
+long &fn3(long &p1, long &p2) {
+    if (p2 < p1)
+      return p2;
+    return p1;
+}
+
+void fn4(long p1) {
+    long a = fn1();
+    fn2();
+    int b = fn3(p1, a);
+    for (int i; i < b; ++i)
+      d[0] = 0;
+    for (; a < p1; ++a)
+      d[a] = 0;
+}
+
+G::G() { fn4(numProcs_ + 1); }