Simplification of relational expressions
John Fine
johnsfine@verizon.net
Wed Jun 4 11:34:00 GMT 2008
Andrew Haley wrote:
> Chris Thiel wrote
>> Is there a reason that the equality and inequality expressions (and only
>> those expressions) are simplified? I understand that signed integer
>> overflow is undefined.
>>
>
> I'm more than a little mystified by this question. Unless the target is
> using something truly weird like saturating arithmetic we can always
> guarantee that a+1 != a, but we cannot guarantee that a+1 > a.
>
>
The optimizer is always allowed to know the behaviors that result in
THIS compiler from undefined behavior. If the optimizer can predict the
run time answer with complete certainty, it can use that answer.
You could create a compiler with saturating arithmetic, so the most
positive integer plus one is still the most positive integer. Then the
optimizer of THAT compiler could safely assume a+1 >= a but couldn't
assume a+1>a nor a+1!=a.
But for THIS compiler the most positive integer plus one is the most
negative integer. The compiler knows that even though the standard
doesn't know it and a well written program shouldn't know it. So THIS
compiler can assume a+1!=a.
More information about the Gcc-help
mailing list