&gt; What I&#x27;m talking about is not adding checks, but what happens when the compiler knows that something has undefined behavior through e.g. Constant propagation.<p>But ... either the compiler can prove at compile time that the program has undefined behaviour, in which case it should simply refuse to compile, or it can not, in which case it has to emit a runtime check to determine when undefined behaviour &quot;is about to happen&quot;, which is potentially expensive?<p>&gt; The undefined behaviour is there to make translations to machine instructions efficient - so that you don&#x27;t need to do checks on pointers and that addition, shift, etc. on several instructions are supported although they behave slightly differently<p>... or in other words: for optimisation?<p>I mean, optimisation ultimately is nothing but the selection of the cheapest possible sequence of instructions to perform a given computation. And undefined behaviour helps with that, not just in the last step of mapping your IR to instructions, but in every step before that, as every optimisation step has to preserve the semantics of the code, and the fewer restrictions there are on the interpretation of a given piece of code, the more options every optimisation step has to transform the code without changing the semantics, and thus the more chances for one of them being cheaper than the others.