[PATCH] D138269: [LoopFusion] Exit early if one of fusion candidate has guarded branch but the another has not

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 23:12:41 PST 2022


StephenFan updated this revision to Diff 483086.
StephenFan added a comment.

Pre-commit test check regeneration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138269

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


Index: llvm/test/Transforms/LoopFusion/guarded.ll
===================================================================
--- llvm/test/Transforms/LoopFusion/guarded.ll
+++ llvm/test/Transforms/LoopFusion/guarded.ll
@@ -360,3 +360,33 @@
   %j.lcssa = phi i64 [ 0, %for.second.guard ], [ %j.02, %for.second.exit ]
   ret i64 %j.lcssa
 }
+
+define void @pr59024() {
+; CHECK-LABEL: @pr59024(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br i1 false, label [[FOR_2_PREHEADER:%.*]], label [[FOR_1_PREHEADER:%.*]]
+; CHECK:       for.1.preheader:
+; CHECK-NEXT:    br label [[FOR_1:%.*]]
+; CHECK:       for.1:
+; CHECK-NEXT:    br i1 true, label [[FOR_2_PREHEADER_LOOPEXIT:%.*]], label [[FOR_1]]
+; CHECK:       for.2.preheader.loopexit:
+; CHECK-NEXT:    br label [[FOR_2_PREHEADER]]
+; CHECK:       for.2.preheader:
+; CHECK-NEXT:    br label [[FOR_2:%.*]]
+; CHECK:       for.2:
+; CHECK-NEXT:    br i1 true, label [[EXIT:%.*]], label [[FOR_2]]
+; CHECK:       exit:
+; CHECK-NEXT:    ret void
+;
+entry:
+  br i1 false, label %for.2, label %for.1
+
+for.1:                                        ; preds = %for.body6, %entry
+  br i1 true, label %for.2, label %for.1
+
+for.2:                                       ; preds = %for.cond13, %for.body6, %entry
+  br i1 true, label %exit, label %for.2
+
+exit:                                          ; preds = %for.cond13
+  ret void
+}
Index: llvm/lib/Transforms/Scalar/LoopFuse.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -895,9 +895,9 @@
             continue;
           }
 
-          if (!FC0->GuardBranch && FC1->GuardBranch) {
-            LLVM_DEBUG(dbgs() << "The second candidate is guarded while the "
-                                 "first one is not. Not fusing.\n");
+          if (!FC0->GuardBranch != !FC1->GuardBranch) {
+            LLVM_DEBUG(dbgs() << "The one of candidate is guarded while the "
+                                 "another one is not. Not fusing.\n");
             reportLoopFusion<OptimizationRemarkMissed>(
                 *FC0, *FC1, OnlySecondCandidateIsGuarded);
             continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138269.483086.patch
Type: text/x-patch
Size: 2191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221215/9ce923c8/attachment-0001.bin>


More information about the llvm-commits mailing list