[llvm] a172eb9 - [GlobalISel][AMDGPU] Emit proper diagnostic when inline asm register allocation fails (#201380)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 03:01:34 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-06-09T12:01:28+02:00
New Revision: a172eb9fcdebc93ad123b1f9d8b3ba953b904e7d
URL: https://github.com/llvm/llvm-project/commit/a172eb9fcdebc93ad123b1f9d8b3ba953b904e7d
DIFF: https://github.com/llvm/llvm-project/commit/a172eb9fcdebc93ad123b1f9d8b3ba953b904e7d.diff
LOG: [GlobalISel][AMDGPU] Emit proper diagnostic when inline asm register allocation fails (#201380)
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
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/inline-asm-mismatched-size.ll
Removed:
################################################################################
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
More information about the llvm-commits
mailing list