[llvm-dev] Condition removed? Difference between LLVM and GCC on a small testcase

Yan Luo via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 1 14:38:41 PST 2019


Hello Dev,

I have a very simple testcase, which shows strange difference between LLVM and GCC. Does anyone know which optimization pass removes the condition? Thanks!

C code:
extern void bar(int, int);

void foo(int a) {
  int b, d;

  if (a > 114) {
    b = a * 58;
  } else {
    d = a * 51;
  }
  bar(b, d);
}

clang.7.0.1 -O2, LLVM generated assembly:
   0:   6b c7 3a                     imul   $0x3a,%edi,%eax
   3:   6b f7 33                      imul   $0x33,%edi,%esi
   6:   89 c7                           mov    %eax,%edi
   8:   e9 00 00 00 00         jmpq   d <foo+0xd>

GCC.5.2.0 -O3, GCC generated assembly:
   0:   83 ff 72                       cmp    $0x72,%edi
   3:   7f 0b                           jg     10 <foo+0x10>
   5:   6b f7 33                      imul   $0x33,%edi,%esi
   8:   89 c7                           mov    %eax,%edi
   a:   e9 00 00 00 00         jmpq   f <foo+0xf>
   f:   90                                  nop
  10:   6b c7 3a                    imul   $0x3a,%edi,%eax
  13:   89 c7                          mov    %eax,%edi
  15:   e9 00 00 00 00       jmpq   1a <foo+0x1a>



Regards,
Yan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190301/6998ceb9/attachment-0001.html>


More information about the llvm-dev mailing list