This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
As-if Rule (was: ARMv8, GCC 4.9 and necessary code optimized away)
- From: Jeffrey Walton <noloader at gmail dot com>
- To: "Richard Earnshaw (lists)" <Richard dot Earnshaw at arm dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 1 Jun 2016 08:09:51 -0400
- Subject: As-if Rule (was: ARMv8, GCC 4.9 and necessary code optimized away)
- Authentication-results: sourceware.org; auth=none
- Reply-to: noloader at gmail dot com
> 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