Skip to content

Commit 1090b91

Browse files
mstorsjotru
authored andcommitted
[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. (cherry picked from commit 6ae36c0)
1 parent 69c8c96 commit 1090b91

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

llvm/lib/MC/MCWin64EH.cpp

+3
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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,12 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
10331033
// Set required alignment.
10341034
setMinFunctionAlignment(Align(4));
10351035
// Set preferred alignments.
1036-
setPrefLoopAlignment(STI.getPrefLoopAlignment());
1036+
1037+
// Don't align loops on Windows. The SEH unwind info generation needs to
1038+
// know the exact length of functions before the alignments have been
1039+
// expanded.
1040+
if (!Subtarget->isTargetWindows())
1041+
setPrefLoopAlignment(STI.getPrefLoopAlignment());
10371042
setMaxBytesForAlignment(STI.getMaxBytesForLoopAlignment());
10381043
setPrefFunctionAlignment(STI.getPrefFunctionAlignment());
10391044

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)