Skip to content

Commit 6ae36c0

Browse files
authored
[AArch64] Disable loop alignment for Windows targets (#67894)
This should fix #66912. When emitting SEH unwind info, we need to be able to calculate the exact length of functions before alignments are fixed. Until that limitation is overcome, just disable all loop alignment on Windows targets.
1 parent 3923e61 commit 6ae36c0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

llvm/lib/MC/MCWin64EH.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,9 @@ static void ARM64EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info,
14021402
// here, but we'd have to emit the pdata, the xdata header, and the
14031403
// epilogue scopes later, since they depend on whether the we need to
14041404
// split the unwind data.
1405+
//
1406+
// If this is fixed, remove code in AArch64ISelLowering.cpp that
1407+
// disables loop alignment on Windows.
14051408
RawFuncLength = GetAbsDifference(streamer, info->FuncletOrFuncEnd,
14061409
info->Begin);
14071410
}

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,12 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
10511051
// Set required alignment.
10521052
setMinFunctionAlignment(Align(4));
10531053
// Set preferred alignments.
1054-
setPrefLoopAlignment(STI.getPrefLoopAlignment());
1054+
1055+
// Don't align loops on Windows. The SEH unwind info generation needs to
1056+
// know the exact length of functions before the alignments have been
1057+
// expanded.
1058+
if (!Subtarget->isTargetWindows())
1059+
setPrefLoopAlignment(STI.getPrefLoopAlignment());
10551060
setMaxBytesForAlignment(STI.getMaxBytesForLoopAlignment());
10561061
setPrefFunctionAlignment(STI.getPrefFunctionAlignment());
10571062

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; RUN: llc < %s -mtriple=aarch64-windows | FileCheck %s --check-prefix=WINDOWS
2+
; RUN: llc < %s -mtriple=aarch64-linux | FileCheck %s --check-prefix=LINUX
3+
4+
define dso_local void @b() #0 {
5+
entry:
6+
br label %for.cond
7+
8+
for.cond:
9+
tail call void @a()
10+
br label %for.cond
11+
}
12+
13+
declare dso_local void @a(...)
14+
15+
attributes #0 = { noreturn nounwind uwtable "tune-cpu"="cortex-a53" }
16+
17+
; LINUX-LABEL: b:
18+
; LINUX: .p2align 4
19+
20+
; WINDOWS-LABEL: b:
21+
; WINDOWS-NOT: .p2align

0 commit comments

Comments
 (0)