[LLVMdev] LLVM optmization

Bill Wendling isanbard at gmail.com
Wed Jan 7 11:40:02 PST 2009


On Wed, Jan 7, 2009 at 2:56 AM, Manoel Teixeira <manoel at fonetica.com.br> wrote:
>
> The following C test program was  compiled using LLVM with -O3 option  and MSVC with /O2.
> The MSVC one is about 600 times faster than the one compiled with the LLVM.
> We can see that the for loop in MSVC assembler is solved in the optimization pass more efficiently than that in LLVM.
> Is there an way to get a optimization result in LLVM like that of the MSVC?
> Manoel Teixeira
>
> #include <windows.h>
> #include <stdio.h>
>
> int  TESTE ( int  parami ,int  paraml ,double  paramd  )
> {
>  int varx=0,vary=0;
>  int nI =0;
>
>    if( parami > 0  )
>        {
>   varx = parami;
>   vary = 0;
>        }
>  else
>  {
>   varx = 0;
>   vary = paraml;
>  }
>  for( nI = 1 ;   nI <=  paraml; nI++)
>  {
>    varx =  varx + parami + 1 ;
>        vary =  varx + nI;
>  }
>
> return varx ;
> }
> unsigned long thread_call( LPVOID c )
> {
>        int num = 1;
>        int (*fp)(int, int, double) = (int (*)(int, int,double)) c;
>        //printf("\n(1)threadid =  %ld seqt=%ld inum=%d",GetCurrentThreadId(),num,inum);
>        int ret = fp(num,1000000000,1);
>        printf("\n(2)leu %ld threadid =  %ld seqt=%ld ",ret , GetCurrentThreadId(),num);
>        return (unsigned long) ret;
> }
> ///cronometro
> unsigned long tini;
> unsigned long tfim;
> #define getmilisecs(x) (x)
> #define num_th 100
> unsigned long milisecs() { return getmilisecs(tfim-tini);};
> unsigned long secs() { return milisecs()/1000;};
> const char *spenttime ()
> {
>        static char buffer[64];
>        unsigned long systime                   =        secs();
>        unsigned long milisectime               =        milisecs()%1000;
>        sprintf(buffer,"%02d:%02d:%02d:%03d",systime/3600,(systime%3600)/60,(systime%3600)%60,milisectime);
>        return (const char*) buffer;
> };
> //fim cronometro
> int main(int a, char **b)
> {
>  int i;
>  DWORD  iThreadId;
>  HANDLE mainThread[num_th];
>  tfim   =       0;
>  tini   =       GetTickCount();

You're starting your count ...

>  for(i=0;       i<      num_th;i++)
>                mainThread[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_call, (LPVOID)TESTE, 0, (DWORD *)&iThreadId);
>
While doing a thread create method (which I don't have on my darwin
box) that calls "printf". "printf" is I/O bound and makes for a lousy
performance test.

Nevertheless, I've attached the .s file generated by LLVM from the IR
you gave. I can't see anything obviously wrong with it. Please point
out in it which parts are 600x slower than on Windows. I'm not able to
run it because I don't have a Windows box, and it requires some
Windows calls.

Note: The ASM is for a Darwin box. I didn't generate this code with
frame pointers disabled. This would improve performance, but you
didn't mention that you did the same for your Windows compile.

-bw
-------------- next part --------------
A non-text attachment was scrubbed...
Name: y.s
Type: application/octet-stream
Size: 3985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090107/2f929f53/attachment.obj>


More information about the llvm-dev mailing list