Re: Detailed algorithms on inline optimization

Miles Bader <miles@gnu.org>
Wed, 20 Jan 2010 16:58:48 +0900

          From comp.compilers

Related articles
Detailed algorithms on inline optimization pengyu.ut@gmail.com (Peng Yu) (2010-01-18)
Re: Detailed algorithms on inline optimization bobduff@shell01.TheWorld.com (Robert A Duff) (2010-01-19)
Re: Detailed algorithms on inline optimization holgersiegel74@yahoo.de (Holger Siegel) (2010-01-20)
Re: Detailed algorithms on inline optimization bobduff@shell01.TheWorld.com (Robert A Duff) (2010-01-19)
Re: Detailed algorithms on inline optimization gneuner2@comcast.net (George Neuner) (2010-01-19)
Re: Detailed algorithms on inline optimization miles@gnu.org (Miles Bader) (2010-01-20)
Re: Detailed algorithms on inline optimization rangsynth@gmail.com (Robin Holmes) (2010-01-20)
Re: Detailed algorithms on inline optimization jeremy.wright@microfocus.com (Jeremy Wright) (2010-01-20)
Re: Detailed algorithms on inline optimization dot@dotat.at (Tony Finch) (2010-01-21)
Re: Detailed algorithms on inline optimization bear@sonic.net (Ray) (2010-01-21)
Re: Detailed algorithms on inline optimization bobduff@shell01.TheWorld.com (Robert A Duff) (2010-01-21)
Re: Detailed algorithms on inline optimization cdodd@acm.org (Chris Dodd) (2010-01-23)
[8 later articles]
| List of all articles for this month |

From: Miles Bader <miles@gnu.org>
Newsgroups: comp.compilers
Date: Wed, 20 Jan 2010 16:58:48 +0900
Organization: NEC Electronics
References: 10-01-058 10-01-061 10-01-063
Keywords: optimize, code
Posted-Date: 21 Jan 2010 00:58:57 EST
Blat: Foop

Robert A Duff <bobduff@shell01.TheWorld.com> writes:
> And then a call like "X := Factorial(7);" would compile into
> a "move 5040 into X" instruction. It had inlined 7 levels,
> and then constant-folded it. Factorial(8) didn't do that.
>
> I don't know if GNAT (the gcc Ada compiler) can do this sort
> of thing.


I don't know about GNAT in particular, but gcc will do it sometimes;
e.g., the following:


      static int fact (int n) { if (n == 0) return 1; else return n * fact (n - 1); }


      int foo1 () { return fact (7); }
      int foo2 () { return fact (8); }
      int foo3 () { return fact (9); }
      int foo4 () { return fact (10); }


      int foo5 () { return fact (33); }


compiles into:


      foo1:
                      movl $5040, %eax
                      ret
      foo2:
                      movl $40320, %eax
                      ret
      foo3:
                      movl $362880, %eax
                      ret
      foo4:
                      movl $3628800, %eax
                      ret
      foo5:
                      movl $1, %eax
                      movl $33, %edx
      .L11:
                      imull %edx, %eax
                      decl %edx
                      jne .L11
                      rep
                      ret


("gcc-4.4 -O3 -fomit-frame-pointer -march=native -S x.c")


-miles


--
Erudition, n. Dust shaken out of a book into an empty skull.



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.