Skip to content

Commit d422e90

Browse files
author
Thorsten Schütt
authored
[GlobalIsel][AArch64] fix out of range access in regbankselect (#92072)
Fixes #92062
1 parent e60b83a commit d422e90

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,11 @@ bool AArch64RegisterBankInfo::isLoadFromFPType(const MachineInstr &MI) const {
600600
EltTy = GV->getValueType();
601601
// Look at the first element of the struct to determine the type we are
602602
// loading
603-
while (StructType *StructEltTy = dyn_cast<StructType>(EltTy))
603+
while (StructType *StructEltTy = dyn_cast<StructType>(EltTy)) {
604+
if (StructEltTy->getNumElements() == 0)
605+
break;
604606
EltTy = StructEltTy->getTypeAtIndex(0U);
607+
}
605608
// Look at the first element of the array to determine its type
606609
if (isa<ArrayType>(EltTy))
607610
EltTy = EltTy->getArrayElementType();

llvm/test/CodeGen/AArch64/pr92062.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -mtriple=aarch64 -O0 -global-isel %s -o - 2>&1 | FileCheck %s
3+
4+
target triple = "arm64"
5+
6+
@p = external global { {}, { ptr } }
7+
8+
define void @foo() {
9+
; CHECK-LABEL: foo:
10+
; CHECK: // %bb.0: // %bb
11+
; CHECK-NEXT: adrp x8, :got:p
12+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:p]
13+
; CHECK-NEXT: ldr x8, [x8]
14+
; CHECK-NEXT: mov x9, xzr
15+
; CHECK-NEXT: str x8, [x9]
16+
; CHECK-NEXT: ret
17+
bb:
18+
%i1 = load ptr, ptr @p, align 8
19+
store ptr %i1, ptr null, align 8
20+
ret void
21+
}

0 commit comments

Comments
 (0)