https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105198
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- So before pcom we have <bb 2> [local count: 114863530]: j_29 = k_28(D) + -1; _1 = (long unsigned int) j_29; _2 = _1 * 4; _3 = x_30(D) + _2; _4 = *_3; _5 = _4 + 1; *_3 = _5; if (j_29 > 0) goto <bb 11>; [94.50%] <bb 11> [local count: 108546036]: <bb 3> [local count: 1014686026]: # j_40 = PHI <j_34(12), j_29(11)> # tmp_39 = PHI <_17(12), _4(11)> _6 = (long unsigned int) j_40; _7 = _6 * 4; _8 = x_30(D) + _7; _9 = *_8; _11 = j_29 - j_40; _12 = n_33(D) - _11; if (_9 < _12) goto <bb 14>; [5.50%] else goto <bb 4>; [94.50%] and pcom replaces the _9 load like the following: <bb 3> [local count: 1014686026]: # j_40 = PHI <j_34(12), j_29(11)> # D__lsm0.5_25 = PHI <D__lsm0.5_18(12), _4(11)> tmp_39 = D__lsm0.5_25; _6 = (long unsigned int) j_40; _7 = _6 * 4; _8 = x_30(D) + _7; _9 = D__lsm0.5_25; _11 = j_29 - j_40; _12 = n_33(D) - _11; if (_9 < _12) goto <bb 14>; [5.50%] else goto <bb 4>; [94.50%] but that fails to realize that while _4 loads from the same address, the *_3 = _5 store clobbers the value. So with pcom applied we exit the loop immediately at the x[j] < n - (k - 1 -j)) test because we use the wrong loop entry value for x[j]. It somehow gets derailed to use 'tmp' here (it doesn't actually even analyze the load/store in BB2). So it's probably wrong in determining Store-loads chain 0x3410a90 max distance 1, may reuse first inits _4 references: *_15 (id 2, write) offset -1 distance 0 looparound ref in statement tmp_39 = PHI <_17(12), _4(11)> distance 1 *_8 (id 0) offset 0 distance 1 in particular identifying the looparound ref which is only partly a looparund ref (the initial value isn't). Indeed, prepare_initializers_chain simply does /* If we have replaced some looparound phi nodes, use their initializers instead of creating our own. */ FOR_EACH_VEC_ELT (chain->refs, i, laref) { if (gimple_code (laref->stmt) != GIMPLE_PHI) continue; gcc_assert (laref->distance > 0); chain->inits[n - laref->distance] = PHI_ARG_DEF_FROM_EDGE (laref->stmt, entry); } which would be OK, but find_looparound_phi simply looks at the def of the loop entry value and matches it up with the chain, not considering intermediate clobbering stmts.