[llvm] [GlobalISel][AMDGPU] Emit proper diagnostic when inline asm register allocation fails (PR #201380)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 08:09:12 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
Replace the silent fallback return with a DiagnosticInfoInlineAsm error and undef result values, so the failure is reported to the user instead of relying on -global-isel-abort
discussed in https://github.com/llvm/llvm-project/pull/200771
---
Full diff: https://github.com/llvm/llvm-project/pull/201380.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp (+22-7)
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/inline-asm-mismatched-size.ll (+1-1)
``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
index 6481d0e180352..3efa6ecaa9dc0 100644
--- a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
@@ -17,6 +17,7 @@
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetLowering.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Module.h"
#define DEBUG_TYPE "inline-asm-lowering"
@@ -25,6 +26,16 @@ using namespace llvm;
void InlineAsmLowering::anchor() {}
+/// Emit an inline asm error diagnostic and materialize undef values for the
+/// call results so that the rest of the function remains well-formed.
+static void emitInlineAsmError(MachineIRBuilder &MIRBuilder,
+ const CallBase &Call, const Twine &Message,
+ ArrayRef<Register> ResRegs) {
+ Call.getContext().diagnose(DiagnosticInfoInlineAsm(Call, Message));
+ for (Register Reg : ResRegs)
+ MIRBuilder.buildUndef(Reg);
+}
+
namespace {
/// GISelAsmOperandInfo - This contains information for each constraint that we
@@ -347,9 +358,12 @@ bool InlineAsmLowering::lowerInlineAsm(
// Find a register that we can use.
if (OpInfo.Regs.empty()) {
- LLVM_DEBUG(dbgs()
- << "Couldn't allocate output register for constraint\n");
- return false;
+ emitInlineAsmError(MIRBuilder, Call,
+ "could not allocate output register for "
+ "constraint '" +
+ Twine(OpInfo.ConstraintCode) + "'",
+ GetOrCreateVRegs(Call));
+ return true;
}
// Add information to the INLINEASM instruction to know that this
@@ -528,10 +542,11 @@ bool InlineAsmLowering::lowerInlineAsm(
// Copy the input into the appropriate registers.
if (OpInfo.Regs.empty()) {
- LLVM_DEBUG(
- dbgs()
- << "Couldn't allocate input register for register constraint\n");
- return false;
+ emitInlineAsmError(MIRBuilder, Call,
+ "could not allocate input reg for constraint '" +
+ Twine(OpInfo.ConstraintCode) + "'",
+ GetOrCreateVRegs(Call));
+ return true;
}
unsigned NumRegs = OpInfo.Regs.size();
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/inline-asm-mismatched-size.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/inline-asm-mismatched-size.ll
index f3bf6e548e261..bce42750502c1 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/inline-asm-mismatched-size.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/inline-asm-mismatched-size.ll
@@ -1,4 +1,4 @@
-; RUN: not llc -global-isel -global-isel-abort=2 -mtriple=amdgcn -mcpu=fiji -filetype=null %s 2>&1 | FileCheck -check-prefix=ERR %s
+; RUN: not llc -global-isel -mtriple=amdgcn -mcpu=fiji -filetype=null %s 2>&1 | FileCheck -check-prefix=ERR %s
; This asm is broken because it's using a 5 element wide physical
; register for a 4 element wide value. Make sure we don't crash, and
``````````
</details>
https://github.com/llvm/llvm-project/pull/201380
More information about the llvm-commits
mailing list