As-if Rule (was: ARMv8, GCC 4.9 and necessary code optimized away)

Jeffrey Walton noloader@gmail.com
Wed Jun 1 12:09:00 GMT 2016


> ARM intrinsics, as with most constructs in programming languages are
> governed by the 'as if' rule.  That is, the behaviour (from the
> view-point of the abstract machine defined by the programming language)
> is as if the operation were performed.  If the compiler can determine
> that an alternative code sequence can satisfy that requirement it is at
> liberty to substitute that alternative sequence.

I'm not sure I would agree. GCC needs to know intent (q.v.), and I'm
guessing that's probably an NP-complete problem.

C++11 got constexpr to specify intent, so I know the committee is
familiar with the concept.

Sorry to sound argumentative. I'm frustrated when a correct program is
turned into a misbehaving program :)

Maybe as a stop gap GCC could warn when its completely discarding
blocks of code. As far as I know, the only warning at the moment is
for -Wstrict-overflow when an optimization is taken due to integer
overflow. And maybe the "unreachable" because of an early return.

Jeff



More information about the Gcc-help mailing list