Skip to content

Commit ebb5f1a

Browse files
committed
[AArch64][GlobalISel] Fix crash when selecting an anyextending FP load.
We split anyext FP loads back into a regular load + extend, but when we do that we need to ensure that some state about the instruction is updated to correctly reflect the new reality. rdar://141660282
1 parent 16e4223 commit ebb5f1a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,8 +3055,8 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
30553055
#endif
30563056

30573057
const Register ValReg = LdSt.getReg(0);
3058-
const LLT ValTy = MRI.getType(ValReg);
30593058
const RegisterBank &RB = *RBI.getRegBank(ValReg, MRI, TRI);
3059+
LLT ValTy = MRI.getType(ValReg);
30603060

30613061
// The code below doesn't support truncating stores, so we need to split it
30623062
// again.
@@ -3096,6 +3096,7 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
30963096
auto SubRegRC = getRegClassForTypeOnBank(MRI.getType(OldDst), RB);
30973097
RBI.constrainGenericRegister(OldDst, *SubRegRC, MRI);
30983098
MIB.setInstr(LdSt);
3099+
ValTy = MemTy; // This is no longer an extending load.
30993100
}
31003101
}
31013102

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -O0 -o - %s | FileCheck %s
3+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
4+
target triple = "arm64e-apple-macosx10.15.0"
5+
6+
; Check we don't crash here when selecting an anyextending FP load.
7+
8+
define i32 @test() {
9+
; CHECK-LABEL: test:
10+
; CHECK: ; %bb.0: ; %entry
11+
; CHECK-NEXT: sub sp, sp, #80
12+
; CHECK-NEXT: stp x29, x30, [sp, #64] ; 16-byte Folded Spill
13+
; CHECK-NEXT: .cfi_def_cfa_offset 80
14+
; CHECK-NEXT: .cfi_offset w30, -8
15+
; CHECK-NEXT: .cfi_offset w29, -16
16+
; CHECK-NEXT: mov x8, #0 ; =0x0
17+
; CHECK-NEXT: ldr s0, [x8]
18+
; CHECK-NEXT: ; kill: def $d0 killed $s0
19+
; CHECK-NEXT: mov x8, sp
20+
; CHECK-NEXT: mov w9, #0 ; =0x0
21+
; CHECK-NEXT: str w9, [sp, #60] ; 4-byte Folded Spill
22+
; CHECK-NEXT: str xzr, [x8]
23+
; CHECK-NEXT: str xzr, [x8, #8]
24+
; CHECK-NEXT: str xzr, [x8, #16]
25+
; CHECK-NEXT: str xzr, [x8, #24]
26+
; CHECK-NEXT: str d0, [x8, #32]
27+
; CHECK-NEXT: str xzr, [x8, #40]
28+
; CHECK-NEXT: mov x8, #0 ; =0x0
29+
; CHECK-NEXT: mov x0, x8
30+
; CHECK-NEXT: blr x8
31+
; CHECK-NEXT: ldr w0, [sp, #60] ; 4-byte Folded Reload
32+
; CHECK-NEXT: ldp x29, x30, [sp, #64] ; 16-byte Folded Reload
33+
; CHECK-NEXT: add sp, sp, #80
34+
; CHECK-NEXT: ret
35+
entry:
36+
%0 = inttoptr i64 0 to ptr
37+
%1 = load i32, ptr %0, align 4
38+
%call86 = call i32 (ptr, ...) null(ptr null, i32 0, i32 0, i32 0, i32 0, i32 %1, i32 0)
39+
%2 = load float, ptr %0, align 4
40+
ret i32 0
41+
}
42+

0 commit comments

Comments
 (0)