[llvm-bugs] [Bug 28957] New: [x86] unnecessary mov of constant function parameter

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 12 15:04:27 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28957

            Bug ID: 28957
           Summary: [x86] unnecessary mov of constant function parameter
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

I'm not sure which layer should handle this, but I'm assuming it's something
late in the backend:

extern int bar(int);
int foo(int x) {
  if (x == 1)
    return bar(1);  // 1st parameter is already '1'
  else
    return bar(-1);
}

or as IR:

define i32 @foo(i32 %x) {
entry:
  %cmp = icmp eq i32 %x, 1
  br i1 %cmp, label %if.then, label %if.else

if.then:            
  %call = tail call i32 @bar(i32 1) #2
  br label %return

if.else:                 
  %call1 = tail call i32 @bar(i32 -1) #2
  br label %return

return:                 
  %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
  ret i32 %retval.0
}

declare i32 @bar(i32)

---------------------------------------------------------------------------

$ ./clang -O2 -fomit-frame-pointer repeatParameter.c -S -o - 
...
    cmpl    $1, %edi
    jne    LBB0_2
## BB#1:                               
    movl    $1, %edi   <--- %edi is already '1'               
    jmp    _bar       <--- 2nd bug? MachineCSE?        
LBB0_2:                           
    movl    $-1, %edi
    jmp    _bar              


gcc gets this right:

foo(int):
        cmpl    $1, %edi
        je      .L3
        movl    $-1, %edi
.L3:
        jmp     bar(int)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160812/1bef4d2e/attachment.html>


More information about the llvm-bugs mailing list