Skip to content

Commit e24b104

Browse files
committed
[ARM GlobalISel] Support G_GEP for Thumb2
Same as ARM, but use a different opcode in the instruction selection. llvm-svn: 353151
1 parent dccfaff commit e24b104

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed

llvm/lib/Target/ARM/ARMInstructionSelector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ bool ARMInstructionSelector::select(MachineInstr &I,
930930
return selectShift(ARM_AM::ShiftOpc::lsl, MIB);
931931
}
932932
case G_GEP:
933-
I.setDesc(TII.get(ARM::ADDrr));
933+
I.setDesc(TII.get(STI.isThumb2() ? ARM::t2ADDrr : ARM::ADDrr));
934934
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
935935
break;
936936
case G_FRAME_INDEX:

llvm/lib/Target/ARM/ARMLegalizerInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
131131
{s32, p0, 32},
132132
{p0, p0, 32}});
133133

134+
getActionDefinitionsBuilder(G_GEP).legalFor({{p0, s32}});
135+
134136
if (ST.isThumb()) {
135137
// FIXME: merge with the code for non-Thumb.
136138
computeTables();
@@ -161,8 +163,6 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
161163
.clampScalar(0, s32, s32);
162164
}
163165

164-
getActionDefinitionsBuilder(G_GEP).legalFor({{p0, s32}});
165-
166166
getActionDefinitionsBuilder(G_SELECT).legalForCartesianProduct({s32, p0},
167167
{s1});
168168

llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-load-store.mir

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# RUN: llc -mtriple thumb-- -mattr=+v6t2 -run-pass=legalizer %s -o - | FileCheck %s
33
--- |
44
define void @test_legal_loads_stores() { ret void }
5+
6+
define void @test_gep() { ret void }
57
...
68
---
79
name: test_legal_loads_stores
@@ -47,3 +49,28 @@ body: |
4749
G_STORE %6(p0), %0(p0) :: (store 4)
4850
BX_RET 14, $noreg
4951
...
52+
---
53+
name: test_gep
54+
# CHECK-LABEL: name: test_gep
55+
legalized: false
56+
# CHECK: legalized: true
57+
regBankSelected: false
58+
selected: false
59+
tracksRegLiveness: true
60+
registers:
61+
- { id: 0, class: _ }
62+
- { id: 1, class: _ }
63+
- { id: 2, class: _ }
64+
body: |
65+
bb.0:
66+
liveins: $r0, $r1
67+
68+
%0(p0) = COPY $r0
69+
%1(s32) = COPY $r1
70+
71+
; CHECK: {{%[0-9]+}}:_(p0) = G_GEP {{%[0-9]+}}, {{%[0-9]+}}(s32)
72+
%2(p0) = G_GEP %0, %1(s32)
73+
74+
$r0 = COPY %2(p0)
75+
BX_RET 14, $noreg, implicit $r0
76+
...

llvm/test/CodeGen/ARM/GlobalISel/arm-legalizer.mir

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
define void @test_load_from_stack() { ret void }
44
define void @test_load_store_64() #0 { ret void }
55

6-
define void @test_gep() { ret void }
7-
86
define void @test_constants_s64() { ret void }
97

108
define void @test_icmp_s8() { ret void }
@@ -85,31 +83,6 @@ body: |
8583
BX_RET 14, $noreg
8684
...
8785
---
88-
name: test_gep
89-
# CHECK-LABEL: name: test_gep
90-
legalized: false
91-
# CHECK: legalized: true
92-
regBankSelected: false
93-
selected: false
94-
tracksRegLiveness: true
95-
registers:
96-
- { id: 0, class: _ }
97-
- { id: 1, class: _ }
98-
- { id: 2, class: _ }
99-
body: |
100-
bb.0:
101-
liveins: $r0, $r1
102-
103-
%0(p0) = COPY $r0
104-
%1(s32) = COPY $r1
105-
106-
; CHECK: {{%[0-9]+}}:_(p0) = G_GEP {{%[0-9]+}}, {{%[0-9]+}}(s32)
107-
%2(p0) = G_GEP %0, %1(s32)
108-
109-
$r0 = COPY %2(p0)
110-
BX_RET 14, $noreg, implicit $r0
111-
...
112-
---
11386
name: test_constants_s64
11487
# CHECK-LABEL: name: test_constants_s64
11588
legalized: false

llvm/test/CodeGen/ARM/GlobalISel/thumb-select-load-store.mir

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
define void @test_s8() { ret void }
44
define void @test_s16() { ret void }
55
define void @test_s32() { ret void }
6+
7+
define void @test_gep() { ret void }
68
...
79
---
810
name: test_s8
@@ -82,3 +84,33 @@ body: |
8284
BX_RET 14, $noreg
8385
; CHECK: BX_RET 14, $noreg
8486
...
87+
---
88+
name: test_gep
89+
# CHECK-LABEL: name: test_gep
90+
legalized: true
91+
regBankSelected: true
92+
selected: false
93+
# CHECK: selected: true
94+
registers:
95+
- { id: 0, class: gprb }
96+
- { id: 1, class: gprb }
97+
- { id: 2, class: gprb }
98+
body: |
99+
bb.0:
100+
liveins: $r0, $r1
101+
102+
%0(p0) = COPY $r0
103+
; CHECK: [[PTR:%[0-9]+]]:gprnopc = COPY $r0
104+
105+
%1(s32) = COPY $r1
106+
; CHECK: [[OFF:%[0-9]+]]:rgpr = COPY $r1
107+
108+
%2(p0) = G_GEP %0, %1(s32)
109+
; CHECK: [[GEP:%[0-9]+]]:gprnopc = t2ADDrr [[PTR]], [[OFF]], 14, $noreg, $noreg
110+
111+
$r0 = COPY %2(p0)
112+
; CHECK: $r0 = COPY [[GEP]]
113+
114+
BX_RET 14, $noreg, implicit $r0
115+
; CHECK: BX_RET 14, $noreg, implicit $r0
116+
...

0 commit comments

Comments
 (0)