https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72772
Bug ID: 72772 Summary: Missed SCEV after pass reordering@236440 Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: amker at gcc dot gnu.org Target Milestone: --- For below case int foo (int flag, char *a) { short i, j; short l = 0; if (flag == 1) l = 3; for (i = 0; i < 4; i++) { for (j = l - 1; j > 0; j--) a[j] = a[j - 1]; a[0] = i; } } GCC can't recognize &a[j]/&a[j-1] as SCEVs after pass reordering @commit: commit 410372fef14173261ce8e547db98eafb3174921f Author: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Thu May 19 07:39:52 2016 +0000 2016-05-19 Richard Biener <rguent...@suse.de> PR tree-optimization/70729 * passes.def: Move LIM pass before PRE. Remove no longer required copyprop and move first DCE out of the loop pipeline. * gcc.dg/autopar/outer-6.c: Adjust to avoid redundant store. * gcc.dg/graphite/scop-18.c: Likewise. * gcc.dg/pr41783.c: Disable LIM. * gcc.dg/tree-ssa/loadpre10.c: Likewise. * gcc.dg/tree-ssa/loadpre23.c: Likewise. * gcc.dg/tree-ssa/loadpre24.c: Likewise. * gcc.dg/tree-ssa/loadpre25.c: Likewise. * gcc.dg/tree-ssa/loadpre4.c: Likewise. * gcc.dg/tree-ssa/loadpre8.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-16.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-18.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-20.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-3.c: Likewise. * gfortran.dg/pr42108.f90: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@236440 138bc75d-0d04-0410-961f-82ee72b054a4 This is because of changed IR, from: Loop_guard: if (prephitmp_41 > 0) goto <bb 8>; else goto <bb 6>; Preheader: <bb 8>: Loop: <bb 9>: # j_29 = PHI <prephitmp_41(8), j_23(11)> _3 = (sizetype) j_29; _4 = a_21(D) + _3; _5 = _3 + 18446744073709551615; _6 = a_21(D) + _5; _7 = *_6; *_4 = _7; j.2_8 = (unsigned short) j_29; _9 = j.2_8 + 65535; j_23 = (short int) _9; if (j_23 > 0) goto <bb 11>; else goto <bb 10>; Latch: <bb 11>: goto <bb 9>; To: Loop_guard: if (prephitmp_43 > 0) goto <bb 6>; else goto <bb 10>; Preheader: <bb 6>: # j_16 = PHI <prephitmp_43(5)> Loop: <bb 7>: # j_29 = PHI <j_16(6), j_23(8)> _3 = (sizetype) j_29; _4 = a_21(D) + _3; _5 = _3 + 18446744073709551615; _6 = a_21(D) + _5; _7 = *_6; *_4 = _7; j.2_8 = (unsigned short) j_29; _9 = j.2_8 + 65535; j_23 = (short int) _9; if (j_23 > 0) goto <bb 8>; else goto <bb 9>; Latch: <bb 8>: goto <bb 7>; Specifically, simplif_using_initial_conditions failed in this case because it missed expanding simple operations in single-arg PHI in preheader.