Skip to content

Commit 7524ad9

Browse files
committed
[AArch64][GlobalISel] Fix incorrect selection of monotonic s32->s64 anyext load.
This load isn't selected by tablegen due to the anyext, but wasn't generating a subreg_to_reg. Maybe it shouldn't be formed at all during the combiner but to stop crashes later in codegen select it manually for now.
1 parent 7c63431 commit 7524ad9

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,13 +2997,14 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
29972997
}
29982998
}
29992999

3000-
if (IsZExtLoad) {
3001-
// The zextload from a smaller type to i32 should be handled by the
3000+
if (IsZExtLoad ||
3001+
(isa<GLoad>(LdSt) && ValTy == LLT::scalar(64) && MemSizeInBits == 32)) {
3002+
// The any/zextload from a smaller type to i32 should be handled by the
30023003
// importer.
30033004
if (MRI.getType(LoadStore->getOperand(0).getReg()).getSizeInBits() != 64)
30043005
return false;
3005-
// If we have a ZEXTLOAD then change the load's type to be a narrower reg
3006-
// and zero_extend with SUBREG_TO_REG.
3006+
// If we have an extending load then change the load's type to be a
3007+
// narrower reg and zero_extend with SUBREG_TO_REG.
30073008
Register LdReg = MRI.createVirtualRegister(&AArch64::GPR32RegClass);
30083009
Register DstReg = LoadStore->getOperand(0).getReg();
30093010
LoadStore->getOperand(0).setReg(LdReg);

llvm/test/CodeGen/AArch64/GlobalISel/select-atomic-load-store.mir

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
ret i8 %v
1010
}
1111

12+
define i32 @anyext_load_monotonic_i32() {
13+
%v = load atomic i32, ptr null monotonic, align 4
14+
ret i32 %v
15+
}
16+
1217
...
1318
---
1419
name: load_acq_i8
@@ -25,13 +30,33 @@ body: |
2530
2631
; CHECK-LABEL: name: load_acq_i8
2732
; CHECK: liveins: $x0
28-
; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
29-
; CHECK: [[LDARB:%[0-9]+]]:gpr32 = LDARB [[COPY]] :: (load acquire (s8) from %ir.ptr, align 8)
30-
; CHECK: $w0 = COPY [[LDARB]]
31-
; CHECK: RET_ReallyLR implicit $w0
33+
; CHECK-NEXT: {{ $}}
34+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
35+
; CHECK-NEXT: [[LDARB:%[0-9]+]]:gpr32 = LDARB [[COPY]] :: (load acquire (s8) from %ir.ptr, align 8)
36+
; CHECK-NEXT: $w0 = COPY [[LDARB]]
37+
; CHECK-NEXT: RET_ReallyLR implicit $w0
3238
%0:gpr(p0) = COPY $x0
3339
%2:gpr(s32) = G_LOAD %0(p0) :: (load acquire (s8) from %ir.ptr, align 8)
3440
$w0 = COPY %2(s32)
3541
RET_ReallyLR implicit $w0
3642
3743
...
44+
---
45+
name: anyext_load_monotonic_i32
46+
legalized: true
47+
regBankSelected: true
48+
tracksRegLiveness: true
49+
body: |
50+
bb.1:
51+
; CHECK-LABEL: name: anyext_load_monotonic_i32
52+
; CHECK: [[COPY:%[0-9]+]]:gpr64common = COPY $xzr
53+
; CHECK-NEXT: [[LDRWui:%[0-9]+]]:gpr32 = LDRWui [[COPY]], 0 :: (load monotonic (s32) from `ptr null`)
54+
; CHECK-NEXT: %ld:gpr64all = SUBREG_TO_REG 0, [[LDRWui]], %subreg.sub_32
55+
; CHECK-NEXT: $x0 = COPY %ld
56+
; CHECK-NEXT: RET_ReallyLR implicit $x0
57+
%1:gpr(p0) = G_CONSTANT i64 0
58+
%ld:gpr(s64) = G_LOAD %1(p0) :: (load monotonic (s32) from `ptr null`)
59+
$x0 = COPY %ld(s64)
60+
RET_ReallyLR implicit $x0
61+
62+
...

0 commit comments

Comments
 (0)