[llvm] [TargetInstrInfo] Enable instruction size verification by default (PR #221687)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 7 02:14:22 PDT 2026


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

Enable verification for instruction sizes by default. When emitting machine code, this checks that the reported instruction size is not smaller than the actual instruction size. Not under-reporting instruction sizes is critical for any target that does branch relaxation (or similar) on MIR.

The default allows over-estimating the size by default. Targets can opt-in to precise instruction sizes if they want.

Exclude two instructions on ARM, which report incorrect sizes, but fixing those sizes breaks the constant islands pass for some reason.

>From 4949891f9511b801f9dd6a87243223cdc26d4070 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 3 Sep 2026 15:48:27 +0200
Subject: [PATCH 1/2] enable inst size check

---
 llvm/include/llvm/CodeGen/TargetInstrInfo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index 2134b5e15146c..3c60e8d516a67 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -450,7 +450,7 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
   /// getInstSizeInBytes() should be verified.
   virtual InstSizeVerifyMode
   getInstSizeVerifyMode(const MachineInstr &MI) const {
-    return InstSizeVerifyMode::NoVerify;
+    return InstSizeVerifyMode::AllowOverEstimate;
   }
 
   /// Return true if the instruction is as cheap as a move instruction.

>From 1d735d360d9589b2e0b0d5be93481cea9700488c Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 3 Sep 2026 16:36:03 +0200
Subject: [PATCH 2/2] arm opt out

---
 llvm/lib/Target/ARM/ARMBaseInstrInfo.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.h b/llvm/lib/Target/ARM/ARMBaseInstrInfo.h
index 94595ab2b338b..3ad5b3d45ce55 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.h
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.h
@@ -193,6 +193,15 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {
   ///
   unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
 
+  InstSizeVerifyMode
+  getInstSizeVerifyMode(const MachineInstr &MI) const override {
+    // FIXME: These instructions report an incorrect size, but the ARM constant
+    // islands pass somehow depends on it being incorrect.
+    if (MI.getOpcode() == ARM::tTBB_JT || MI.getOpcode() == ARM::tTBH_JT)
+      return InstSizeVerifyMode::NoVerify;
+    return InstSizeVerifyMode::AllowOverEstimate;
+  }
+
   Register isLoadFromStackSlot(const MachineInstr &MI,
                                int &FrameIndex) const override;
   Register isStoreToStackSlot(const MachineInstr &MI,



More information about the llvm-commits mailing list