> If UB was instead defined to trap, most optimizations that are made possible by UB would still be possible, but without the footgun part.
... on hardware where the native instruction happens to trap.
Otherwise it needs to generate a conditional branch and explicit trap instruction, which is as unoptimal as any other imposed behavior.