|
| 1 | +From 5423496713e84dea2650e1703821de620f934573 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nemanja Ivanovic <nemanja.i.ibm@gmail.com> |
| 3 | +Date: Thu, 9 Apr 2020 21:34:30 -0500 |
| 4 | +Subject: [PATCH] [PowerPC] Bail out of redundant LI elimination on an implicit |
| 5 | + kill |
| 6 | + |
| 7 | +The transformation currently does not differentiate between explicit |
| 8 | +and implicit kills. However, it is not valid to later simply clear |
| 9 | +an implicit kill flag since the kill could be due to a call or return. |
| 10 | + |
| 11 | +Fixes: https://bugs.llvm.org/show_bug.cgi?id=45374 |
| 12 | +--- |
| 13 | + .../lib/Target/PowerPC/PPCPreEmitPeephole.cpp | 10 ++ |
| 14 | + .../remove-redundant-li-skip-imp-kill.mir | 114 ++++++++++++++++++ |
| 15 | + 2 files changed, 124 insertions(+) |
| 16 | + create mode 100644 llvm/test/CodeGen/PowerPC/remove-redundant-li-skip-imp-kill.mir |
| 17 | + |
| 18 | +diff --git llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp |
| 19 | +index a4b4bf2973d..4ea714ff15f 100644 |
| 20 | +--- llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp |
| 21 | ++++ llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp |
| 22 | +@@ -109,6 +109,16 @@ namespace { |
| 23 | + // Track the operand that kill Reg. We would unset the kill flag of |
| 24 | + // the operand if there is a following redundant load immediate. |
| 25 | + int KillIdx = AfterBBI->findRegisterUseOperandIdx(Reg, true, TRI); |
| 26 | ++ |
| 27 | ++ // We can't just clear implicit kills, so if we encounter one, stop |
| 28 | ++ // looking further. |
| 29 | ++ if (KillIdx != -1 && AfterBBI->getOperand(KillIdx).isImplicit()) { |
| 30 | ++ LLVM_DEBUG(dbgs() |
| 31 | ++ << "Encountered an implicit kill, cannot proceed: "); |
| 32 | ++ LLVM_DEBUG(AfterBBI->dump()); |
| 33 | ++ break; |
| 34 | ++ } |
| 35 | ++ |
| 36 | + if (KillIdx != -1) { |
| 37 | + assert(!DeadOrKillToUnset && "Shouldn't kill same register twice"); |
| 38 | + DeadOrKillToUnset = &AfterBBI->getOperand(KillIdx); |
| 39 | +diff --git llvm/test/CodeGen/PowerPC/remove-redundant-li-skip-imp-kill.mir llvm/test/CodeGen/PowerPC/remove-redundant-li-skip-imp-kill.mir |
| 40 | +new file mode 100644 |
| 41 | +index 00000000000..78091d027ce |
| 42 | +--- /dev/null |
| 43 | ++++ llvm/test/CodeGen/PowerPC/remove-redundant-li-skip-imp-kill.mir |
| 44 | +@@ -0,0 +1,114 @@ |
| 45 | ++# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py |
| 46 | ++# RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown -run-pass \ |
| 47 | ++# RUN: ppc-pre-emit-peephole %s -o - | FileCheck %s |
| 48 | ++--- | |
| 49 | ++ ; ModuleID = 'a.ll' |
| 50 | ++ source_filename = "a.ll" |
| 51 | ++ target datalayout = "e-m:e-i64:64-n32:64" |
| 52 | ++ |
| 53 | ++ ; Function Attrs: nounwind |
| 54 | ++ define dso_local signext i32 @b(i32 signext %a, i32* nocapture %b) local_unnamed_addr #0 { |
| 55 | ++ entry: |
| 56 | ++ %call = tail call signext i32 @g(i32 signext %a) |
| 57 | ++ store i32 %call, i32* %b, align 4 |
| 58 | ++ %call1 = tail call signext i32 @g(i32 signext %a) |
| 59 | ++ ret i32 %call1 |
| 60 | ++ } |
| 61 | ++ |
| 62 | ++ ; Function Attrs: nounwind |
| 63 | ++ declare signext i32 @g(i32 signext) local_unnamed_addr #0 |
| 64 | ++ |
| 65 | ++ ; Function Attrs: nounwind |
| 66 | ++ declare void @llvm.stackprotector(i8*, i8**) #0 |
| 67 | ++ |
| 68 | ++ attributes #0 = { nounwind } |
| 69 | ++ |
| 70 | ++... |
| 71 | ++--- |
| 72 | ++name: b |
| 73 | ++alignment: 16 |
| 74 | ++exposesReturnsTwice: false |
| 75 | ++legalized: false |
| 76 | ++regBankSelected: false |
| 77 | ++selected: false |
| 78 | ++failedISel: false |
| 79 | ++tracksRegLiveness: true |
| 80 | ++hasWinCFI: false |
| 81 | ++registers: [] |
| 82 | ++liveins: |
| 83 | ++ - { reg: '$x3', virtual-reg: '' } |
| 84 | ++ - { reg: '$x4', virtual-reg: '' } |
| 85 | ++frameInfo: |
| 86 | ++ isFrameAddressTaken: false |
| 87 | ++ isReturnAddressTaken: false |
| 88 | ++ hasStackMap: false |
| 89 | ++ hasPatchPoint: false |
| 90 | ++ stackSize: 64 |
| 91 | ++ offsetAdjustment: 0 |
| 92 | ++ maxAlignment: 1 |
| 93 | ++ adjustsStack: true |
| 94 | ++ hasCalls: true |
| 95 | ++ stackProtector: '' |
| 96 | ++ maxCallFrameSize: 32 |
| 97 | ++ cvBytesOfCalleeSavedRegisters: 0 |
| 98 | ++ hasOpaqueSPAdjustment: false |
| 99 | ++ hasVAStart: false |
| 100 | ++ hasMustTailInVarArgFunc: false |
| 101 | ++ localFrameSize: 0 |
| 102 | ++ savePoint: '' |
| 103 | ++ restorePoint: '' |
| 104 | ++fixedStack: |
| 105 | ++ - { id: 0, type: spill-slot, offset: -80, size: 8, alignment: 16, stack-id: default, |
| 106 | ++ callee-saved-register: '$x30', callee-saved-restored: true, debug-info-variable: '', |
| 107 | ++ debug-info-expression: '', debug-info-location: '' } |
| 108 | ++ - { id: 1, type: spill-slot, offset: -88, size: 8, alignment: 8, stack-id: default, |
| 109 | ++ callee-saved-register: '$x29', callee-saved-restored: true, debug-info-variable: '', |
| 110 | ++ debug-info-expression: '', debug-info-location: '' } |
| 111 | ++stack: [] |
| 112 | ++callSites: [] |
| 113 | ++constants: [] |
| 114 | ++machineFunctionInfo: {} |
| 115 | ++body: | |
| 116 | ++ bb.0.entry: |
| 117 | ++ liveins: $x3, $x4, $x29, $x30 |
| 118 | ++ |
| 119 | ++ ; CHECK-LABEL: name: b |
| 120 | ++ ; CHECK: liveins: $x3, $x4, $x29, $x30 |
| 121 | ++ ; CHECK: $x0 = MFLR8 implicit $lr8 |
| 122 | ++ ; CHECK: STD killed $x29, -24, $x1 :: (store 8 into %fixed-stack.0) |
| 123 | ++ ; CHECK: STD killed $x30, -16, $x1 :: (store 8 into %fixed-stack.1, align 16) |
| 124 | ++ ; CHECK: STD killed $x0, 16, $x1 |
| 125 | ++ ; CHECK: $x1 = STDU $x1, -64, $x1 |
| 126 | ++ ; CHECK: $x30 = OR8 killed $x4, $x4 |
| 127 | ++ ; CHECK: dead $r4 = LI 10, implicit-def $x4 |
| 128 | ++ ; CHECK: $x29 = OR8 $x3, $x3 |
| 129 | ++ ; CHECK: BL8_NOP @g, csr_ppc64_r2_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit killed $x4, implicit $x2, implicit-def $r1, implicit-def $x3 |
| 130 | ++ ; CHECK: STW8 killed renamable $x3, 0, killed renamable $x30 :: (store 4 into %ir.b) |
| 131 | ++ ; CHECK: $x3 = OR8 killed $x29, $x29 |
| 132 | ++ ; CHECK: BL8_NOP @g, csr_ppc64_r2_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit $x2, implicit-def $r1, implicit-def $x3 |
| 133 | ++ ; CHECK: $x1 = ADDI8 $x1, 64 |
| 134 | ++ ; CHECK: $x0 = LD 16, $x1 |
| 135 | ++ ; CHECK: $x30 = LD -16, $x1 :: (load 8 from %fixed-stack.1, align 16) |
| 136 | ++ ; CHECK: $x29 = LD -24, $x1 :: (load 8 from %fixed-stack.0) |
| 137 | ++ ; CHECK: MTLR8 killed $x0, implicit-def $lr8 |
| 138 | ++ ; CHECK: BLR8 implicit $lr8, implicit $rm, implicit killed $x3 |
| 139 | ++ $x0 = MFLR8 implicit $lr8 |
| 140 | ++ STD killed $x29, -24, $x1 :: (store 8 into %fixed-stack.1) |
| 141 | ++ STD killed $x30, -16, $x1 :: (store 8 into %fixed-stack.0, align 16) |
| 142 | ++ STD killed $x0, 16, $x1 |
| 143 | ++ $x1 = STDU $x1, -64, $x1 |
| 144 | ++ $x30 = OR8 killed $x4, $x4 |
| 145 | ++ dead $r4 = LI 10, implicit-def $x4 |
| 146 | ++ $x29 = OR8 $x3, $x3 |
| 147 | ++ BL8_NOP @g, csr_ppc64_r2_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit killed $x4, implicit $x2, implicit-def $r1, implicit-def $x3 |
| 148 | ++ STW8 killed renamable $x3, 0, killed renamable $x30 :: (store 4 into %ir.b) |
| 149 | ++ $x3 = OR8 killed $x29, $x29 |
| 150 | ++ BL8_NOP @g, csr_ppc64_r2_altivec, implicit-def dead $lr8, implicit $rm, implicit killed $x3, implicit $x2, implicit-def $r1, implicit-def $x3 |
| 151 | ++ $x1 = ADDI8 $x1, 64 |
| 152 | ++ $x0 = LD 16, $x1 |
| 153 | ++ $x30 = LD -16, $x1 :: (load 8 from %fixed-stack.0, align 16) |
| 154 | ++ $x29 = LD -24, $x1 :: (load 8 from %fixed-stack.1) |
| 155 | ++ MTLR8 killed $x0, implicit-def $lr8 |
| 156 | ++ BLR8 implicit $lr8, implicit $rm, implicit killed $x3 |
| 157 | ++ |
| 158 | ++... |
| 159 | +-- |
| 160 | +2.26.0 |
| 161 | + |
0 commit comments