[LLVMdev] LLVM optmization

Duncan Sands baldrick at free.fr
Wed Jan 14 01:31:52 PST 2009


Hi Manoel,

>  Hi, Duncan.
> 
>  Here an example :
> #include <stdio.h>
> #include <stdlib.h>
> //
> int  TESTE ( int  parami ,int  paraml   ) 
> {
>   int varx=0;
>   int nI =0;
>   
>   if( parami  > 0 )
>   {
>     varx = parami;
>   }
>   else
>   {
>     varx = 1;
>    }
>   
>   for( nI = 1 ;   nI <=  paraml; nI++)
>   {
>     varx =  varx +  parami+ 1;
>   }
> 
> return varx ;
> }
> 
> int main(int argc, char **argv)
> {
>    if( argc < 3 )
>      return 0;
>    return TESTE(atoi(argv[1]),atoi(argv[2]));
> }
> 
>  I don't know how gcc4 resolves the for loop, but the MSVC is great in this example.

gcc-4.3 also eliminates the loop entirely and directly calculates the value of varx.

>  If I change the paraml  and put a constant, the LLVM optmizes very well.

It looks like LLVM's scalar evolution code isn't handling your testcase well.

Ciao,

Duncan.



More information about the llvm-dev mailing list