https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101250
Bug ID: 101250 Summary: adjust_iv_update_pos update the iv statement unexpectedly cause memory address offset mismatch Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: luoxhu at gcc dot gnu.org Target Milestone: --- Test case: unsigned int foo (unsigned char *ip, unsigned char *ref, unsigned int maxlen) { unsigned int len = 2; do { len++; }while(len < maxlen && ip[len] == ref[len]); return len; } ivopts: <bb 4> [local count: 1014686026]: _3 = MEM[(unsigned char *)ip_10(D) + ivtmp.16_15 * 1]; ivtmp.16_16 = ivtmp.16_15 + 1; _19 = ref_12(D) + 18446744073709551615; _6 = MEM[(unsigned char *)_19 + ivtmp.16_16 * 1]; if (_3 == _6) goto <bb 6>; [94.50%] else goto <bb 10>; [5.50%] Disable adjust_iv_update_pos will produce: <bb 4> [local count: 1014686026]: _3 = MEM[(unsigned char *)ip_10(D) + ivtmp.16_15 * 1]; _6 = MEM[(unsigned char *)ref_12(D) + ivtmp.16_15 * 1]; ivtmp.16_16 = ivtmp.16_15 + 1; if (_3 == _6) goto <bb 6>; [94.50%] else goto <bb 10>; [5.50%] discussions: https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573709.html