[llvm] [AArch64] Add a fast-path for AArch64InstrInfo::getInstSizeInBytes (NFC) (PR #221894)
Cullen Rhodes via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 01:06:27 PDT 2026
https://github.com/c-rhodes updated https://github.com/llvm/llvm-project/pull/221894
>From be1403a1f2db85c9443fa8300fa8522561bea90a Mon Sep 17 00:00:00 2001
From: Cullen Rhodes <cullen.rhodes at arm.com>
Date: Tue, 28 Apr 2026 19:21:46 +0000
Subject: [PATCH 1/2] [AArch64] Add a fast-path for
AArch64InstrInfo::getInstSizeInBytes (NFC)
Assisted-by: codex
---
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index e69336ea04857..35fc9a67e1304 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -204,6 +204,10 @@ static std::optional<unsigned> getLFIInstSizeInBytes(const MachineInstr &MI) {
/// GetInstSize - Return the number of bytes of code the specified
/// instruction may be. This returns the maximum number of bytes.
unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
+ const MCInstrDesc &Desc = MI.getDesc();
+ if (!Desc.isPseudo() && !Subtarget.isLFI())
+ return 4;
+
const MachineBasicBlock &MBB = *MI.getParent();
const MachineFunction *MF = MBB.getParent();
const Function &F = MF->getFunction();
@@ -222,7 +226,6 @@ unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
// FIXME: We currently only handle pseudoinstructions that don't get expanded
// before the assembly printer.
unsigned NumBytes = 0;
- const MCInstrDesc &Desc = MI.getDesc();
// LFI rewriter expansions that supersede normal sizing.
const auto &STI = MF->getSubtarget<AArch64Subtarget>();
>From ad2dae7afb1fc969eb93530f38398d7a3a3b926c Mon Sep 17 00:00:00 2001
From: Cullen Rhodes <cullen.rhodes at arm.com>
Date: Tue, 8 Sep 2026 08:04:59 +0000
Subject: [PATCH 2/2] address comments
---
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 35fc9a67e1304..27c1be3f19096 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -205,8 +205,10 @@ static std::optional<unsigned> getLFIInstSizeInBytes(const MachineInstr &MI) {
/// instruction may be. This returns the maximum number of bytes.
unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
const MCInstrDesc &Desc = MI.getDesc();
- if (!Desc.isPseudo() && !Subtarget.isLFI())
+ if (!Desc.isPseudo() && !Subtarget.isLFI()) {
+ assert(Desc.getSize() == 4 && "Unexpected instruction size");
return 4;
+ }
const MachineBasicBlock &MBB = *MI.getParent();
const MachineFunction *MF = MBB.getParent();
More information about the llvm-commits
mailing list