PR60733 identifies a case where straight-line strength reduction produces code that doesn't satisfy SSA verification. For a PHI candidate, the insertion of an initializer for a stride calculation along an incoming arc was specified to be at the point of the feeding definition of the PHI along that arc. This is wrong and can place the initializer far earlier than its operands are guaranteed to be available. In this case, the initializer was placed earlier in the block than the definition of one of its operands.
In fact, the initializer is only needed at the end of the feeding block for the PHI argument, and its operands are guaranteed to be available at that point. This patch changes the placement of the initializer to this location for PHI candidates. The nearest common dominator algorithm may still place the initializer at an earlier point, but only if it is safe to do so. Bootstrapped and tested on powerpc64-unknown-linux-gnu with no new regressions; committed. Thanks, Bill [gcc] 2014-04-02 Bill Schmidt <wschm...@linux.vnet.ibm.com> PR tree-optimization/60733 * gimple-ssa-strength-reduction.c (ncd_with_phi): Change required insertion point for PHI candidates to be the end of the feeding block for the PHI argument. [gcc/testsuite] 2014-04-02 Bill Schmidt <wschm...@linux.vnet.ibm.com> PR tree-optimization/60733 * gcc.dg/torture/pr60733.c: New test. Index: gcc/testsuite/gcc.dg/torture/pr60733.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr60733.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr60733.c (revision 0) @@ -0,0 +1,36 @@ +/* { dg-do run } */ + +int a, d, e, f, g, h, i, j, k; +unsigned short b; + +short +fn1 (int p1, int p2) +{ + return p1 * p2; +} + +int +main () +{ + for (; a; a--) + { + int l = 0; + if (f >= 0) + { + for (; h;) + e = 0; + for (; l != -6; l--) + { + j = fn1 (b--, d); + for (g = 0; g; g = 1) + ; + k = e ? 2 : 0; + } + i = 0; + for (;;) + ; + } + } + d = 0; + return 0; +} Index: gcc/gimple-ssa-strength-reduction.c =================================================================== --- gcc/gimple-ssa-strength-reduction.c (revision 209023) +++ gcc/gimple-ssa-strength-reduction.c (working copy) @@ -3001,10 +3001,10 @@ ncd_with_phi (slsr_cand_t c, double_int incr, gimp { slsr_cand_t arg_cand = base_cand_from_table (arg); double_int diff = arg_cand->index - basis->index; + basic_block pred = gimple_phi_arg_edge (phi, i)->src; if ((incr == diff) || (!address_arithmetic_p && incr == -diff)) - ncd = ncd_for_two_cands (ncd, gimple_bb (arg_cand->cand_stmt), - *where, arg_cand, where); + ncd = ncd_for_two_cands (ncd, pred, *where, NULL, where); } } }