https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70159
--- Comment #7 from Sebastian Pop <spop at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #6) > Note this is both a hoisting and a sinking issue. > Hoisting should happen before sinking. > LLVM looks like it only implements sinking. You are right: LLVM does sinking very early as part of instcombine: it transforms the phi nodes after the if into selects over the operands and sinks the sub and mul after the select. By the time other redundancy elimination passes are executed the shape of the code is more difficult to optimize.