Re: fix for strict-alias warnings

From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: fix for strict-alias warnings
Date: 2003-10-14 20:32:56
Message-ID: 3F8C5D78.1090802@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:

>Given that gcc is smart enough not to move any code across the memset()
>call, I doubt that it would be moving anything across the whole if()
>construct. Now if the if-condition were such that the memset code path
>could be optimized away, then we'd have a problem, but in practice I do
>not believe gcc is smart enough to realize that the alignment check is
>always true.
>
gcc-3.2.2 optimizes the memset away - that's a simple exercise for gcc.

gcc-3.2.2 isn't smart enough to replace everything - it didn't like the
pointer arithmetics.
After some massaging, I've succeeded in generating bad code using a
slightly modified MemSetAligned macro (parameters -O2
-fstrict-aliasing): gcc pipelined the x*x around the memset.

Annotated asm output with gcc -O99 -fomit-frame-pointer -fstrict-aliasing:
08048328 <test2>:
8048328: 83 ec 18 sub $0x18,%esp
>>>>> stack setup for automatic variables.
804832b: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp,1)
8048332: 00
8048333: c7 44 24 10 00 00 00 movl $0x40000000,0x10(%esp,1)
804833a: 40
>>>> x = 1.0;
804833b: dd 44 24 0c fldl 0xc(%esp,1)
804833f: d8 c8 fmul %st(0),%st
>>>> x = x*x;
8048341: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp,1)
8048348: 00
8048349: c7 44 24 10 00 00 00 movl $0x0,0x10(%esp,1)
8048350: 00
>>>>> MemSetAligned(): optimized to storing two ints.
8048351: dd 54 24 0c fstl 0xc(%esp,1)
>>> write back the result of x*x to the stack
8048355: dd 1c 24 fstpl (%esp,1)
>>> push x*x for printf call
8048358: 68 54 84 04 08 push $0x8048454
>>> push pointer to "square is %f.\n"
804835d: e8 06 ff ff ff call 8048268 <_init+0x38>
>>>> call printf
8048362: 83 c4 1c add $0x1c,%esp
8048365: c3 ret
>>>>> and exit.
8048366: 89 f6 mov %esi,%esi

To paraphrase the ISO C line: gcc is not your grandfather's gcc. It's
within 10% of the best compilers for SpecInt - the propagation and
analysis of constants it quite good, and several bugs were fixed sinced
3.2.2.

What is the oldest gcc versions still supported by postgres? It seems
that the strict alias analysis is from the egcs tree. Probably first
supported by egcs-1.1.2 - is that gcc-2.91?

http://groups.google.de/groups?q=g:thl2087564510d&dq=&hl=de&lr=&ie=UTF-8&oe=UTF-8&selm=fa.fjlldvv.l7m7hk%40ifi.uio.no

--
Manfred

Attachment Content-Type Size
work.c text/x-csrc 795 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2003-10-14 20:32:59 Re: postgres --help-config
Previous Message Peter Eisentraut 2003-10-14 20:29:25 Re: fix for strict-alias warnings

Browse pgsql-patches by date

  From Date Subject
Next Message Neil Conway 2003-10-14 20:38:17 Re: fix for strict-alias warnings
Previous Message Peter Eisentraut 2003-10-14 20:29:25 Re: fix for strict-alias warnings