Re: Executing code at compilation time

shrey <shreyas76@gmail.com>
Tue, 16 Mar 2010 17:03:04 -0700 (PDT)

          From comp.compilers

Related articles
[3 earlier articles]
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)
Re: Executing code at compilation time pronesto@gmail.com (Fernando Magno Quintao Pereira) (2010-03-16)
Re: Executing code at compilation time pat@jantar.org (Patryk Zadarnowski) (2010-03-17)
Re: Executing code at compilation time gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-03-17)
Re: Executing code at compilation time bear@sonic.net (Ray) (2010-03-19)
Re: Executing code at compilation time bear@sonic.net (Ray) (2010-03-19)
Re: Executing code at compilation time bobduff@shell01.TheWorld.com (Robert A Duff) (2010-03-21)
[4 later articles]
| List of all articles for this month |

From: shrey <shreyas76@gmail.com>
Newsgroups: comp.compilers
Date: Tue, 16 Mar 2010 17:03:04 -0700 (PDT)
Organization: Compilers Central
References: 10-03-038
Keywords: optimize
Posted-Date: 16 Mar 2010 23:39:15 EDT

The first loop is case of recognizing that it is reduction pattern.
The simplest case of the pattern will present as a cyclic loop self
dependence.


The following book explans the concepts for this very well...
Optimizing Compilers for Modern Architectures: A Dependence-based
Approach by Randy Allen and Ken Kennedy




In the second loop, if you didnt have the if I can imagine some
compiler trying to collapse the loops and then recognizing there is a
reduction.


Resolving the if with % needs some complex induction variable
analysis. GCC with its scalar evolution module probably has the
ability to do the reasoning on the possible values that trigger the
condition.


thanks
shrey




On Mar 15, 6:53 pm, Fernando <prone...@gmail.com> wrote:


> GCC does a pretty good job at optimizing a program like this one
> below:
>
> #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.
>
> I would like to know what kind of optimizations are used to be able to
> completely resolve the loop. Could you give me some source? E.g,
> chapter in textbook, or paper?


Post a followup to this message

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