https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71815
Bug ID: 71815 Summary: SLSR misses several PHI candidate cases Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- Derived from gcc.dg/tree-ssa/slsr-3[56].c which fail with code hoisting enabled. int f (int s, int c, int i) { int a1, a3, x1, x3, x; a1 = i * s; x1 = c + a1; i = i + 2; if (x1 > 6) i = i + 2; a3 = i * s; x3 = c + a3; x = x1 + x3; return x; } fails to SLSR properly. With forwprop enabled the conditional i increment gets rewritten to i = i + 4 and i = i + 2 is sunk into the else arm which is handled but in a suboptimal way: <bb 2>: a1_4 = i_2(D) * s_3(D); x1_6 = a1_4 + c_5(D); if (x1_6 > 6) goto <bb 4>; else goto <bb 3>; <bb 3>: i_7 = i_2(D) + 2; slsr_16 = s_3(D) * 2; slsr_14 = a1_4 + slsr_16; goto <bb 5>; <bb 4>: i_8 = i_2(D) + 4; slsr_15 = s_3(D) * 4; slsr_13 = a1_4 + slsr_15; <bb 5>: # i_1 = PHI <i_7(3), i_8(4)> # slsr_17 = PHI <slsr_14(3), slsr_13(4)> a3_9 = slsr_17; x3_10 = c_5(D) + a3_9; x_11 = x1_6 + x3_10; return x_11; when code-hoisting is enabled on gcc.dg/tree-ssa/slsr-3[56].c we get the same effect as with -fno-tree-forwprop on the above testcase - the increment after the if gets hoisted before it, and slsr fails: <bb 2>: a1_4 = i_2(D) * s_3(D); x1_6 = c_5(D) + a1_4; i_7 = i_2(D) + 2; if (x1_6 > 6) goto <bb 3>; else goto <bb 4>; <bb 3>: i_8 = i_7 + 2; slsr_16 = s_3(D) * 4; <bb 4>: # i_1 = PHI <i_7(2), i_8(3)> a3_9 = i_1 * s_3(D); x3_10 = c_5(D) + a3_9; x_11 = x1_6 + x3_10; return x_11;