[llvm] [CodeGen] Add OffloadBlockUniformityAnalysis for offload PGO (PR #178417)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 19:49:19 PDT 2026
================
@@ -0,0 +1,79 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -O0 -stop-after=finalize-isel -o - %s | \
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -passes='print<block-uniformity-profile>' -x mir -filetype=null 2>&1 | FileCheck %s
+
+; Test that BlockUniformityProfileProxy correctly reads block.uniformity.profile
+; metadata from IR basic blocks and classifies machine blocks.
+;
+; This metadata is attached during PGO-use phase to indicate whether a basic block
+; was executed uniformly (all lanes together) or divergently (partial wave).
+;
+; The analysis is consumed by SpillPlacement to flatten block frequencies for
+; divergent blocks, preventing PGO from causing regressions on divergent code paths.
+
+; CHECK-LABEL: BlockUniformityProfile for function: @uniform_blocks
+; CHECK-NEXT: HasProfile: true
+; CHECK: %bb.{{[0-9]+}} (%entry): uniform
+define amdgpu_kernel void @uniform_blocks(ptr addrspace(1) %out) #0 {
+entry:
+ store i32 1, ptr addrspace(1) %out, align 4
+ ret void, !block.uniformity.profile !0
+}
+
+; CHECK-LABEL: BlockUniformityProfile for function: @divergent_blocks
+; CHECK-NEXT: HasProfile: true
+; CHECK-DAG: %bb.{{[0-9]+}} (%if.then): divergent
+; CHECK-DAG: %bb.{{[0-9]+}} (%if.else): uniform
+define amdgpu_kernel void @divergent_blocks(ptr addrspace(1) %out, i32 %tid) #0 {
+entry:
+ %cmp = icmp eq i32 %tid, 0
+ br i1 %cmp, label %if.then, label %if.else
+
+if.then:
+ store i32 1, ptr addrspace(1) %out, align 4
+ ret void, !block.uniformity.profile !1
+
+if.else:
+ store i32 2, ptr addrspace(1) %out, align 4
+ ret void, !block.uniformity.profile !0
+}
+
+; CHECK-LABEL: BlockUniformityProfile for function: @missing_metadata
+; CHECK-NEXT: HasProfile: true
+; CHECK-DAG: %bb.{{[0-9]+}} (%if.then): no PGO annotation (treated divergent for spill placement)
+; CHECK-DAG: %bb.{{[0-9]+}} (%if.else): uniform
+define amdgpu_kernel void @missing_metadata(ptr addrspace(1) %out, i32 %cond) #0 {
+entry:
+ %cmp = icmp sgt i32 %cond, 0
+ br i1 %cmp, label %if.then, label %if.else
+
+if.then:
+ store i32 1, ptr addrspace(1) %out, align 4
+ ret void
+
+if.else:
+ store i32 2, ptr addrspace(1) %out, align 4
+ ret void, !block.uniformity.profile !0
----------------
yxsamliu wrote:
Done. I added a loop test that checks the loop header/body and exit block classification.
https://github.com/llvm/llvm-project/pull/178417
More information about the llvm-commits
mailing list