<br />Hi, <br />I certainly will Quentin!<br /><br />Thanks<br />-- <br />Sent from Yandex.Mail for mobile<br /><br />20:10, 13 July 2015, Quentin Colombet <qcolombet@apple.com>:<br /><blockquote>Hi Jog,<br /><br />This look like a scheduling problem to me.<br /><br />The main difference here is that in GCC the final “a + b” is scheduled before the call, whereas in LLVM case, this is scheduled after the call.<br />Because of that, %rdi cannot be used in the final add and it has to be saved somewhere else.<br /><br />You can see that in effect by replacing:<br />        puts("ok");<br />        return a + b;<br /><br />By<br /><br />        b += a;<br />        puts("ok");<br />        return b;<br /><br />That being said, you shouldn’t have to do that to have the nice code.<br /><br />Could you file a PR for the scheduling problem?<br /><br />Thanks,<br />-Quentin<br /><br /><blockquote> On Jul 13, 2015, at 10:03 AM, deco33000@yandex.com wrote:<br /><br /> Hello,<br /><br /> I have an issue with the llvm optimizations. I need to create object codes.<br /><br /> the -ON PURPOSE poor && useless- code :<br /> ---------------------------------------------------<br /> #include <stdio.h><br /> #include <stdlib.h><br /><br /> int ci(int a){<br /><br />         return 23;<br /><br /> }<br /> int flop(int a, char ** c){<br /><br />         a += 71;<br /><br />         int b = 0;<br /><br />         if (a == 56){<br /><br />                 b = 69;<br />                 b += ci(a);<br />         }<br /><br />         puts("ok");<br />         return a + b;<br /> }<br /> --------------------------------------<br /><br /> Compiled that way (using the versions I downloaded and eventually compiled) :<br /> clang_custom -std=c11 -O3 -march=native -c app2.c -S<br /><br /> against gcc:<br /> gcc_custom -std=c11 -O3 -march=native -c app2.c -S<br /><br /> Versions (latest for each, downloaded just a few days ago):<br /> gcc : 5.1<br /> clang/llvm: clang+llvm-3.6.1-x86_64-apple-darwin<br /><br /> Host:<br /> osx yosemite.<br /><br /> The assembly (cut to the essential):<br /><br /> LLVM:<br />         pushq %rbp<br />         movq %rsp, %rbp<br />         pushq %r14<br />         pushq %rbx<br />         movl %edi, %r14d<br />         leal 71(%r14), %eax<br />         xorl %ecx, %ecx<br />         cmpl $56, %eax<br />         movl $92, %ebx<br />         cmovnel %ecx, %ebx<br />         leaq L_.str(%rip), %rdi<br />         callq _puts<br />         leal 71(%rbx,%r14), %eax<br />         popq %rbx<br />         popq %r14<br />         popq %rbp<br />         retq<br /><br /> and the gcc one:<br /><br />        pushq %rbp<br />         movl $0, %eax<br />         movl $92, %ebp<br />         pushq %rbx<br />         leal 71(%rdi), %ebx<br />         leaq LC1(%rip), %rdi<br />         subq $8, %rsp<br />         cmpl $56, %ebx<br />         cmovne %eax, %ebp<br />         call _puts<br />         addq $8, %rsp<br />         leal 0(%rbp,%rbx), %eax<br />         popq %rbx<br />         popq %rbp<br />         ret<br /><br /> As we can see, llvm makes poor register allocations (ecx and r14), leading to more instructions for the same result.<br /><br /> Are there some optimizations I can bring on the table to avoid this ?<br /> -- <br /> Jog<br /><br /> _______________________________________________<br /> LLVM Developers mailing list<br /> LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu<br /> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev<br /></blockquote><br /><br /></blockquote>