Skip to content

Commit

Permalink
[ARM] GlobalISel: Select 32-bit G_CONSTANT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rovka committed Feb 28, 2017
1 parent 568082b commit de6b127
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Target/ARM/ARMInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 19 additions & 0 deletions test/CodeGen/ARM/GlobalISel/arm-instruction-select.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de6b127

Please sign in to comment.