vfjpl
vfjpl

Reputation: 31

GCC not standard / non-conforming optimization flags?

I'm looking for compiler optimization flags that disregard standards compliance to produce better performing/smaller binaries.

Thus far I found:

-ffast-math
    -fno-math-errno
    -funsafe-math-optimizations
        -fno-signed-zeros
        -fno-trapping-math
        -fassociative-math
        -freciprocal-math
    -ffinite-math-only
    -fno-rounding-math
    -fno-signaling-nans
    -fcx-limited-range
    -fexcess-precision=fast

-fmerge-all-constants

Are there more of this type of flags?

Upvotes: 1

Views: 82

Answers (2)

supercat
supercat

Reputation: 81257

So far as I can tell, almost any optimization setting other than -O0 will cause gcc to violate the portion N1570 6.5.9 paragraph 6 highlighted below:

Two pointers compare equal if and only if both are null pointers, both are pointers to the same object (including a pointer to an object and a subobject at its beginning) or function, both are pointers to one past the last element of the same array object, or one is a pointer to one past the end of one array object and the other is a pointer to the start of a different array object that happens to immediately follow the first array object in the address space.

Although a compiler would not be required to accommodate the possibility that the highlighted case might occur with named objects if it ensured that it left at least one unused byte of storage between any two named objects whose address was taken, and documented a requirement that any compilers generating code for linking with gcc do likewise, gcc does none of those things.

Indeed, its behavior is limited not merely to treating the highlighted case as sometimes reporting objects equal and sometimes not equal, but given a statement like if (p==array1+1) *p=1; it will sometimes behave in a manner which isn't consistent with the assignment being performed, nor with its being skipped.

Consequently, use of any optimization setting other than -O0 would trade off conformance for performance were it not for the One Program Rule, which treats a compiler's ability to correctly process a meaningful range of programs as a quality-of-implementation issue rather than a conformance one.

Upvotes: 0

ndrwnaguib
ndrwnaguib

Reputation: 6135

-Ofast should exactly do this.

Upvotes: 0

Related Questions