Skip to content

AMDGPU: Add noundef to mbcnt intrinsic returns #136304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Apr 18, 2025

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

arsenm added 2 commits April 18, 2025 15:30
I started to add the range, but it probably can't be done on
the declaration due to the second added operand.
Copy link
Contributor Author

arsenm commented Apr 18, 2025

@arsenm arsenm requested review from AlexVlx, jayfoad and shiltian April 18, 2025 13:31
@arsenm arsenm marked this pull request as ready for review April 18, 2025 13:31
@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/136304.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/IntrinsicsAMDGPU.td (+9-9)
  • (modified) llvm/test/Assembler/amdgcn-intrinsic-attributes.ll (+15-2)
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) }

Copy link
Contributor Author

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the output gonna be if the input is undef?

@arsenm
Copy link
Contributor Author

arsenm commented Apr 24, 2025

What is the output gonna be if the input is undef?

For mbcnt lo, An unspecified value between 0 and 32. There's an embedded freeze, the output value is more constrained than the input. For mbcnt_hi I'm less clear on how to interpret src1

Base automatically changed from users/arsenm/amdgpu/add-range-declaration-wavefrontsize-intrinsic to main April 25, 2025 08:19
@arsenm
Copy link
Contributor Author

arsenm commented Apr 30, 2025

I think the add just makes this wrong

@arsenm arsenm closed this Apr 30, 2025
@arsenm arsenm deleted the users/arsenm/amdgpu/add-noundef-mbcnt-intrinsic-return branch April 30, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants