[llvm] [AMDGPU] Avoid crash on missing operands in wave32 MIR (PR #211739)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 23:55:33 PDT 2026
https://github.com/woruyu created https://github.com/llvm/llvm-project/pull/211739
This pr fixes https://github.com/llvm/llvm-project/issues/211581, the original codes call getNumExplicitOperands to check the minimum operand count, which assumes that the instruction's fixed operands are present. It will crash in `operands_impl().drop_front(NumOperands)`, so modify to use `getNumOperands()`.
Assisted-by: OpenAI Codex
>From 075e7a2c2c388518a7455968f015c0c7904ec3df Mon Sep 17 00:00:00 2001
From: woruyu <1214539920 at qq.com>
Date: Fri, 24 Jul 2026 14:48:05 +0800
Subject: [PATCH] [AMDGPU] Avoid crash on missing operands in wave32 MIR
---
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 2 +-
.../MIR/AMDGPU/g_intrinsic_missing_operand_crash.mir | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/MIR/AMDGPU/g_intrinsic_missing_operand_crash.mir
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 28914d598a72d..b84b658958765 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -10361,7 +10361,7 @@ void SIInstrInfo::fixImplicitOperands(MachineInstr &MI) const {
if (MI.isInlineAsm())
return;
- if (MI.getNumOperands() < MI.getNumExplicitOperands())
+ if (MI.getNumOperands() < MI.getDesc().getNumOperands())
return;
for (auto &Op : MI.implicit_operands()) {
diff --git a/llvm/test/CodeGen/MIR/AMDGPU/g_intrinsic_missing_operand_crash.mir b/llvm/test/CodeGen/MIR/AMDGPU/g_intrinsic_missing_operand_crash.mir
new file mode 100644
index 0000000000000..47665762137a9
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AMDGPU/g_intrinsic_missing_operand_crash.mir
@@ -0,0 +1,11 @@
+# RUN: not --crash llc -mtriple=amdgpu12.00 -run-pass=none -verify-machineinstrs %s -filetype=null 2>&1 | FileCheck %s
+
+---
+# CHECK: Bad machine code: Too few operands
+name: missing_operand_crash
+legalized: true
+tracksRegLiveness: true
+body: |
+ bb.0:
+ G_INTRINSIC
+...
More information about the llvm-commits
mailing list