[PATCH] D30554: [AArch64] Extend redundant copy elimination pass to handle shifted compares.
Chad Rosier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 14:32:44 PST 2017
mcrosier created this revision.
Herald added subscribers: rengolin, aemerson.
Please take a look.
Chad
https://reviews.llvm.org/D30554
Files:
lib/Target/AArch64/AArch64RedundantCopyElimination.cpp
test/CodeGen/AArch64/machine-copy-remove.mir
Index: test/CodeGen/AArch64/machine-copy-remove.mir
===================================================================
--- test/CodeGen/AArch64/machine-copy-remove.mir
+++ test/CodeGen/AArch64/machine-copy-remove.mir
@@ -535,3 +535,28 @@
bb.2:
RET_ReallyLR
+...
+# Eliminate redundant MOVi32imm 4096 in bb.1 when the compare has a shifted immediate.
+# CHECK-LABEL: name: test19
+# CHECK: bb.1:
+# CHECK-NOT: MOVi32imm
+name: test19
+tracksRegLiveness: true
+body: |
+ bb.0.entry:
+ successors: %bb.1, %bb.2
+ liveins: %w0, %x1
+
+ dead %wzr = SUBSWri killed %w0, 1, 12, implicit-def %nzcv
+ Bcc 1, %bb.2, implicit killed %nzcv
+ B %bb.1
+
+ bb.1:
+ successors: %bb.2
+ liveins: %x1
+
+ %w0 = MOVi32imm 4096
+ STRWui killed %w0, killed %x1, 0
+
+ bb.2:
+ RET_ReallyLR
Index: lib/Target/AArch64/AArch64RedundantCopyElimination.cpp
===================================================================
--- lib/Target/AArch64/AArch64RedundantCopyElimination.cpp
+++ lib/Target/AArch64/AArch64RedundantCopyElimination.cpp
@@ -166,18 +166,18 @@
if (!PredI.getOperand(2).isImm())
return None;
- // FIXME: For simplicity, give up on non-zero shifts.
- if (PredI.getOperand(3).getImm())
- return None;
+
// The src register must not be modified between the cmp and conditional
// branch. This includes a self-clobbering compare.
if (ClobberedRegs[SrcReg])
return None;
// We've found the Cmp that sets NZCV.
+ int32_t Imm = PredI.getOperand(2).getImm();
+ int32_t Shift = PredI.getOperand(3).getImm();
FirstUse = PredI;
- return RegImm(PredI.getOperand(1).getReg(), PredI.getOperand(2).getImm());
+ return RegImm(PredI.getOperand(1).getReg(), Imm << Shift);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30554.90397.patch
Type: text/x-patch
Size: 1835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/8716ab46/attachment.bin>
More information about the llvm-commits
mailing list