Skip to content

AMDGPU: Add some leaf intrinsics to isAlwaysUniform #101925

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

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Aug 5, 2024

These would always be uniform anyway, but it shouldn't hurt to
mark them as always uniform. This will help use TTI::isAlwaysUniform
in place of proper uniformity analysis in trivial situations.

Copy link
Contributor Author

arsenm commented Aug 5, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @arsenm and the rest of your teammates on Graphite Graphite

@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2024

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

These would always be uniform anyway, but it shouldn't hurt to
mark them as always uniform. This will help use TTI::isAlwaysUniform
in place of proper uniformity analysis in trivial situations.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td (+4)
  • (modified) llvm/test/Analysis/UniformityAnalysis/AMDGPU/always_uniform.ll (+33)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td b/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
index a323f63767737..98c93b1c6801f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
@@ -378,3 +378,7 @@ def : AlwaysUniform<int_amdgcn_icmp>;
 def : AlwaysUniform<int_amdgcn_fcmp>;
 def : AlwaysUniform<int_amdgcn_ballot>;
 def : AlwaysUniform<int_amdgcn_if_break>;
+def : AlwaysUniform<int_amdgcn_s_getpc>;
+def : AlwaysUniform<int_amdgcn_s_getreg>;
+def : AlwaysUniform<int_amdgcn_s_memrealtime>;
+def : AlwaysUniform<int_amdgcn_s_memtime>;
diff --git a/llvm/test/Analysis/UniformityAnalysis/AMDGPU/always_uniform.ll b/llvm/test/Analysis/UniformityAnalysis/AMDGPU/always_uniform.ll
index d7d8d29fbfd42..285bd04a93bbc 100644
--- a/llvm/test/Analysis/UniformityAnalysis/AMDGPU/always_uniform.ll
+++ b/llvm/test/Analysis/UniformityAnalysis/AMDGPU/always_uniform.ll
@@ -79,6 +79,39 @@ define void @no_divergent_args_if_inreg(i32 inreg %i32, i1 inreg %i1) {
  ret void
 }
 
+; CHECK-LABEL: for function 's_getpc':
+; CHECK: ALL VALUES UNIFORM
+define void @s_getpc(ptr addrspace(1) inreg %out) {
+  %result = call i64 @llvm.amdgcn.s.getpc()
+  store i64 %result, ptr addrspace(1) %out, align 8
+  ret void
+}
+
+; CHECK-LABEL: for function 's_getreg':
+; CHECK: ALL VALUES UNIFORM
+define void @s_getreg(ptr addrspace(1) inreg %out) {
+  %result = call i32 @llvm.amdgcn.s.getreg(i32 123)
+  store i32 %result, ptr addrspace(1) %out, align 4
+  ret void
+}
+
+; CHECK-LABEL: for function 's_memtime':
+; CHECK: ALL VALUES UNIFORM
+define void @s_memtime(ptr addrspace(1) inreg %out) {
+  %result = call i64 @llvm.amdgcn.s.memtime()
+  store i64 %result, ptr addrspace(1) %out, align 8
+  ret void
+}
+
+; CHECK-LABEL: for function 's_memrealtime':
+; CHECK: ALL VALUES UNIFORM
+define void @s_memrealtime(ptr addrspace(1) inreg %out) {
+  %result = call i64 @llvm.amdgcn.s.memrealtime()
+  store i64 %result, ptr addrspace(1) %out, align 8
+  ret void
+}
+
+
 declare i32 @llvm.amdgcn.workitem.id.x() #0
 declare i32 @llvm.amdgcn.readfirstlane(i32) #0
 declare i64 @llvm.amdgcn.icmp.i32(i32, i32, i32) #1

@arsenm arsenm marked this pull request as ready for review August 5, 2024 06:36
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Aug 5, 2024
@ssahasra
Copy link
Collaborator

ssahasra commented Aug 5, 2024

These would always be uniform anyway, but it shouldn't hurt to mark them as always uniform. This will help use TTI::isAlwaysUniform in place of proper uniformity analysis in trivial situations.

I don't think that so much justification is required. Things that are known to be uniform should be marked as such, liberally.

Copy link
Collaborator

@rampitec rampitec left a comment

Choose a reason for hiding this comment

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

I think uniformity analysis will always tell it is uniform because it has no divergent arguments. Do you think searching this table is faster?

@arsenm
Copy link
Contributor Author

arsenm commented Aug 5, 2024

I think uniformity analysis will always tell it is uniform because it has no divergent arguments. Do you think searching this table is faster?

The table is only used once to initialize special overriding map entries. The point of this is we can use it for trivial checks without using full uniformity analysis

These would always be uniform anyway, but it shouldn't hurt to
mark them as always uniform. This will help use TTI::isAlwaysUniform
in place of proper uniformity analysis in trivial situations.
@arsenm arsenm force-pushed the users/arsenm/amdgpu-leaf-intrinsics-isalwaysuniform branch from e32536e to f21373b Compare August 6, 2024 08:25
@arsenm arsenm merged commit 3e3ea54 into main Aug 6, 2024
7 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu-leaf-intrinsics-isalwaysuniform branch August 6, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU llvm:analysis Includes value tracking, cost tables and constant folding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants