[PATCH] D85288: [PowerPC] Remove implicit use register after transformToImmFormFedByLI()
Zhang Kang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 03:12:01 PDT 2020
ZhangKang created this revision.
ZhangKang added reviewers: nemanjai, jsji, efriedma, PowerPC.
ZhangKang added a project: LLVM.
Herald added subscribers: shchenz, wuzish, hiraditya.
ZhangKang requested review of this revision.
When the instruction has imm form and fed by LI, we can remove the redundat LI instruction.
Below is an example:
renamable $x5 = LI8 2
renamable $x4 = exact SRD killed renamable $x4, killed renamable $r5, implicit $x5
will be converted to:
renamable $x5 = LI8 2
renamable $x4 = exact RLDICL killed renamable $x4, 62, 2, implicit killed $x5
``
But when we do this optimization, we forget to remove implicit killed $x5
This bug has caused a lnt case error. This patch is to fix above bug.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85288
Files:
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
llvm/test/CodeGen/PowerPC/remove-redundant-li-implicit-reg.mir
Index: llvm/test/CodeGen/PowerPC/remove-redundant-li-implicit-reg.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/remove-redundant-li-implicit-reg.mir
@@ -0,0 +1,23 @@
+# RUN: llc -mtriple=powerpc64le--linux-gnu -stop-after ppc-pre-emit-peephole %s -o - -verify-machineinstrs | FileCheck %s
+
+
+---
+name: testRedundantLiImplicitReg
+tracksRegLiveness: true
+body: |
+ bb.0.entry:
+ liveins: $x3, $x4, $x5
+
+ STW killed $r3, killed $x5, 100
+ renamable $x5 = LI8 2
+ renamable $x4 = exact SRD killed renamable $x4, killed renamable $r5, implicit $x5
+ STD $x4, $x4, 100
+ BLR8 implicit $lr8, implicit $rm
+
+ ; CHECK-LABEL: testRedundantLiImplicitReg
+ ; CHECK: bb.0.entry:
+ ; CHECK: STW killed $r3, killed $x5, 100
+ ; CHECK: renamable $x4 = exact RLDICL killed renamable $x4, 62, 2
+ ; CHECK: STD killed $x4, $x4, 100
+ ; CHECK: BLR8 implicit $lr8, implicit $rm
+...
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -4210,6 +4210,20 @@
}
}
+ // Remove the implicit registers defined by DefMI.
+ const TargetRegisterInfo *TRI = &getRegisterInfo();
+ int idx = MI.findRegisterUseOperandIdx(DefMI.getOperand(0).getReg(),
+ false, TRI);
+ if (idx != -1 && MI.getOperand(idx).isImplicit()) {
+ // Below is an example:
+ // renamable $x5 = LI8 2
+ // renamable $x4 = exact RLDICL killed renamable $x4, 62, 2, implicit $x5
+ // ==> Remove the implicit $x5
+ // dead renamable $x5 = LI8 2
+ // renamable $x4 = exact RLDICL killed renamable $x4, 62, 2
+ MI.RemoveOperand(idx);
+ }
+
// Fix up killed/dead flag after transformation.
// Pattern:
// ForwardKilledOperandReg = LI imm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85288.283177.patch
Type: text/x-patch
Size: 1922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/51d8b087/attachment-0001.bin>
More information about the llvm-commits
mailing list