[llvm] 4590ef3 - [AMDGPU][Uniformity Analysis] Marking G_DYN_STACKALLOC AlwaysUniform in uniformity analysis (#200390)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 03:51:54 PDT 2026


Author: Abhinav Garg
Date: 2026-06-04T16:21:49+05:30
New Revision: 4590ef3017290cd2bb7eeadf14c23fe0c6d5128f

URL: https://github.com/llvm/llvm-project/commit/4590ef3017290cd2bb7eeadf14c23fe0c6d5128f
DIFF: https://github.com/llvm/llvm-project/commit/4590ef3017290cd2bb7eeadf14c23fe0c6d5128f.diff

LOG: [AMDGPU][Uniformity Analysis] Marking G_DYN_STACKALLOC AlwaysUniform in uniformity analysis (#200390)

Mark G_DYN_STACKALLOC as AlwaysUniform.
The result of G_DYN_STACKALLOC is always derived from the wave-uniform
stack pointer and wave-wide max reduce alloca size hence its always uniform.

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
    llvm/test/Analysis/UniformityAnalysis/AMDGPU/MIR/always-uniform.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index a544f1380e53d..3b72ba4bd4967 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -10989,6 +10989,11 @@ SIInstrInfo::getGenericValueUniformity(const MachineInstr &MI) const {
       AMDGPU::isGenericAtomic(Opcode)) {
     return ValueUniformity::NeverUniform;
   }
+
+  // Result is computed from uniform SP and uniform wave-wide max size.
+  if (Opcode == TargetOpcode::G_DYN_STACKALLOC)
+    return ValueUniformity::AlwaysUniform;
+
   return ValueUniformity::Default;
 }
 

diff  --git a/llvm/test/Analysis/UniformityAnalysis/AMDGPU/MIR/always-uniform.mir b/llvm/test/Analysis/UniformityAnalysis/AMDGPU/MIR/always-uniform.mir
index 09d3cfb9aa6cd..dbe9986e04a70 100644
--- a/llvm/test/Analysis/UniformityAnalysis/AMDGPU/MIR/always-uniform.mir
+++ b/llvm/test/Analysis/UniformityAnalysis/AMDGPU/MIR/always-uniform.mir
@@ -55,3 +55,25 @@ body:             |
     %1:vgpr_32 = COPY $sgpr1
     S_ENDPGM 0
 ...
+
+# G_DYN_STACKALLOC result is always uniform. The returned value is computed
+# from the wave-uniform stack pointer and the wave-wide max allocation size
+# (reduced via wave_reduce_umax when divergent), both of which are uniform.
+# Hence the result is always uniform, even when the input size is divergent.
+---
+name:            dyn_stackalloc_divergent_size
+legalized:       true
+frameInfo:
+  maxAlignment: 4
+stack:
+  - { id: 0, type: variable-sized, alignment: 4 }
+body:             |
+  bb.0:
+    liveins: $vgpr0
+    ; CHECK-LABEL: MachineUniformityInfo for function:  @dyn_stackalloc_divergent_size
+    ; CHECK: DIVERGENT: %0
+    ; CHECK-NOT: DIVERGENT: {{.*}}G_DYN_STACKALLOC
+    %0:_(s32) = COPY $vgpr0
+    %1:_(p5) = G_DYN_STACKALLOC %0(s32), 4
+    S_ENDPGM 0, implicit %1
+...


        


More information about the llvm-commits mailing list