From: Andrew Pinski <pinskia@physics.uc.edu>
To: "Håkan Hjort" <hakan@safelogic.se>
Cc: Reza Roboubi <reza@linisoft.com>, gcc@gcc.gnu.org
Subject: Re: optimizations
Date: Tue, 18 Feb 2003 18:16:00 -0000 [thread overview]
Message-ID: <ADC117AC-436C-11D7-A57E-00039372607E@physics.uc.edu> (raw)
In-Reply-To: <20030218175524.GA8638@safelogic.se>
Here is the generation for 3.4 (20030214) on ppc (darwin/mac os x):
_main:
mflr r2
li r9,0
stw r2,8(r1)
li r2,0
stwu r1,-64(r1)
stw r2,56(r1) <== store 0 in &k before the loop. WHY?
b L2
L10:
addi r9,r9,1
L2:
cmpwi cr0,r9,16
bne+ cr0,L10
addi r4,r1,56 <== the second parm to write
li r3,1 <== the first parm to write
li r5,1 <== the third parm to write
stw r9,56(r1) <== stores the 2nd parm to write aka &k
bl _write <== `call' write
addi r1,r1,64 <== restore the stack pointer
lwz r4,8(r1)
li r3,0 <== the return value from main
mtlr r4
blr
Here is the generation for 3.4 (20030215) on x86 (linux):
main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl $0, -4(%ebp) <=== store 0 into &k
andl $-16, %esp
jmp .L2
.p2align 4,,7
.L9:
incl %eax <=== increment k
movl %eax, -4(%ebp) <=== store k into &k WHY?
.L2:
movl -4(%ebp), %eax <=== load k from &k WHY?
cmpl $16, %eax <=== compare k to 16
jne .L9 <=== jump not equal to L9
movl $1, 8(%esp) <=== 1st parm to write (1)
leal -4(%ebp), %edx <=== (&k) into edx
movl %edx, 4(%esp) <=== 2nd parm to write (&k/edx)
movl $1, (%esp) <=== 3rd parm to write (1)
call write <=== call write
leave
ret
From the looks of it, gcc does a better job on ppc compared to i686 for
some reason in terms of optimizations.
Thanks,
Andrew Pinski
On Tuesday, Feb 18, 2003, at 09:55 US/Pacific, Håkan Hjort wrote:
> Wed Jan 15 2003, Reza Roboubi wrote:
>> tm_gccmail@mail.kloo.net wrote:
>> [snap]
>>> I mentioned this on the gcc-bugs mailing list, and Mark Mitchell
>>> contributed a fairly simple load hoisting improvement to the loop
>>> optmiizer which restored performance on Whetstone.
>>>
>>> If you look at the gcc-bugs archives for 1998, you may be able to
>>> find
>>> this message thread.
>> [snap]
>>
>> Thanks for this input. It would be interesting to see how the issue
>> was fixed.
> Sorry for getting into this so late.
> Nobody actually posted the code generated by 3.3/3.4...
>
> inline int mm(int *i) {
> if((*i)==0x10) return 0;
> (*i)++; return 1;
> }
>
> int main() {
> int k=0;
> while (mm(&k)) {}
> write(1,&k,1);
> return 0;
> }
>
> For Sun's Forte compiler one gets the following:
>
> main:
> save %sp,-104,%sp
> or %g0,16,%g1
> st %g1,[%fp-4]
> add %fp,-4,%o1
> or %g0,1,%o0
> call write ! params = %o0 %o1 %o2 ! Result
> or %g0,1,%o2
> ret ! Result = %i0
> restore %g0,0,%o0
>
> I.e. it just stores '16' in k before the call to write, no trace left
> of mm() or any loop, as should be.
>
> Perhaps GCC now does the same after hoisting both the load and the
> store?
>
> --
> /Håkan
>
next prev parent reply other threads:[~2003-02-18 18:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-15 23:20 optimizations Bonzini
2003-01-16 10:53 ` optimizations Reza Roboubi
2003-01-16 11:03 ` optimizations tm_gccmail
2003-01-16 12:34 ` optimizations Reza Roboubi
2003-02-18 18:13 ` optimizations Håkan Hjort
2003-02-18 18:16 ` Andrew Pinski [this message]
2003-02-18 18:17 ` optimizations Zack Weinberg
2003-02-18 18:40 ` optimizations Håkan Hjort
2003-02-19 5:02 ` optimizations David Edelsohn
2003-01-16 11:53 ` optimizations Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2003-01-14 22:58 optimizations Reza Roboubi
2003-01-15 0:15 ` optimizations Andrew Pinski
2003-01-15 5:10 ` optimizations Reza Roboubi
2003-01-15 6:31 ` optimizations Reza Roboubi
2003-01-15 17:37 ` optimizations Andrew Pinski
2003-01-15 17:46 ` optimizations Reza Roboubi
2000-03-10 1:46 Optimizations Virgil Palanciuc
1997-12-14 14:30 [EGCS] Optimizations meissner
1997-12-15 5:38 ` Optimizations Marc Lehmann
1997-12-15 11:29 ` Optimizations Dave Love
1997-12-15 15:43 ` Optimizations Marc Lehmann
[not found] ` <19971216000653.24186.cygnus.egcs@cerebro.laendle>
1997-12-23 7:51 ` Optimizations Stan Cox
1997-12-09 9:52 Optimizations David M. Ronis
1997-12-09 11:19 ` Optimizations Jeffrey A Law
1997-12-10 10:46 ` [EGCS] Optimizations Marc Lehmann
1997-12-14 5:39 ` Philipp Thomas
1997-12-14 15:14 ` Optimizations Marc Lehmann
1997-12-14 20:14 ` Optimizations Jeffrey A Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ADC117AC-436C-11D7-A57E-00039372607E@physics.uc.edu \
--to=pinskia@physics.uc.edu \
--cc=gcc@gcc.gnu.org \
--cc=hakan@safelogic.se \
--cc=reza@linisoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).