[llvm] [ARM] Fix Int_eh_sjlj_longjmp instruction size (PR #223639)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 02:44:09 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/223639

These pseudos expand to one more instruction on non-darwin/windows platforms.

See: https://github.com/llvm/llvm-project/blob/88107b203b9e02a2d6ce87bf8ba0d98cb6ff53ec/llvm/lib/Target/ARM/ARMAsmPrinter.cpp#L2738-L2764

>From 90f2c6388b2e7cc48f7a05d706519a9c4e2aa744 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 15 Sep 2026 11:41:29 +0200
Subject: [PATCH] [ARM] Fix Int_eh_sjlj_longjmp instruction size

These pseudos expand to one more instruction on non-darwin/windows
platforms.
---
 llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp | 4 ++++
 llvm/lib/Target/ARM/ARMInstrInfo.td      | 4 ++--
 llvm/lib/Target/ARM/ARMInstrThumb.td     | 4 ++--
 llvm/test/CodeGen/ARM/setjmp_longjmp.ll  | 6 ++++++
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
index 51f3cdea9ad5c7..dad034ede1dd43 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -646,6 +646,10 @@ unsigned ARMBaseInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
       Size = alignTo(Size, 4);
     return Size;
   }
+  case ARM::Int_eh_sjlj_longjmp:
+    return Subtarget.isTargetDarwin() || Subtarget.isTargetWindows() ? 16 : 20;
+  case ARM::tInt_eh_sjlj_longjmp:
+    return Subtarget.isTargetDarwin() || Subtarget.isTargetWindows() ? 10 : 12;
   }
 }
 
diff --git a/llvm/lib/Target/ARM/ARMInstrInfo.td b/llvm/lib/Target/ARM/ARMInstrInfo.td
index f7e9a6327f698b..40eca3dc1e48ee 100644
--- a/llvm/lib/Target/ARM/ARMInstrInfo.td
+++ b/llvm/lib/Target/ARM/ARMInstrInfo.td
@@ -6132,9 +6132,9 @@ let Defs =
                                 Requires<[IsARM, NoVFP]>;
 }
 
-// This gets lowered to an instruction sequence of 16 bytes
+// This gets lowered to an instruction sequence of 16 or 20 bytes
 // FIXME: Non-IOS version(s)
-let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, Size = 16,
+let isBarrier = 1, hasSideEffects = 1, isTerminator = 1,
     Defs = [ R7, LR, SP ] in {
 def Int_eh_sjlj_longjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$scratch),
                              NoItinerary,
diff --git a/llvm/lib/Target/ARM/ARMInstrThumb.td b/llvm/lib/Target/ARM/ARMInstrThumb.td
index de9d41c116a373..ed939626ab2576 100644
--- a/llvm/lib/Target/ARM/ARMInstrThumb.td
+++ b/llvm/lib/Target/ARM/ARMInstrThumb.td
@@ -1549,10 +1549,10 @@ def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
                                   AddrModeNone, 0, NoItinerary, "","",
                           [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
 
-// This gets lowered to an instruction sequence of 10 bytes
+// This gets lowered to an instruction sequence of 10 or 12 bytes
 // FIXME: Non-IOS version(s)
 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
-    Size = 10, Defs = [ R7, LR, SP ] in
+    Defs = [ R7, LR, SP ] in
 def tInt_eh_sjlj_longjmp : XI<(outs), (ins tGPR:$src, tGPR:$scratch),
                               AddrModeNone, 0, IndexModeNone,
                               Pseudo, NoItinerary, "", "",
diff --git a/llvm/test/CodeGen/ARM/setjmp_longjmp.ll b/llvm/test/CodeGen/ARM/setjmp_longjmp.ll
index ddc1de3e31d386..4a6f4b5beac84b 100644
--- a/llvm/test/CodeGen/ARM/setjmp_longjmp.ll
+++ b/llvm/test/CodeGen/ARM/setjmp_longjmp.ll
@@ -1,6 +1,12 @@
 ; RUN: llc -simplifycfg-require-and-preserve-domtree=1 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=armv7-linux -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - | FileCheck %s -check-prefix CHECK-LINUX
 ; RUN: llc -mtriple=thumbv7-win32 -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - | FileCheck %s -check-prefix CHECK-WIN32
+
+; Run instruction size verification via -filetype=obj.
+; RUN: llc -mtriple=armv7-linux -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - -filetype=obj | llvm-objdump -d -
+; RUN: llc -mtriple=thumbv7-linux -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - -filetype=obj | llvm-objdump -d -
+; RUN: llc -mtriple=thumbv7-win32 -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - -filetype=obj | llvm-objdump -d -
+
 target triple = "armv7-apple-ios"
 
 declare i32 @llvm.eh.sjlj.setjmp(ptr)



More information about the llvm-commits mailing list