[llvm] 758aa4a - [CodeGen] Avoid sinking EH pad blocks (#224812)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 17:57:17 PDT 2026


Author: Trung Nguyen
Date: 2026-10-03T00:57:06Z
New Revision: 758aa4a9246f29af8576fde6f7e8ce9a0317e13b

URL: https://github.com/llvm/llvm-project/commit/758aa4a9246f29af8576fde6f7e8ce9a0317e13b
DIFF: https://github.com/llvm/llvm-project/commit/758aa4a9246f29af8576fde6f7e8ce9a0317e13b.diff

LOG: [CodeGen] Avoid sinking EH pad blocks (#224812)

EH pad blocks should not be sinkable since the control flow comes from
the unwinder instead of the predecessor.

This exclusion also matches the behavior of other sinkers.

Fixes #224802.

Added: 
    llvm/test/CodeGen/X86/postra-machine-sink-eh-pad.mir

Modified: 
    llvm/lib/CodeGen/MachineSink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index cbd2598a47210..3bfa604ccbd7b 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -2249,7 +2249,7 @@ bool PostRAMachineSinkingImpl::tryToSinkCopy(MachineBasicBlock &CurBB,
   // so that we can directly sink COPY instructions to the successor without
   // adding any new block or branch instruction.
   for (MachineBasicBlock *SI : CurBB.successors())
-    if (!SI->livein_empty() && SI->pred_size() == 1)
+    if (!SI->livein_empty() && SI->pred_size() == 1 && !SI->isEHPad())
       SinkableBBs.insert(SI);
 
   if (SinkableBBs.empty())

diff  --git a/llvm/test/CodeGen/X86/postra-machine-sink-eh-pad.mir b/llvm/test/CodeGen/X86/postra-machine-sink-eh-pad.mir
new file mode 100644
index 0000000000000..884f46b882fec
--- /dev/null
+++ b/llvm/test/CodeGen/X86/postra-machine-sink-eh-pad.mir
@@ -0,0 +1,40 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=postra-machine-sink -verify-machineinstrs -o - %s | FileCheck %s
+# RUN: llc -mtriple=x86_64-unknown-linux-gnu -passes=postra-machine-sink -o - %s | FileCheck %s
+
+# Regression test for llvm/llvm-project#224802.
+
+---
+name:            no_sink_into_landing_pad
+tracksRegLiveness: true
+body: |
+  ; CHECK-LABEL: name: no_sink_into_landing_pad
+  ; CHECK: bb.0:
+  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
+  ; CHECK-NEXT:   liveins: $rbx
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   renamable $rax = COPY killed renamable $rbx
+  ; CHECK-NEXT:   JMP_1 %bb.1
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.1:
+  ; CHECK-NEXT:   RET 0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.2 (landing-pad):
+  ; CHECK-NEXT:   liveins: $rax
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   RET 0, $rax
+  bb.0:
+    successors: %bb.1, %bb.2
+    liveins: $rbx
+
+    renamable $rax = COPY killed renamable $rbx
+    JMP_1 %bb.1
+
+  bb.1:
+    RET 0
+
+  bb.2 (landing-pad):
+    liveins: $rax
+
+    RET 0, $rax
+...


        


More information about the llvm-commits mailing list