[llvm-branch-commits] [llvm] AMDGPU: Add noundef to mbcnt intrinsic returns (PR #136304)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 18 06:31:01 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/136304

I started to add the range, but it probably can't be done on
the declaration due to the second added operand.

>From 050b743d821d333655c1290caf37d89beb14c492 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 18 Apr 2025 15:06:41 +0200
Subject: [PATCH] AMDGPU: Add noundef to mbcnt intrinsic returns

I started to add the range, but it probably can't be done on
the declaration due to the second added operand.
---
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td       | 18 +++++++++---------
 .../Assembler/amdgcn-intrinsic-attributes.ll   | 17 +++++++++++++++--
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index a57eb4a6dba49..9803693253853 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2215,15 +2215,15 @@ def int_amdgcn_live_mask : DefaultAttrsIntrinsic <[llvm_i1_ty],
   [], [NoUndef<RetIndex>, IntrReadMem, IntrInaccessibleMemOnly]
 >;
 
-def int_amdgcn_mbcnt_lo :
-  ClangBuiltin<"__builtin_amdgcn_mbcnt_lo">,
-  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
-   [IntrNoMem]>;
-
-def int_amdgcn_mbcnt_hi :
-  ClangBuiltin<"__builtin_amdgcn_mbcnt_hi">,
-  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
-            [IntrNoMem]>;
+def int_amdgcn_mbcnt_lo
+    : ClangBuiltin<"__builtin_amdgcn_mbcnt_lo">,
+      DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+                            [NoUndef<RetIndex>, IntrNoMem]>;
+
+def int_amdgcn_mbcnt_hi
+    : ClangBuiltin<"__builtin_amdgcn_mbcnt_hi">,
+      DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+                            [NoUndef<RetIndex>, IntrNoMem]>;
 
 // llvm.amdgcn.ds.swizzle src offset
 def int_amdgcn_ds_swizzle :
diff --git a/llvm/test/Assembler/amdgcn-intrinsic-attributes.ll b/llvm/test/Assembler/amdgcn-intrinsic-attributes.ll
index 744c94ac85410..b965bef634f9d 100644
--- a/llvm/test/Assembler/amdgcn-intrinsic-attributes.ll
+++ b/llvm/test/Assembler/amdgcn-intrinsic-attributes.ll
@@ -18,12 +18,25 @@ define i32 @ds_consume(ptr addrspace(3) %ptr) {
   ret i32 %ret
 }
 
+; CHECK: declare noundef i32 @llvm.amdgcn.mbcnt.hi(i32, i32) #1
+define i32 @mbcnt_hi(i32 %a, i32 %b) {
+  %ret = call i32 @llvm.amdgcn.mbcnt.hi(i32 %a, i32 %b)
+  ret i32 %ret
+}
+
+; CHECK: declare noundef i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #1
+define i32 @mbcnt_lo(i32 %a, i32 %b) {
+  %ret = call i32 @llvm.amdgcn.mbcnt.lo(i32 %a, i32 %b)
+  ret i32 %ret
+}
+
 ; Test assumed range
-; CHECK: declare noundef range(i32 32, 65) i32 @llvm.amdgcn.wavefrontsize() #1
+; CHECK: declare noundef range(i32 32, 65) i32 @llvm.amdgcn.wavefrontsize() #2
 define i32 @wavefrontsize() {
   %ret = call i32 @llvm.amdgcn.wavefrontsize()
   ret i32 %ret
 }
 
 ; CHECK: attributes #0 = { convergent nocallback nofree nounwind willreturn memory(argmem: readwrite) }
-; CHECK: attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+; CHECK: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
+; CHECK: attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }



More information about the llvm-branch-commits mailing list