[llvm] 09e12d1 - [LLVM][Uniformity] Fix error causing assert on some irreducible control flow

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 21:18:40 PDT 2023


Author: Alex MacLean
Date: 2023-08-18T09:47:49+05:30
New Revision: 09e12d13a04f8861b881f79a96ef8a60c9840ee1

URL: https://github.com/llvm/llvm-project/commit/09e12d13a04f8861b881f79a96ef8a60c9840ee1
DIFF: https://github.com/llvm/llvm-project/commit/09e12d13a04f8861b881f79a96ef8a60c9840ee1.diff

LOG: [LLVM][Uniformity] Fix error causing assert on some irreducible control flow

As the test case demonstrates, it is possible for a block to be identified as a
join point while not being the header of a reducible cycle. To address this,
when searching for the outermost cycle made divergent by branch outside it, we
first check for an irreducible outermost cycle before checking if the parent is
reducible.

Reviewed By: sameerds

Differential Revision: https://reviews.llvm.org/D158014

Added: 
    llvm/test/Analysis/UniformityAnalysis/NVPTX/non-header-join.ll

Modified: 
    llvm/include/llvm/ADT/GenericUniformityImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/GenericUniformityImpl.h b/llvm/include/llvm/ADT/GenericUniformityImpl.h
index 2d5f6ee037ef7b..954af5e44b894c 100644
--- a/llvm/include/llvm/ADT/GenericUniformityImpl.h
+++ b/llvm/include/llvm/ADT/GenericUniformityImpl.h
@@ -946,11 +946,6 @@ static const CycleT *getExtDivCycle(const CycleT *Cycle,
   if (Cycle->contains(DivTermBlock))
     return nullptr;
 
-  if (Cycle->isReducible()) {
-    assert(Cycle->getHeader() == JoinBlock);
-    return nullptr;
-  }
-
   const auto *Parent = Cycle->getParentCycle();
   while (Parent && !Parent->contains(DivTermBlock)) {
     // If the join is inside a child, then the parent must be
@@ -961,6 +956,11 @@ static const CycleT *getExtDivCycle(const CycleT *Cycle,
     Parent = Cycle->getParentCycle();
   }
 
+  if (Cycle->isReducible()) {
+    assert(Cycle->getHeader() == JoinBlock);
+    return nullptr;
+  }
+
   LLVM_DEBUG(dbgs() << "cycle made divergent by external branch\n");
   return Cycle;
 }

diff  --git a/llvm/test/Analysis/UniformityAnalysis/NVPTX/non-header-join.ll b/llvm/test/Analysis/UniformityAnalysis/NVPTX/non-header-join.ll
new file mode 100644
index 00000000000000..5fbf435f2f16fa
--- /dev/null
+++ b/llvm/test/Analysis/UniformityAnalysis/NVPTX/non-header-join.ll
@@ -0,0 +1,24 @@
+; RUN: opt %s -passes='print<uniformity>' -disable-output 2>&1 | FileCheck %s
+
+target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
+target triple = "nvptx64-nvidia-cuda"
+
+; CHECK: CYCLES ASSSUMED DIVERGENT:
+; CHECK-NEXT: depth=1: entries(if.end16 for.cond1) for.body4
+
+define void @foo(i1 %b) {
+entry:
+  br i1 %b, label %if.then, label %if.end16
+
+if.then:                                          ; preds = %entry
+  br label %for.cond1
+
+for.cond1:                                        ; preds = %if.end16, %for.body4, %if.then
+  br i1 false, label %for.body4, label %if.end16
+
+for.body4:                                        ; preds = %for.cond1
+  br label %for.cond1
+
+if.end16:                                         ; preds = %for.cond1, %entry
+  br label %for.cond1
+}


        


More information about the llvm-commits mailing list