[ARM] GlobalISel: Select 32-bit G_CONSTANT
authorDiana Picus <diana.picus@linaro.org>
Tue, 28 Feb 2017 13:05:42 +0000 (13:05 +0000)
committerDiana Picus <diana.picus@linaro.org>
Tue, 28 Feb 2017 13:05:42 +0000 (13:05 +0000)
Put it into a register by means of a MOVi.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296471 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMInstructionSelector.cpp
test/CodeGen/ARM/GlobalISel/arm-instruction-select.mir

index dccd717eb995ef1d0a1017237b5c45dfc7b33693..d7e5220f9247a7384acefb66705f5967c48e8b76 100644 (file)
@@ -313,6 +313,17 @@ bool ARMInstructionSelector::select(MachineInstr &I) const {
     I.setDesc(TII.get(ARM::ADDri));
     MIB.addImm(0).add(predOps(ARMCC::AL)).add(condCodeOp());
     break;
+  case G_CONSTANT: {
+    unsigned Reg = I.getOperand(0).getReg();
+    if (MRI.getType(Reg).getSizeInBits() != 32)
+      return false;
+
+    assert(RBI.getRegBank(Reg, MRI, TRI)->getID() == ARM::GPRRegBankID &&
+           "Expected constant to live in a GPR");
+    I.setDesc(TII.get(ARM::MOVi));
+    MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
+    break;
+  }
   case G_STORE:
   case G_LOAD: {
     const auto &MemOp = **I.memoperands_begin();
index 847c10c29701c2b93b101c13a2c0618922ba7ae1..57fea9a5dbabd7d27e9bb390d2fe4b15c955c298 100644 (file)
@@ -19,6 +19,7 @@
   define void @test_stores() #0 { ret void }
 
   define void @test_gep() { ret void }
+  define void @test_constants() { ret void }
 
   define void @test_soft_fp_double() #0 { ret void }
 
@@ -466,6 +467,24 @@ body:             |
     BX_RET 14, _, implicit %r0
 ...
 ---
+name:            test_constants
+# CHECK-LABEL: name: test_constants
+legalized:       true
+regBankSelected: true
+selected:        false
+# CHECK: selected: true
+registers:
+  - { id: 0, class: gprb }
+# CHECK: id: [[C:[0-9]+]], class: gpr
+body:             |
+  bb.0:
+    %0(s32) = G_CONSTANT 42
+    ; CHECK: %[[C]] = MOVi 42, 14, _, _
+
+    %r0 = COPY %0(s32)
+    BX_RET 14, _, implicit %r0
+...
+---
 name:            test_soft_fp_double
 # CHECK-LABEL: name: test_soft_fp_double
 legalized:       true