Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AArch64] Disable loop alignment for Windows targets #67894

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

mstorsjo
Copy link
Member

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.

This should fix llvm#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.
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 30, 2023

@llvm/pr-subscribers-mc
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-backend-aarch64

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/67894.diff

3 Files Affected:

  • (modified) llvm/lib/MC/MCWin64EH.cpp (+3)
  • (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+6-1)
  • (added) llvm/test/CodeGen/AArch64/sched-loop-align.ll (+21)
diff --git a/llvm/lib/MC/MCWin64EH.cpp b/llvm/lib/MC/MCWin64EH.cpp
index a2d61da722af870..bb3492bec8aad8a 100644
--- a/llvm/lib/MC/MCWin64EH.cpp
+++ b/llvm/lib/MC/MCWin64EH.cpp
@@ -1402,6 +1402,9 @@ static void ARM64EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info,
     // here, but we'd have to emit the pdata, the xdata header, and the
     // epilogue scopes later, since they depend on whether the we need to
     // split the unwind data.
+    //
+    // If this is fixed, remove code in AArch64ISelLowering.cpp that
+    // disables loop alignment on Windows.
     RawFuncLength = GetAbsDifference(streamer, info->FuncletOrFuncEnd,
                                      info->Begin);
   }
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 932b36587f0694e..46064bc7e46783f 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1051,7 +1051,12 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
   // Set required alignment.
   setMinFunctionAlignment(Align(4));
   // Set preferred alignments.
-  setPrefLoopAlignment(STI.getPrefLoopAlignment());
+
+  // Don't align loops on Windows. The SEH unwind info generation needs to
+  // know the exact length of functions before the alignments have been
+  // expanded.
+  if (!Subtarget->isTargetWindows())
+    setPrefLoopAlignment(STI.getPrefLoopAlignment());
   setMaxBytesForAlignment(STI.getMaxBytesForLoopAlignment());
   setPrefFunctionAlignment(STI.getPrefFunctionAlignment());
 
diff --git a/llvm/test/CodeGen/AArch64/sched-loop-align.ll b/llvm/test/CodeGen/AArch64/sched-loop-align.ll
new file mode 100644
index 000000000000000..5b8e42c2790a439
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sched-loop-align.ll
@@ -0,0 +1,21 @@
+; RUN: llc < %s -mtriple=aarch64-windows | FileCheck %s --check-prefix=WINDOWS
+; RUN: llc < %s -mtriple=aarch64-linux | FileCheck %s --check-prefix=LINUX
+
+define dso_local void @b() #0 {
+entry:
+  br label %for.cond
+
+for.cond:
+  tail call void @a()
+  br label %for.cond
+}
+
+declare dso_local void @a(...)
+
+attributes #0 = { noreturn nounwind uwtable "tune-cpu"="cortex-a53" }
+
+; LINUX-LABEL: b:
+; LINUX: .p2align 4
+
+; WINDOWS-LABEL: b:
+; WINDOWS-NOT: .p2align

@mstorsjo mstorsjo merged commit 6ae36c0 into llvm:main Oct 2, 2023
6 checks passed
@mstorsjo mstorsjo deleted the aarch64-no-loop-align branch October 2, 2023 20:55
tru pushed a commit that referenced this pull request Oct 10, 2023
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fatal error: error in backend: Failed to evaluate function length in SEH unwind info
3 participants