Skip to content

Commit 70579c9

Browse files
authored
[AArch64][GlobalISel] Look into array's element (#74109)
In AArch64RegisterBankInfo, IsFPOrFPType() does not work correctly with ArrayTypes and StructTypes as it does not not look at their elements. This caused some registers to be selected as gpr instead of fpr.
1 parent cb1a7d2 commit 70579c9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,13 @@ bool AArch64RegisterBankInfo::isLoadFromFPType(const MachineInstr &MI) const {
621621
Type *EltTy = nullptr;
622622
if (const GlobalValue *GV = dyn_cast<GlobalValue>(LdVal)) {
623623
EltTy = GV->getValueType();
624+
// Look at the first element of the struct to determine the type we are
625+
// loading
626+
while (StructType *StructEltTy = dyn_cast<StructType>(EltTy))
627+
EltTy = StructEltTy->getTypeAtIndex(0U);
628+
// Look at the first element of the array to determine its type
629+
if (isa<ArrayType>(EltTy))
630+
EltTy = EltTy->getArrayElementType();
624631
} else {
625632
// FIXME: grubbing around uses is pretty ugly, but with no more
626633
// `getPointerElementType` there's not much else we can do.

llvm/test/CodeGen/AArch64/GlobalISel/regbankselect-fp-loads.mir

+6-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ body: |
123123
; CHECK-NEXT: {{ $}}
124124
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr(s32) = COPY $w0
125125
; CHECK-NEXT: [[GV:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @array_double
126-
; CHECK-NEXT: %fp_load:gpr(s64) = G_LOAD [[GV]](p0) :: (dereferenceable load (s64) from @array_double)
126+
; CHECK-NEXT: %fp_load:fpr(s64) = G_LOAD [[GV]](p0) :: (dereferenceable load (s64) from @array_double)
127127
; CHECK-NEXT: {{ $}}
128128
; CHECK-NEXT: bb.1:
129129
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
130130
; CHECK-NEXT: {{ $}}
131-
; CHECK-NEXT: [[PHI:%[0-9]+]]:gpr(s32) = PHI %fp_load(s64), %bb.0, [[PHI]](s32), %bb.1
131+
; CHECK-NEXT: [[PHI:%[0-9]+]]:fpr(s32) = PHI %fp_load(s64), %bb.0, [[PHI]](s32), %bb.1
132132
; CHECK-NEXT: G_BRCOND [[COPY]](s32), %bb.1
133133
; CHECK-NEXT: {{ $}}
134134
; CHECK-NEXT: bb.2:
@@ -164,12 +164,12 @@ body: |
164164
; CHECK-NEXT: {{ $}}
165165
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr(s32) = COPY $w0
166166
; CHECK-NEXT: [[GV:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @struct_array_double
167-
; CHECK-NEXT: %fp_load:gpr(s64) = G_LOAD [[GV]](p0) :: (dereferenceable load (s64) from @struct_array_double)
167+
; CHECK-NEXT: %fp_load:fpr(s64) = G_LOAD [[GV]](p0) :: (dereferenceable load (s64) from @struct_array_double)
168168
; CHECK-NEXT: {{ $}}
169169
; CHECK-NEXT: bb.1:
170170
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
171171
; CHECK-NEXT: {{ $}}
172-
; CHECK-NEXT: [[PHI:%[0-9]+]]:gpr(s32) = PHI %fp_load(s64), %bb.0, [[PHI]](s32), %bb.1
172+
; CHECK-NEXT: [[PHI:%[0-9]+]]:fpr(s32) = PHI %fp_load(s64), %bb.0, [[PHI]](s32), %bb.1
173173
; CHECK-NEXT: G_BRCOND [[COPY]](s32), %bb.1
174174
; CHECK-NEXT: {{ $}}
175175
; CHECK-NEXT: bb.2:
@@ -205,12 +205,12 @@ body: |
205205
; CHECK-NEXT: {{ $}}
206206
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr(s32) = COPY $w0
207207
; CHECK-NEXT: [[GV:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @struct_struct_array_double
208-
; CHECK-NEXT: %fp_load:gpr(s64) = G_LOAD [[GV]](p0) :: (dereferenceable load (s64) from @struct_struct_array_double)
208+
; CHECK-NEXT: %fp_load:fpr(s64) = G_LOAD [[GV]](p0) :: (dereferenceable load (s64) from @struct_struct_array_double)
209209
; CHECK-NEXT: {{ $}}
210210
; CHECK-NEXT: bb.1:
211211
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
212212
; CHECK-NEXT: {{ $}}
213-
; CHECK-NEXT: [[PHI:%[0-9]+]]:gpr(s32) = PHI %fp_load(s64), %bb.0, [[PHI]](s32), %bb.1
213+
; CHECK-NEXT: [[PHI:%[0-9]+]]:fpr(s32) = PHI %fp_load(s64), %bb.0, [[PHI]](s32), %bb.1
214214
; CHECK-NEXT: G_BRCOND [[COPY]](s32), %bb.1
215215
; CHECK-NEXT: {{ $}}
216216
; CHECK-NEXT: bb.2:

0 commit comments

Comments
 (0)