[LLVMbugs] [Bug 7300] New: Unused argument registers can not be reused

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 4 00:48:01 PDT 2010


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

           Summary: Unused argument registers can not be reused
           Product: libraries
           Version: 2.7
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: Arnaud.AllardDeGrandMaison at dibcom.com
                CC: llvmbugs at cs.uiuc.edu


Using the msp430 backend, the first four parameters of a function are passed
thru registers. What I observe is that if those parameters are not used inside
the function, those registers can not be used. Note : this behaviour is not
specific to the msp430 backend.

Steps to reproduce:
> cat test_unused_regs.c
short a = 2;
short b = 32;
short r = 1024;

void
test(short w, short x, short y, short z)
{
  r -= a+b;
}

> clang -ccc-host-triple msp430-unknown-unknown -O2 -fomit-frame-pointer -S -o test_unused_regs.s test_unused_regs.c
> cat test_unused_regs.s
…
test:
      push.w      r11
      mov.w &b, r11
      add.w &a, r11
      sub.w r11, &r
      pop.w r11
      ret
…

Instead of using r11, llvm should have used r12/r13/r14 or r15. This was my
expectation, and the behaviour with llvm-2.6. This would have spared
saving/restoring r11.

This bug has been introduced/revealed by svn commit #95493, which enabled
DeadMachineInstructionElimPass for all targets. Disabling this pass makes
llvm-2.7 behave as expected.

Dump of the test function at entry / exit of DeadMachineInstructionElimPass :
# Machine code for function test:
Function Live Ins: %R15W in reg%1024, %R14W in reg%1025, %R13W in reg%1026,
%R12W in reg%1027

BB#0: derived from LLVM BB %entry
    Live Ins: %R15W %R14W %R13W %R12W
        %reg1027<def> = MOV16rr %R12W
        %reg1026<def> = MOV16rr %R13W
        %reg1025<def> = MOV16rr %R14W
        %reg1024<def> = MOV16rr %R15W
        %reg1028<def> = MOV16rm %reg0, <ga:@b>; mem:LD2[@b]
        %reg1029<def> = ADD16rm %reg1028, %reg0, <ga:@a>, %SRW<imp-def,dead>;
mem:LD2[@a]
        SUB16mr %reg0, <ga:@r>, %reg1029, %SRW<imp-def,dead>; mem:ST2[@r]
LD2[@r]
        RET

# End machine code for function test.

# Machine code for function test:
Function Live Ins: %R15W in reg%1024, %R14W in reg%1025, %R13W in reg%1026,
%R12W in reg%1027

BB#0: derived from LLVM BB %entry
    Live Ins: %R15W %R14W %R13W %R12W
        %reg1028<def> = MOV16rm %reg0, <ga:@b>; mem:LD2[@b]
        %reg1029<def> = ADD16rm %reg1028, %reg0, <ga:@a>, %SRW<imp-def,dead>;
mem:LD2[@a]
        SUB16mr %reg0, <ga:@r>, %reg1029, %SRW<imp-def,dead>; mem:ST2[@r]
LD2[@r]
        RET

# End machine code for function test.

Those MOV16rr instructions are all dead, so machine DCE removes them. That
leaves the livein registers dangling, never to be killed. LiveIntervalAnalysis
then decides that they are live through the block.

-- 
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