Well you can't have your cake and eat it too ;)
> Dead code removal is unexpected by the programmer, because programmer does not write dead code.
Of course it is expected, because the optimizations leading to dead code are fundamental for the performance you get out of a release-mode binary (and that's also true for languages with less UB like Rust btw).
When you have a function:
static int add(int a, int b) {
return a + b;
}
And you call that function with const parameters:
int c = add(2, 3);
Then you want that entire function call to be removed and "folded" into its result 5, and when this was the only place the function was called, you'd also want the actual function to be removed from the binary (because what's the point of lugging code around in the binary that's guaranteed to never be executed).