[llvm] [AMDGPU] InstCombine: fold invalid calls to amdgcn intrinsics into poison values (PR #191904)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 18:48:29 PDT 2026
================
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes='instcombine' -mtriple=amdgcn-amd-amdhsa < %s | FileCheck %s
+
+; When amdgpu-no-dispatch-id is set, calling the intrinsic is UB and the
+; call should be folded to poison.
+define i64 @no_dispatch_id() #0 {
+; CHECK-LABEL: define i64 @no_dispatch_id(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: ret i64 poison
+;
+entry:
+ %tmp = call i64 @llvm.amdgcn.dispatch.id()
+ ret i64 %tmp
+}
+
+; Without the attribute the call is kept.
+define i64 @dispatch_id_no_attr() {
+; CHECK-LABEL: define i64 @dispatch_id_no_attr() {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[TMP:%.*]] = call i64 @llvm.amdgcn.dispatch.id()
+; CHECK-NEXT: ret i64 [[TMP]]
+;
+entry:
+ %tmp = call i64 @llvm.amdgcn.dispatch.id()
+ ret i64 %tmp
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare i64 @llvm.amdgcn.dispatch.id() #1
----------------
shiltian wrote:
The intrinsic declaration is no longer needed. It can go, as well as attribute 1.
https://github.com/llvm/llvm-project/pull/191904
More information about the llvm-commits
mailing list