Re: Executing code at compilation time

Diego Novillo <dnovillo@acm.org>
Tue, 16 Mar 2010 09:01:56 -0400

          From comp.compilers

Related articles
Executing code at compilation time pronesto@gmail.com (Fernando) (2010-03-15)
Re: Executing code at compilation time gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-03-16)
Re: Executing code at compilation time torbenm@diku.dk (2010-03-16)
Re: Executing code at compilation time dnovillo@acm.org (Diego Novillo) (2010-03-16)
Re: Executing code at compilation time bartc@freeuk.com (Bartc) (2010-03-16)
Re: Executing code at compilation time quinn_jackson2004@yahoo.ca (Quinn Tyler Jackson) (2010-03-16)
Re: Executing code at compilation time apoelstra@localhost.localdomain (Andrew Poelstra) (2010-03-16)
Re: Executing code at compilation time bear@sonic.net (Ray) (2010-03-16)
Re: Executing code at compilation time pat@jantar.org (Patryk Zadarnowski) (2010-03-17)
Re: Executing code at compilation time shreyas76@gmail.com (shrey) (2010-03-16)
[10 later articles]
| List of all articles for this month |

From: Diego Novillo <dnovillo@acm.org>
Newsgroups: comp.compilers
Date: Tue, 16 Mar 2010 09:01:56 -0400
Organization: Compilers Central
References: 10-03-038
Keywords: optimize
Posted-Date: 16 Mar 2010 23:35:10 EDT
X-Google-Sender-Auth: c5d8cd03aeb2986b

On Mon, Mar 15, 2010 at 21:53, Fernando <pronesto@gmail.com> wrote:


> #include <stdio.h>
>
> int main(int argc, char** argv) {
> int i = 0;
> int sum = 0;
> for (; i < 10; i++) {
> sum += i;
> }
> printf("The sum is %d\n", sum);
> }
>
> GCC -O1 produces an assembly that simply prints the answer, 45. It
> completely resolves the loop.


In GCC, this is computed by scalar evolutions, which is used by
optimizations like constant propagation (in this case) to determine
the value of reduction variables in loops. Later, the loop is found
empty and removed by other optimizations.


To see the changes the compiler makes to the code as it optimizes, you
can use the flag -fdump-tree-all in GCC 4.x. IIRC, you should find
the beginnings of this optimization in the .sccp dump file.




Diego.



Post a followup to this message

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