[llvm] [AMDGPU][GIsel] Properly handle unsupported intrinsic translation (PR #228040)
Vikram Hegde via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 23:20:05 PDT 2026
https://github.com/vikramRH updated https://github.com/llvm/llvm-project/pull/228040
>From 20e7abdad3293fb4052b81d091d7f4f477ee4be3 Mon Sep 17 00:00:00 2001
From: vikhegde <vikram.hegde at amd.com>
Date: Thu, 1 Oct 2026 16:27:53 +0530
Subject: [PATCH 1/2] [AMDGPU][GIsel] Properly handle unsupported intrinsics
translation
---
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 32 ++++++++++++++------
llvm/test/CodeGen/AMDGPU/s-wakeup-barrier.ll | 4 +++
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 9f043a6f57872..8de42022f84be 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -337,6 +337,11 @@ class IRTranslatorImpl {
const CallBase &CB, Intrinsic::ID ID, MachineIRBuilder &MIRBuilder,
ArrayRef<TargetLowering::IntrinsicInfo> TgtMemIntrinsicInfos = {});
+ /// Report an intrinsic the subtarget does not support and define its results
+ /// with G_IMPLICIT_DEF. Prevents creating a malformed MIR.
+ bool handleUnsupportedIntrinsic(const CallBase &CB, Intrinsic::ID ID,
+ MachineIRBuilder &MIRBuilder);
+
/// When an invoke or a cleanupret unwinds to the next EH pad, there are
/// many places it could ultimately go. In the IR, we have a single unwind
/// destination, but in the machine CFG, we enumerate all the possible blocks.
@@ -3664,11 +3669,8 @@ bool IRTranslatorImpl::translateCall(const User &U,
assert(ID != Intrinsic::not_intrinsic && "unknown intrinsic");
- if (!MF->getSubtarget().isIntrinsicSupported(ID)) {
- const Function &Fn = MF->getFunction();
- Fn.getContext().diagnose(
- DiagnosticInfoUnsupportedTargetIntrinsic(Fn, ID, CI.getDebugLoc()));
- }
+ if (!MF->getSubtarget().isIntrinsicSupported(ID))
+ return handleUnsupportedIntrinsic(CI, ID, MIRBuilder);
if (translateKnownIntrinsic(CI, ID, MIRBuilder))
return true;
@@ -3679,15 +3681,25 @@ bool IRTranslatorImpl::translateCall(const User &U,
return translateIntrinsic(CI, ID, MIRBuilder, Infos);
}
+bool IRTranslatorImpl::handleUnsupportedIntrinsic(
+ const CallBase &CB, Intrinsic::ID ID, MachineIRBuilder &MIRBuilder) {
+ const Function &F = MF->getFunction();
+ F.getContext().diagnose(
+ DiagnosticInfoUnsupportedTargetIntrinsic(F, ID, CB.getDebugLoc()));
+
+ if (!CB.getType()->isVoidTy())
+ for (Register Reg : getOrCreateVRegs(CB))
+ MIRBuilder.buildUndef(Reg);
+
+ return true;
+}
+
/// Translate a call or callbr to an intrinsic.
bool IRTranslatorImpl::translateIntrinsic(
const CallBase &CB, Intrinsic::ID ID, MachineIRBuilder &MIRBuilder,
ArrayRef<TargetLowering::IntrinsicInfo> TgtMemIntrinsicInfos) {
- if (!MF->getSubtarget().isIntrinsicSupported(ID)) {
- const Function &F = MF->getFunction();
- F.getContext().diagnose(
- DiagnosticInfoUnsupportedTargetIntrinsic(F, ID, CB.getDebugLoc()));
- }
+ if (!MF->getSubtarget().isIntrinsicSupported(ID))
+ return handleUnsupportedIntrinsic(CB, ID, MIRBuilder);
ArrayRef<Register> ResultRegs;
if (!CB.getType()->isVoidTy())
diff --git a/llvm/test/CodeGen/AMDGPU/s-wakeup-barrier.ll b/llvm/test/CodeGen/AMDGPU/s-wakeup-barrier.ll
index 192c8b4d95039..bf108456b8bab 100644
--- a/llvm/test/CodeGen/AMDGPU/s-wakeup-barrier.ll
+++ b/llvm/test/CodeGen/AMDGPU/s-wakeup-barrier.ll
@@ -5,6 +5,10 @@
; RUN: not llc -global-isel=0 -mtriple=amdgpu12.00 -filetype=null < %s 2>&1 | FileCheck -check-prefix=ERR %s
; RUN: not llc -global-isel=1 -mtriple=amdgpu12.00 -filetype=null < %s 2>&1 | FileCheck -check-prefix=ERR %s
+; Check that we report the error rather than crashing on pre-gfx12.
+; RUN: not llc -global-isel=0 -mtriple=amdgpu9.42 -filetype=null < %s 2>&1 | FileCheck -check-prefix=ERR %s
+; RUN: not llc -global-isel=1 -mtriple=amdgpu9.42 -filetype=null < %s 2>&1 | FileCheck -check-prefix=ERR %s
+
; ERR: error: <unknown>:0:0: in function @kernel1 void (ptr addrspace(1), ptr addrspace(15)): llvm.amdgcn.s.wakeup.barrier requires target feature 's-wakeup-barrier-inst'
@bar = internal addrspace(15) global target("amdgcn.named.barrier", 0) poison
>From 2571ecb11f45fb14254c8a47d5cdffb61c6e2727 Mon Sep 17 00:00:00 2001
From: vikhegde <vikram.hegde at amd.com>
Date: Mon, 5 Oct 2026 11:49:13 +0530
Subject: [PATCH 2/2] braces
---
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 8de42022f84be..0bedf1a21c8e9 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -3687,9 +3687,10 @@ bool IRTranslatorImpl::handleUnsupportedIntrinsic(
F.getContext().diagnose(
DiagnosticInfoUnsupportedTargetIntrinsic(F, ID, CB.getDebugLoc()));
- if (!CB.getType()->isVoidTy())
+ if (!CB.getType()->isVoidTy()) {
for (Register Reg : getOrCreateVRegs(CB))
MIRBuilder.buildUndef(Reg);
+ }
return true;
}
More information about the llvm-commits
mailing list