https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105142
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- Created attachment 52745 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52745&action=edit avoid combining the conditions Like this prototype which fixes the testcase and avoids combining from stmts defined in the middle BB. It could be enhanced by only considering not combining from stmts with undefined overflow behavior (or flow-sensitive info). This patch is also incomplete, maybe_fold_and_comparisons and maybe_fold_or_comparisons is used by if-conversion, ifcombine and reassoc and more importantly through recursion with itself and related simplifications in gimple-fold.cc. It's not clear where to extract the context BB from and I didn't follow all the flow through the various routines. Esp. if-conversion looks susceptible, reassoc might restrict itself to conditions from the same BB, not sure.