https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112310
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Hm. It's more complicated, we cannot keep the intersection of expressions here as seen by the added testcase int foo (int flag, int * __restrict a, int * __restrict b) { int res; if (flag) res = *a + *b; else { res = *a; *a = 1; res += *b; } return res; } here we expect to hoist the *a and *b load and the addition. But while we can make the loads have the same expression, the adds will inevitably differ as we do not have valueized operands there. So what happens is that we have multiple expressions for the same value we'd like to hoist, and currently by r14-1161-g5476de2618f we're picking the "first". For the case in this PR it's the "wrong" one, but we can't easily decide which one is correct. For the bug we have {nop_expr,iftmp.1_43} (0028) and {mult_expr,p.5_7,2022160547} (0028) where the first depends on {mult_expr,_4,2022160547} (0033) and the second depends on {nop_expr,_4} (0007) - both are not values we intended to hoist but we'd generate them anyway via create_expression_by_pieces. So instead of forcing the expressions to be the same on all paths as it was before r14-1161-g5476de2618f we can go and check whether the resulting set of expressions to hoist is self-consistent, in that it contains all dependent expressions we'd have to hoist. That also ensures we can truly eliminate the whole computation on both paths (consider the dependent expressions to be live). Ideally we'd keep the union of the expressions from both paths like compute_antic does and then we can pick the representation that fulfills the constraints.