[llvm] [AMDGPU][GIsel] Properly handle unsupported intrinsic translation (PR #228040)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 05:02:03 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Vikram Hegde (vikramRH)
<details>
<summary>Changes</summary>
unsupported intrinsic results are defined with G_IMPLICIT_DEF, preventing malformed translation. Basically tries to mimic SDAG path which creates poison results. prerequisite to https://github.com/llvm/llvm-project/pull/227607.
Assisted by: Opus 5
---
Full diff: https://github.com/llvm/llvm-project/pull/228040.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+22-10)
- (modified) llvm/test/CodeGen/AMDGPU/s-wakeup-barrier.ll (+4)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/228040
More information about the llvm-commits
mailing list