Skip to content

Commit 8987d00

Browse files
committedJan 14, 2019
[ARM GlobalISel] Import MOVi32imm into GlobalISel
Make it possible for TableGen to produce code for selecting MOVi32imm. This allows reasonably recent ARM targets to select a lot more constants than before. We achieve this by adding GISelPredicateCode to arm_i32imm. It's impossible to use the exact same code for both DAGISel and GlobalISel, since one uses "Subtarget->" and the other "STI." to refer to the subtarget. Moreover, in GlobalISel we don't have ready access to the MachineFunction, so we need to add a bit of code for obtaining it from the instruction that we're selecting. This is also the reason why it needs to remain a PatLeaf instead of the more specific IntImmLeaf. llvm-svn: 351056
1 parent 3d42815 commit 8987d00

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
 

‎llvm/lib/Target/ARM/ARMInstrInfo.td

+14-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,20 @@ def arm_i32imm : PatLeaf<(imm), [{
722722
if (Subtarget->useMovt(*MF))
723723
return true;
724724
return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
725-
}]>;
725+
}]> {
726+
// Ideally this would be an IntImmLeaf, but then we wouldn't have access to
727+
// the MachineFunction.
728+
let GISelPredicateCode = [{
729+
const auto &MF = *MI.getParent()->getParent();
730+
if (STI.useMovt(MF))
731+
return true;
732+
733+
const auto &MO = MI.getOperand(1);
734+
if (!MO.isCImm())
735+
return false;
736+
return ARM_AM::isSOImmTwoPartVal(MO.getCImm()->getZExtValue());
737+
}];
738+
}
726739

727740
/// imm0_1 predicate - Immediate in the range [0,1].
728741
def Imm0_1AsmOperand: ImmAsmOperand<0,1> { let Name = "Imm0_1"; }

‎llvm/test/CodeGen/ARM/GlobalISel/arm-instruction-select.mir

+21
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@
6464
define void @test_stores() #0 { ret void }
6565

6666
define void @test_gep() { ret void }
67+
68+
define void @test_MOVi32imm() #3 { ret void }
69+
6770
define void @test_constant_imm() { ret void }
6871
define void @test_constant_cimm() { ret void }
72+
6973
define void @test_pointer_constant_unconstrained() { ret void }
7074
define void @test_pointer_constant_constrained() { ret void }
7175

@@ -1481,6 +1485,23 @@ body: |
14811485
BX_RET 14, $noreg, implicit $r0
14821486
...
14831487
---
1488+
name: test_MOVi32imm
1489+
# CHECK-LABEL: name: test_MOVi32imm
1490+
legalized: true
1491+
regBankSelected: true
1492+
selected: false
1493+
# CHECK: selected: true
1494+
registers:
1495+
- { id: 0, class: gprb }
1496+
body: |
1497+
bb.0:
1498+
%0(s32) = G_CONSTANT 65537
1499+
; CHECK: %[[C:[0-9]+]]:gpr = MOVi32imm 65537
1500+
1501+
$r0 = COPY %0(s32)
1502+
BX_RET 14, $noreg, implicit $r0
1503+
...
1504+
---
14841505
name: test_constant_imm
14851506
# CHECK-LABEL: name: test_constant_imm
14861507
legalized: true

0 commit comments

Comments
 (0)
Please sign in to comment.