This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Simplification of relational expressions


John Fine wrote:
> 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.

Yes.

> 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.

Yes.

> 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.

Which it is doing.  What, then, is your point?

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]