https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102794
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Aldy Hernandez from comment #2) > I haven't looked at this, but there's a pending patch with more > restrictions for loop threading in the presence of loops. Does this help? > > https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581637.html > > We really shouldn't be destroying loop info. Yes I think it does, though I have not tried it. There was a jump threading here: <bb 4> : if (d_10 != 0) goto <bb 5>; [INV] else goto <bb 6>; [INV] <bb 5> : foo (); <bb 6> : a_12 = a_3 + 1; <bb 7> : ;;; loop header # a_3 = PHI <-100(2), a_12(6)> if (a_3 != 0) goto <bb 3>; [INV] else goto <bb 8>; [INV] where d_10 is defined as: d_10 = (short unsigned int) a_3; So yes blocking jumping through the loop header would help. It is very similar to your f3 in ssa-thread-invalid.c testcase.