[llvm] aca7441 - [LoopFusion] Exit early if one of fusion candidate has guarded branch but the another has not
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 3 07:30:57 PST 2023
Author: luxufan
Date: 2023-01-03T23:18:58+08:00
New Revision: aca7441c7ae2c8a0518764265ef6a08449165ced
URL: https://github.com/llvm/llvm-project/commit/aca7441c7ae2c8a0518764265ef6a08449165ced
DIFF: https://github.com/llvm/llvm-project/commit/aca7441c7ae2c8a0518764265ef6a08449165ced.diff
LOG: [LoopFusion] Exit early if one of fusion candidate has guarded branch but the another has not
Fixes: https://github.com/llvm/llvm-project/issues/59024
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D138269
Added:
Modified:
llvm/lib/Transforms/Scalar/LoopFuse.cpp
llvm/test/Transforms/LoopFusion/guarded.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
index 77323f18774ed..34bb165d20ad8 100644
--- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -896,9 +896,10 @@ struct LoopFuser {
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;
diff --git a/llvm/test/Transforms/LoopFusion/guarded.ll b/llvm/test/Transforms/LoopFusion/guarded.ll
index 8037fcecdba58..fb61dde3c31d9 100644
--- a/llvm/test/Transforms/LoopFusion/guarded.ll
+++ b/llvm/test/Transforms/LoopFusion/guarded.ll
@@ -360,3 +360,33 @@ for.end:
%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
+}
More information about the llvm-commits
mailing list