Re: compile warning

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Postgresql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: compile warning
Date: 2003-10-10 19:24:54
Message-ID: 3F870786.3030309@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian wrote:

>This seems to be a bug in gcc-3.3.1. -fstrict-aliasing is enabled by
>-O2 or higher optimization in gcc 3.3.1.
>
>Now that I think of it, they might be talking about an optimization
>called register aliasing, where they are taking the structure and
>mapping it to a CPU register for some optimization, and what we are
>doing is to store a different structure in there that will not fit in a
>register. A Node will fit in a register (it is only an enum) but the
>TriggerData structure will not, meaning the code has to spill the
>register to memory, then access the full structure, or something like
>that.
>
>
>
>

Did you mean register renaming? If so, it is only turned on by -O3. But I can see that strict aliasing does help the compiler make the right guess as to which registers to use for what, even without register renaming.

http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Optimize-Options.html#Optimize%20Options
says:

|-O|

|-O1|
Optimize. Optimizing compilation takes somewhat more time, and a lot
more memory for a large function.

With |-O|, the compiler tries to reduce code size and execution
time, without performing any optimizations that take a great deal of
compilation time.

|-O| turns on the following optimization flags:

-fdefer-pop
-fmerge-constants
-fthread-jumps
-floop-optimize
-fcrossjumping
-fif-conversion
-fif-conversion2
-fdelayed-branch
-fguess-branch-probability
-fcprop-registers

|-O| also turns on |-fomit-frame-pointer| on machines where doing so
does not interfere with debugging.

|-O2|
Optimize even more. GCC performs nearly all supported optimizations
that do not involve a space-speed tradeoff. The compiler does not
perform loop unrolling or function inlining when you specify |-O2|.
As compared to |-O|, this option increases both compilation time and
the performance of the generated code.

|-O2| turns on all optimization flags specified by |-O|. It also
turns on the following optimization flags:

-fforce-mem
-foptimize-sibling-calls
-fstrength-reduce
-fcse-follow-jumps -fcse-skip-blocks
-frerun-cse-after-loop -frerun-loop-opt
-fgcse -fgcse-lm -fgcse-sm
-fdelete-null-pointer-checks
-fexpensive-optimizations
-fregmove
-fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec
-fcaller-saves
-fpeephole2
-freorder-blocks -freorder-functions
-fstrict-aliasing
-falign-functions -falign-jumps
-falign-loops -falign-labels

Please note the warning under |-fgcse| about invoking |-O2| on
programs that use computed gotos.

|-O3|
Optimize yet more. |-O3| turns on all optimizations specified by
|-O2| and also turns on the |-finline-functions| and
|-frename-registers| options.

In the Linux kernel, you can see this in include/linux/tcp.h:

/*
* The union cast uses a gcc extension to avoid aliasing problems
* (union is compatible to any of its members)
* This means this part of the code is -fstrict-aliasing safe now.
*/
union tcp_word_hdr {
struct tcphdr hdr;
__u32 words[5];
};

#define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])

Maybe this gives us a clue.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Satoshi Nagayasu 2003-10-10 19:26:26 Re: 2-phase commit
Previous Message Andrew Sullivan 2003-10-10 19:09:31 Re: 2-phase commit