[PATCH] D139993: [LoopFusion] Sorting of undominated FusionCandidates crashes

Ramkrishnan Narayanan Komala via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 07:43:01 PST 2022


ram-NK updated this revision to Diff 483186.
ram-NK added a comment.

@Narutoworld, @aeubanks, Comments in code are corrected.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139993/new/

https://reviews.llvm.org/D139993

Files:
  llvm/lib/Transforms/Scalar/LoopFuse.cpp
  llvm/test/Transforms/LoopFusion/undominated_loops.ll


Index: llvm/test/Transforms/LoopFusion/undominated_loops.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopFusion/undominated_loops.ll
@@ -0,0 +1,26 @@
+; RUN: opt -S -passes=loop-simplify,newgvn,loop-fusion -pass-remarks-analysis=loop-fusion -disable-output < %s 2>&1 | FileCheck %s
+
+; CHECK: remark: <unknown>:0:0: [function_0]: Loop is not a candidate for fusion: Loop has unknown trip count
+
+define void @function_0() {
+entry_1:
+  br i1 false, label %bb_2, label %bb_3
+
+bb_2:                                         ; preds = %bb_7, %bb_5, %bb_2, %entry_1
+  br i1 false, label %bb_2, label %bb_5
+
+bb_3:                                         ; preds = %bb_3, %entry_1
+  br i1 false, label %bb_3, label %bb_4
+
+bb_4:                                         ; preds = %bb_3
+  br label %bb_6
+
+bb_5:                                         ; preds = %bb_2
+  br i1 undef, label %bb_2, label %bb_7
+
+bb_6:                                         ; preds = %bb_7, %bb_6, %bb_4
+  br i1 undef, label %bb_7, label %bb_6
+
+bb_7:                                         ; preds = %bb_6, %bb_5
+  br i1 undef, label %bb_2, label %bb_6
+}
Index: llvm/lib/Transforms/Scalar/LoopFuse.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -415,9 +415,29 @@
       return true;
     }
 
-    // If LHS does not dominate RHS and RHS does not dominate LHS then there is
-    // no dominance relationship between the two FusionCandidates. Thus, they
-    // should not be in the same set together.
+    // If two FusionCandidates are in the same level of dominator tree,
+    // they will not dominate each other, but may still be control flow
+    // equivalent. To sort those FusionCandidates, nonStrictlyPostDominate()
+    // function is needed.
+    bool wrongOrder =
+        nonStrictlyPostDominate(LHSEntryBlock, RHSEntryBlock, DT, LHS.PDT);
+    bool rightOrder =
+        nonStrictlyPostDominate(RHSEntryBlock, LHSEntryBlock, DT, LHS.PDT);
+    if (wrongOrder && rightOrder) {
+      // If common predecessor of LHS and RHS post dominates both
+      // FusionCandidates then, Order of FusionCandidate can be
+      // identified by its level in post dominator tree.
+      DomTreeNode *LNode = LHS.PDT->getNode(LHSEntryBlock);
+      DomTreeNode *RNode = LHS.PDT->getNode(RHSEntryBlock);
+        return (LNode->getLevel() > RNode->getLevel());
+    } else if (wrongOrder)
+      return false;
+    else if (rightOrder)
+      return true;
+
+    // If LHS does not non-strict Postdominate RHS and RHS does not non-strict
+    // Postdominate LHS then, there is no dominance relationship between the
+    // two FusionCandidates. Thus, they should not be in the same set together.
     llvm_unreachable(
         "No dominance relationship between these fusion candidates!");
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139993.483186.patch
Type: text/x-patch
Size: 2969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221215/45c74a28/attachment.bin>


More information about the llvm-commits mailing list