https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104639
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- One thing is not threading through loop latches, but in this case once the loop is optimized into straight line code in thread2 we don't thread that further, so end up with if (i_2(D) == 4) goto <bb 4>; [97.00%] else goto <bb 3>; [3.00%] <bb 3> [local count: 3540129]: <bb 4> [local count: 118111600]: # i_6 = PHI <i_2(D)(3), 6(2)> _3 = i_6 != 0; return _3; For the result, the i_6 = i_2(D) == 4 ? 6 : i_2(D); is equivalent to just i_2(D) because we only care whether it is non-zero and both 4 and 6 are non-zero.