[backport proposed but not yet applied 4.9/trunk patch for PR57214 regression from PR56982 ] List-Archive: Date: Fri, 10 May 2013 10:34:37 +0200 (CEST) From: Richard Biener Subject: [PATCH] Fix PR57214 This fixes PR57214 - the simple constant propagation pass we perform over unrolled loop bodies does not properly avoid propagating across abnormal edges. Bootstrap & regtest running on x86_64-unknown-linux-gnu, I'll install this on trunk and the 4.8 branch where the bug is latent. Richard. 2013-05-10 Richard Biener PR tree-optimization/57214 * tree-ssa-loop-ivcanon.c (propagate_constants_for_unrolling): Do not propagate from SSA names that occur in abnormal PHI nodes. --- gcc-4.8.0/gcc/testsuite/gcc.dg/torture/pr57214.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.8.0/gcc/testsuite/gcc.dg/torture/pr57214.c 2013-05-10 12:44:36.262956885 +0200 @@ -0,0 +1,25 @@ +/* { dg-do compile } */ + +extern int baz (void); +extern int foo (void) __attribute__ ((returns_twice)); + +void +bar (_Bool b) +{ + int buf[1]; + while (1) + { + _Bool x = 1; + if (b) + baz (); + b = 1; + baz (); + x = 0; + int i; + while (buf[i] && i) + i++; + foo (); + if (!x) + b = 0; + } +} --- gcc-4.8.0/gcc/tree-ssa-loop-ivcanon.c.~1~ 2013-03-01 23:56:18.000000000 +0100 +++ gcc-4.8.0/gcc/tree-ssa-loop-ivcanon.c 2013-05-10 12:44:36.262956885 +0200 @@ -1085,8 +1085,9 @@ propagate_constants_for_unrolling (basic tree lhs; if (is_gimple_assign (stmt) + && gimple_assign_rhs_code (stmt) == INTEGER_CST && (lhs = gimple_assign_lhs (stmt), TREE_CODE (lhs) == SSA_NAME) - && gimple_assign_rhs_code (stmt) == INTEGER_CST) + && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs)) { propagate_into_all_uses (lhs, gimple_assign_rhs1 (stmt)); gsi_remove (&gsi, true);