[PATCH] D64108: [GlobalISel][AArch64] Use getConstantVRegValWithLookThrough for selectArithImmed
Jessica Paquette via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 15:51:53 PDT 2019
paquette created this revision.
paquette added a reviewer: aemerson.
Herald added subscribers: Petar.Avramovic, hiraditya, kristof.beyls, javed.absar, rovka.
Herald added a project: LLVM.
Look through G_TRUNCs, G_SEXTs, and G_ZEXTs when looking for a G_CONSTANT instead of giving up when the first thing we see isn't a G_CONSTANT.
This gives an average ~1.3% code size improvement on CINT2000 at -O3.
https://reviews.llvm.org/D64108
Files:
llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
llvm/test/CodeGen/AArch64/GlobalISel/select-cmp.mir
Index: llvm/test/CodeGen/AArch64/GlobalISel/select-cmp.mir
===================================================================
--- llvm/test/CodeGen/AArch64/GlobalISel/select-cmp.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/select-cmp.mir
@@ -70,3 +70,24 @@
RET_ReallyLR implicit $w0
...
+---
+name: cmp_imm_lookthrough
+legalized: true
+regBankSelected: true
+tracksRegLiveness: true
+body: |
+ bb.1:
+ liveins: $w0
+ ; CHECK-LABEL: name: cmp_imm_lookthrough
+ ; CHECK: liveins: $w0
+ ; CHECK: [[COPY:%[0-9]+]]:gpr32sp = COPY $w0
+ ; CHECK: $wzr = SUBSWri [[COPY]], 42, 0, implicit-def $nzcv
+ ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv
+ ; CHECK: $w0 = COPY [[CSINCWr]]
+ ; CHECK: RET_ReallyLR implicit $w0
+ %0:gpr(s32) = COPY $w0
+ %1:gpr(s64) = G_CONSTANT i64 42
+ %2:gpr(s32) = G_TRUNC %1(s64)
+ %5:gpr(s32) = G_ICMP intpred(eq), %0(s32), %2
+ $w0 = COPY %5(s32)
+ RET_ReallyLR implicit $w0
Index: llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
+++ llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
@@ -3665,7 +3665,11 @@
else if (Root.isCImm())
Immed = Root.getCImm()->getZExtValue();
else if (Root.isReg()) {
- MachineInstr *Def = MRI.getVRegDef(Root.getReg());
+ auto ValAndVReg =
+ getConstantVRegValWithLookThrough(Root.getReg(), MRI, true);
+ if (!ValAndVReg)
+ return None;
+ MachineInstr *Def = MRI.getVRegDef(ValAndVReg->VReg);
if (Def->getOpcode() != TargetOpcode::G_CONSTANT)
return None;
MachineOperand &Op1 = Def->getOperand(1);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64108.207646.patch
Type: text/x-patch
Size: 1752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190702/e454412e/attachment.bin>
More information about the llvm-commits
mailing list