[LLVMbugs] [Bug 12381] New: unexpected spilling of scratch register across branch

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 27 19:14:29 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12381

             Bug #: 12381
           Summary: unexpected spilling of scratch register across branch
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Register Allocator
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: richard-llvm at metafoo.co.uk
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following code, run through clang on x86_64, produces a suboptimal spill:

void f(int); void g(); extern bool b; extern int n;
void h() { if (b) f(n*n*n*n); g(); }

We get:

_Z1hv:                                  # @_Z1hv
# BB#0:                                 # %entry
        pushq   %rax
        testb   $1, b(%rip)
        je      .LBB0_2
# BB#1:                                 # %if.then
        movl    n(%rip), %eax
        movl    %eax, %edi
        imull   %edi, %edi
        imull   %eax, %edi
        imull   %eax, %edi
        callq   _Z1fi
.LBB0_2:                                # %if.end
        popq    %rax
        jmp     _Z1gv                   # TAILCALL

Saving %rax on both sides of the branch, when it is only used on one side, is
not great. But %rax is a scratch register, so why is it being saved at all?

Ideally, it would be great if llc could produce:

_Z1hv:
        testb   $1, b(%rip)
        je      _Z1gv
        movl    n(%rip), %edi
        imull   %edi, %edi
        imull   %edi, %edi
        callq   _Z1fi
        jmp     _Z1gv

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list