Skip to content

Commit 5422e2c

Browse files
committed
[AArch64][GlobalISel] On Darwin don't fold globals into the offset of prefetches.
ld64 doesn't currently support the PAGEOFF relocations on anything but load/stores so we need to bail-out here to fix the build failures on greendragon. rdar://145495288
1 parent 45759fe commit 5422e2c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7617,7 +7617,12 @@ AArch64InstructionSelector::selectAddrModeIndexed(MachineOperand &Root,
76177617

76187618
CodeModel::Model CM = MF.getTarget().getCodeModel();
76197619
// Check if we can fold in the ADD of small code model ADRP + ADD address.
7620-
if (CM == CodeModel::Small) {
7620+
// HACK: ld64 on Darwin doesn't support relocations on PRFM, so we can't fold
7621+
// globals into the offset.
7622+
MachineInstr *RootParent = Root.getParent();
7623+
if (CM == CodeModel::Small &&
7624+
!(RootParent->getOpcode() == AArch64::G_AARCH64_PREFETCH &&
7625+
STI.isTargetDarwin())) {
76217626
auto OpFns = tryFoldAddLowIntoImm(*RootDef, Size, MRI);
76227627
if (OpFns)
76237628
return OpFns;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -global-isel -o - %s | FileCheck %s
3+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
4+
target triple = "arm64-apple-macosx14.0.0"
5+
6+
%struct.S = type { ptr }
7+
8+
@str = global %struct.S zeroinitializer, align 8
9+
10+
; Checks that on Darwin we don't fold the global into the prfm instruction
11+
; since ld64 doesn't support it.
12+
13+
define void @test() #0 {
14+
; CHECK-LABEL: test:
15+
; CHECK: ; %bb.0: ; %entry
16+
; CHECK-NEXT: Lloh0:
17+
; CHECK-NEXT: adrp x8, _str@PAGE
18+
; CHECK-NEXT: Lloh1:
19+
; CHECK-NEXT: add x8, x8, _str@PAGEOFF
20+
; CHECK-NEXT: prfm pldl1strm, [x8]
21+
; CHECK-NEXT: ret
22+
; CHECK-NEXT: .loh AdrpAdd Lloh0, Lloh1
23+
entry:
24+
call void @llvm.prefetch.p0(ptr @str, i32 0, i32 0, i32 1)
25+
ret void
26+
}
27+
28+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
29+
declare void @llvm.prefetch.p0(ptr nocapture readonly, i32 immarg, i32 immarg, i32 immarg) #1
30+

0 commit comments

Comments
 (0)