[cfe-dev] Startling optimization
Xi Wang
xi.wang at gmail.com
Sun Jun 19 22:46:41 PDT 2011
you may try the following passes that will optimize the loop away.
clang -emit-llvm -S -o - test.c | opt -mem2reg -loop-rotate -instcombine -indvars -loop-deletion -S
- xi
On Jun 20, 2011, at 12:56 AM, Robert Purves wrote:
> $ cat test.c
> int foo( int n )
> {
> int a = 0, b = 0, c = 0, j;
>
> for ( j = 0; j < n; j++ )
> {
> a++;
> b = a | c;
> c = a;
> }
> return b;
> }
>
> $ clang -O -S test.c
>
>
> _foo:
> pushq %rbp
> movq %rsp, %rbp
> testl %edi, %edi
> jle LBB0_2
> leal -1(%rdi), %eax
> orl %edi, %eax
> popq %rbp
> ret
> LBB0_2:
> xorl %eax, %eax
> popq %rbp
> ret
>
> Which parts of clang/llvm source should I read to learn how the loop is magically optimized away?
>
> Robert P.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list