Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Prolog/Epilog Insertion going crazy on PPC #3256

Closed Quuxplusone closed 15 years ago

Quuxplusone commented 15 years ago
Bugzilla Link PR2964
Status RESOLVED FIXED
Importance P normal
Reported by Chris Lattner (clattner@nondot.org)
Reported on 2008-10-28 01:53:39 -0700
Last modified on 2008-10-29 13:42:41 -0700
Version 1.0
Hardware PC All
CC dalej@apple.com, evan.cheng@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
go into test/CodeGen/PowerPC and do this:

$ llvm-as < compare-fcmp-ord.ll | llvm-extract -func test | llc -march=ppc32 -
print-machineinstrs -debug-pass=Executions | & less

Before PEI, the code looks like this:

entry: 0x1812ab4, LLVM BB @0x14021a0, ID#0:
Live Ins: %F1 %F2
        %CR7<def> = FCMPUD %F1<kill>, %F2<kill>
        %R2<def> = MFCR %CR0<imp-use,kill>, %CR1<imp-use,kill>, %CR2<imp-use,kill>, %CR3<imp-use,kill>,
%CR4<imp-use,kill>, %CR5<imp-use,kill>, %CR6<imp-use,kill>, %CR7<imp-use,kill>
        %R3<def> = RLWINM %R2, 29, 31, 31
        %R2<def> = RLWINM %R2<kill>, 31, 31, 31
        %R3<def> = OR %R2<kill>, %R3<kill>
        BLR 20, %reg0, %R3<imp-use,kill>, %LR<imp-use>

Afterwards, it looks like this:

entry: 0x1812ab4, LLVM BB @0x14021a0, ID#0:
Live Ins: %F1 %F2 %CR2 %CR3 %CR4
        %R0<def> = MFCR %CR0<imp-use>, %CR1<imp-use>, %CR2<imp-use>, %CR3<imp-use>, %CR4<imp-use>, %CR5<
imp-use>, %CR6<imp-use>, %CR7<imp-use>
        %R0<def> = RLWINM %R0, 8, 0, 31
        STW %R0<kill>, -4, %R1
        %R0<def> = MFCR %CR0<imp-use>, %CR1<imp-use>, %CR2<imp-use>, %CR3<imp-use>, %CR4<imp-use>, %CR5<
imp-use>, %CR6<imp-use>, %CR7<imp-use>
        %R0<def> = RLWINM %R0, 12, 0, 31
        STW %R0<kill>, -8, %R1
        %R0<def> = MFCR %CR0<imp-use>, %CR1<imp-use>, %CR2<imp-use>, %CR3<imp-use>, %CR4<imp-use>, %CR5<
imp-use>, %CR6<imp-use>, %CR7<imp-use>
        %R0<def> = RLWINM %R0, 16, 0, 31
        STW %R0<kill>, -12, %R1
        %CR7<def> = FCMPUD %F1<kill>, %F2<kill>
        %R2<def> = MFCR %CR0<imp-use,kill>, %CR1<imp-use,kill>, %CR2<imp-use,kill>, %CR3<imp-use,kill>,
%CR4<imp-use,kill>, %CR5<imp-use,kill>, %CR6<imp-use,kill>, %CR7<imp-use,kill>
        %R3<def> = RLWINM %R2, 29, 31, 31
        %R2<def> = RLWINM %R2<kill>, 31, 31, 31
        %R3<def> = OR %R2<kill>, %R3<kill>
        %R0<def> = LWZ -12, %R1
        %R0<def> = RLWINM %R0, 16, 0, 31
        %CR4<def> = MTCRF %R0
        %R0<def> = LWZ -8, %R1
        %R0<def> = RLWINM %R0, 20, 0, 31
        %CR3<def> = MTCRF %R0
        %R0<def> = LWZ -4, %R1
        %R0<def> = RLWINM %R0, 24, 0, 31
        %CR2<def> = MTCRF %R0
        BLR 20, %reg0, %R3<imp-use,kill>, %LR<imp-use>

This is a huge code quality regression from the past.  It looks like
individuals CR is being saved and restored.  CR7 (which is def'd by this code)
is a call clobber register according to this:

PPCInstrInfo.td:422.
Quuxplusone commented 15 years ago

I precipitated this by marking MFCR as using all 7 CR subregisters, which it does. This exposed two underlying problems:

It saves callee-saved CR subregisters (and, I think, other registers, the code appears generic) if they are used; it needs to do this only if they're stored into. (I already fixed the same problem for LR.)

It saves CR subregisters individually (it is saving CR2,3 and 4 which are callee-saved) instead of saving CR as a unit. It always did this and nobody noticed before.

I'll take care of this.

Quuxplusone commented 15 years ago

Thanks Dale!

Quuxplusone commented 15 years ago

I've reverted the change that exposed this for now, thus "fixing" the problem.

Quuxplusone commented 15 years ago
Awesome, thanks Dale.  I added a testcase here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20081027/069103.html