> if (a - 10 < 20)
>
> Well that particular example is far fetched in code that people
> expect to run efficiently, but with a bit of effort you could
> come up with a more realistic example.
Not at all far-fetched. The normal way these things come up is macros:
#define DIGIT_TO_INT(D) (D - '0')
...
if (DIGIT_TO_INT (a) < 5)
> Compilers are always full of such optimizations which are simple to do
> and get put in without any sound basis for determining that they actually
> help.
Given the pervasiveness of macros of this type, this sort of folding
optimization catches a lot of cases. And the answer to where a lot of
wierd-looking code comes from is also macros.