https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64081
--- Comment #54 from Segher Boessenkool <segher at gcc dot gnu.org> --- Thanks Aldy, this makes it clear what happens, and it is actually pretty simple. The patch changes check_simple_exit to also return true if check_complex_exit is true (as well as some other conditions). But the call in doloop_optimize (via get_simple_loop_desc) really does need to check for only simple exits. With the patch, the loop in the testcase gets one of its two identical exits replaced by a doloop pattern, which is incorrect (replacing both would work in this case though).