[llvm] [UniformityAnalysis] Remove an incorrect assertion in uniformity analysis (PR #174117)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 31 14:09:17 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Shilei Tian (shiltian)
<details>
<summary>Changes</summary>
The join block could be not a header of a cycle, as shown in the newly added test case.
---
Full diff: https://github.com/llvm/llvm-project/pull/174117.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/GenericUniformityImpl.h (+1-3)
- (added) llvm/test/Analysis/UniformityAnalysis/AMDGPU/incorrect-assertion-issue-170048.ll (+56)
``````````diff
diff --git a/llvm/include/llvm/ADT/GenericUniformityImpl.h b/llvm/include/llvm/ADT/GenericUniformityImpl.h
index 7fb0dbe22f12f..56cbcd4b3c1e6 100644
--- a/llvm/include/llvm/ADT/GenericUniformityImpl.h
+++ b/llvm/include/llvm/ADT/GenericUniformityImpl.h
@@ -962,10 +962,8 @@ static const CycleT *getExtDivCycle(const CycleT *Cycle,
(void)OriginalCycle;
assert(Cycle == OriginalCycle || !Cycle->isReducible());
- if (Cycle->isReducible()) {
- assert(Cycle->getHeader() == JoinBlock);
+ if (Cycle->isReducible())
return nullptr;
- }
LLVM_DEBUG(dbgs() << "cycle made divergent by external branch\n");
return Cycle;
diff --git a/llvm/test/Analysis/UniformityAnalysis/AMDGPU/incorrect-assertion-issue-170048.ll b/llvm/test/Analysis/UniformityAnalysis/AMDGPU/incorrect-assertion-issue-170048.ll
new file mode 100644
index 0000000000000..34ab00e9e813d
--- /dev/null
+++ b/llvm/test/Analysis/UniformityAnalysis/AMDGPU/incorrect-assertion-issue-170048.ll
@@ -0,0 +1,56 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes='print<uniformity>' %s | FileCheck %s
+
+; In this test, the cycle (bb.3 <-> bb.4) is reducible, but the header is not
+; the join block bb.4 of the divergent terminator block bb.5. This should not
+; cause an assertion failure.
+
+define void @uniformity_analysis_crash(i1 %var) {
+; CHECK-LABEL: define void @uniformity_analysis_crash(
+; CHECK-SAME: i1 [[VAR:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 false, label %[[BB_1:.*]], label %[[BB_2:.*]]
+; CHECK: [[BB_1]]:
+; CHECK-NEXT: br label %[[BB_3:.*]]
+; CHECK: [[BB_3]]:
+; CHECK-NEXT: br i1 false, label %[[BB_5:.*]], label %[[BB_4:.*]]
+; CHECK: [[BB_4]]:
+; CHECK-NEXT: br label %[[BB_3]]
+; CHECK: [[BB_5]]:
+; CHECK-NEXT: br i1 [[VAR]], label %[[BB_6:.*]], label %[[BB_7:.*]]
+; CHECK: [[BB_6]]:
+; CHECK-NEXT: br label %[[BB_2]]
+; CHECK: [[BB_7]]:
+; CHECK-NEXT: br label %[[BB_8:.*]]
+; CHECK: [[BB_8]]:
+; CHECK-NEXT: br label %[[BB_3]]
+; CHECK: [[BB_2]]:
+; CHECK-NEXT: br label %[[BB_8]]
+;
+entry:
+ br i1 false, label %bb.1, label %bb.2
+
+bb.1: ; preds = %entry
+ br label %bb.3
+
+bb.3: ; preds = %bb.8, %bb.4, %bb.1
+ br i1 false, label %bb.5, label %bb.4
+
+bb.4: ; preds = %bb.3
+ br label %bb.3
+
+bb.5: ; preds = %bb.3
+ br i1 %var, label %bb.6, label %bb.7
+
+bb.6: ; preds = %bb.5
+ br label %bb.2
+
+bb.7: ; preds = %bb.5
+ br label %bb.8
+
+bb.8: ; preds = %bb.2, %bb.7
+ br label %bb.3
+
+bb.2: ; preds = %bb.6, %entry
+ br label %bb.8
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/174117
More information about the llvm-commits
mailing list