https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104196
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> --- The above patch unfortunately causes ICE on -O2: int a, b, c; void foo (void) { if (!c && !b) a |= 1; } optimize_range_tests_cmp_bitwise in that case wants to optimize the: <bb 2> [local count: 1073741824]: c.0_1 = c; if (c.0_1 == 0) goto <bb 3>; [50.00%] else goto <bb 5>; [50.00%] <bb 3> [local count: 536870913]: b.1_2 = b; if (b.1_2 == 0) goto <bb 4>; [50.00%] else goto <bb 5>; [50.00%] <bb 4> [local count: 268435456]: into c.0_1 = c; b.1_2 = b; _8 = b.1_2 | c.0_1; _9 = _8 == 0; if (_9 != 0) and has a seq argument with that _8 = c.0_1 | b.1_2; in it. But it depends on b.1_2 so has to be done only in the spot of the second comparison and not the first one. So, I think we need to check if exp's SSA_NAME_DEF_STMT if any or any SSA_NAME's SSA_NAME_DEF_STMT for SSA_NAMEs mentioned in seq isn't reassoc_stmt_dominates_stmt_p by the stmt we are considering doing it at. If it isn't, we can do what the patch does, otherwise should do what we were doing before but with extra verification if there could be any UB in between.