Why doesn't the compiler emit a warning for all UB it finds while compiling? Or do regular programs rely on this too much to be feasible? It must be something like that, or there'd not be much performance gains to be had by exploiting UB right?
It's not necessarily detectable statically.
Any time you add two (signed) integers, that's potentially undefined behaviour.