[llvm-branch-commits] [llvm] AMDGPU: Implement getInstSizeVerifyMode (PR #191461)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Apr 17 03:53:40 PDT 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/191461
>From 5c3afd0eb11088056af13a6719cf4d70c9b26115 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 10 Apr 2026 15:23:10 +0200
Subject: [PATCH] AMDGPU: Implement getInstSizeVerifyMode
Replace the custom instruction size check.
---
llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp | 22 --------------------
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 7 +++++++
llvm/lib/Target/AMDGPU/SIInstrInfo.h | 3 +++
3 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
index 56592bde3b1c7..592d1ad6d9195 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
@@ -456,28 +456,6 @@ void AMDGPUAsmPrinter::emitInstruction(const MachineInstr *MI) {
MCInstLowering.lower(MI, TmpInst);
EmitToStreamer(*OutStreamer, TmpInst);
-#ifdef EXPENSIVE_CHECKS
- // Check getInstSizeInBytes on explicitly specified CPUs (it cannot
- // work correctly for the generic CPU).
- //
- // The isPseudo check really shouldn't be here, but unfortunately there are
- // some negative lit tests that depend on being able to continue through
- // here even when pseudo instructions haven't been lowered.
- //
- // We also overestimate branch sizes with the offset bug.
- if (!MI->isPseudo() && STI.isCPUStringValid(STI.getCPU()) &&
- (!STI.hasOffset3fBug() || !MI->isBranch())) {
- SmallVector<MCFixup, 4> Fixups;
- SmallVector<char, 16> CodeBytes;
-
- std::unique_ptr<MCCodeEmitter> InstEmitter(createAMDGPUMCCodeEmitter(
- *STI.getInstrInfo(), OutContext));
- InstEmitter->encodeInstruction(TmpInst, CodeBytes, Fixups, STI);
-
- assert(CodeBytes.size() == STI.getInstrInfo()->getInstSizeInBytes(*MI));
- }
-#endif
-
if (DumpCodeInstEmitter) {
// Disassemble instruction/operands to text
DisasmLines.resize(DisasmLines.size() + 1);
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index fa5492955a1d7..ead72db7a6a2e 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -9899,6 +9899,13 @@ unsigned SIInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
}
}
+TargetInstrInfo::InstSizeVerifyMode
+SIInstrInfo::getInstSizeVerifyMode(const MachineInstr &MI) const {
+ if (MI.isBranch() && ST.hasOffset3fBug())
+ return InstSizeVerifyMode::NoVerify;
+ return InstSizeVerifyMode::ExactSize;
+}
+
bool SIInstrInfo::mayAccessFlatAddressSpace(const MachineInstr &MI) const {
if (!isFLAT(MI))
return false;
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.h b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
index c775cb5c8876e..757cdacc49f7b 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.h
@@ -1581,6 +1581,9 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
+ InstSizeVerifyMode
+ getInstSizeVerifyMode(const MachineInstr &MI) const override;
+
bool mayAccessFlatAddressSpace(const MachineInstr &MI) const;
std::pair<unsigned, unsigned>
More information about the llvm-branch-commits
mailing list