[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
Tue Jan 3 07:31:02 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGaca7441c7ae2: [LoopFusion] Exit early if one of fusion candidate has guarded branch but theā€¦ (authored by StephenFan).

Changed prior to commit:
  https://reviews.llvm.org/D138269?vs=483086&id=485991#toc

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
@@ -896,9 +896,10 @@
             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) ||
+              (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.485991.patch
Type: text/x-patch
Size: 2251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230103/832cf1b0/attachment.bin>


More information about the llvm-commits mailing list