[PATCH] D64108: [GlobalISel][AArch64] Use getConstantVRegValWithLookThrough for selectArithImmed

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 16:40:54 PDT 2019


paquette updated this revision to Diff 207655.
paquette added a comment.

Use `getConstantVRegValWithLookThrough` properly and update test to include a weird number which should lose some bits in the G_TRUNC.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64108/new/

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,49 @@
     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
+
+...
+---
+name:            cmp_imm_lookthrough_bad_trunc
+legalized:       true
+regBankSelected: true
+tracksRegLiveness: true
+body:             |
+  bb.1:
+    liveins: $w0
+    ; CHECK-LABEL: name: cmp_imm_lookthrough_bad_trunc
+    ; CHECK: liveins: $w0
+    ; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
+    ; CHECK: [[MOVi64imm:%[0-9]+]]:gpr64common = MOVi64imm -214721
+    ; CHECK: [[COPY1:%[0-9]+]]:gpr32common = COPY [[MOVi64imm]].sub_32
+    ; CHECK: $wzr = SUBSWrr [[COPY]], [[COPY1]], 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 -214721
+    %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,13 +3665,11 @@
   else if (Root.isCImm())
     Immed = Root.getCImm()->getZExtValue();
   else if (Root.isReg()) {
-    MachineInstr *Def = MRI.getVRegDef(Root.getReg());
-    if (Def->getOpcode() != TargetOpcode::G_CONSTANT)
-      return None;
-    MachineOperand &Op1 = Def->getOperand(1);
-    if (!Op1.isCImm() || Op1.getCImm()->getBitWidth() > 64)
+    auto ValAndVReg =
+        getConstantVRegValWithLookThrough(Root.getReg(), MRI, true);
+    if (!ValAndVReg)
       return None;
-    Immed = Op1.getCImm()->getZExtValue();
+    Immed = ValAndVReg->Value;
   } else
     return None;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64108.207655.patch
Type: text/x-patch
Size: 2748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190702/868ef0ec/attachment.bin>


More information about the llvm-commits mailing list