Re:Impact of Undefined Behavior on Performance
by mike_hock on Friday July 09, 2021 @05:18PM
(#27788638)
If you impose that the unhappy path must trap, the compiler has to guarantee that.
Conversely, if the compiler can reason that the condition is impossible, it can remove code regardless of what behavior is imposed for the condition that it knows can't happen.
Removing code is both among the most sensitive and the most effective optimizations that compilers do, and they use UB as another signal for “unreachable”. The current model of “assume things never happen and don’t plan anything in particular if it does happen” does no one a service.