Related articles |
---|
[4 earlier articles] |
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) |
Re: Executing code at compilation time torbenm@diku.dk (2010-03-22) |
[3 later articles] |
From: | Fernando Magno Quintao Pereira <pronesto@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Tue, 16 Mar 2010 21:37:12 -0300 |
Organization: | Compilers Central |
References: | 10-03-038 <31F5149B-7EAB-498D-95B4-DE608FDDD3A5@jantar.org> |
Keywords: | optimize |
Posted-Date: | 16 Mar 2010 23:39:33 EDT |
Dear Patryk and Diego,
thank you very much for the kind replies. In particular, Patryk,
thank you very much for pointing me to Partial Evaluation.
About the small program that I had posted:
int main(int argc, char** argv) {
int i = 0;
int sum = 0;
for (; i < 32767; i++) {
sum += i;
}
printf("The sum is %d\n", sum);
}
following Diego's hint, "gcc -O1 sl1.c -fdump-tree-all" seems to
reveal that the loop is resolved after sparse conditional constant
propagation. One interesting fact is that the program below is not
optimized by either O1, O2 or O3:
int main(int argc, char** argv) {
int i = 0;
int sum = 0;
for (; i < 32767; i++) {
sum -= i;
}
printf("The sum is %d\n", sum);
}
And the only difference is the "sum -= i". If I decrease the loop
limit to, say, 10, then the loop is completely resolved, what leads me
to believe that the responsible opts are, in this case, a combination
of loop unrolling with constant propagation, as Patryk had pointed. If
you allow me a last question, why the loop:
for (; i < 32767; i++) {
sum += i;
}
is fully resolved, whereas:
for (; i < 32767; i++) {
sum -= i; // see the minus
}
is not?
All the best,
Fernando
Return to the
comp.compilers page.
Search the
comp.compilers archives again.