[PATCH] D136781: ensure loop-simplifed form when running loop-fusion pass with new-PM
MengXuan Cai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 27 13:11:23 PDT 2022
Narutoworld updated this revision to Diff 471277.
Narutoworld added a comment.
Update patch based on comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136781/new/
https://reviews.llvm.org/D136781
Files:
llvm/lib/Transforms/Scalar/LoopFuse.cpp
llvm/test/Transforms/LoopFusion/ensure_loop_simplify_form.ll
Index: llvm/test/Transforms/LoopFusion/ensure_loop_simplify_form.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopFusion/ensure_loop_simplify_form.ll
@@ -0,0 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=loop-fusion -S | FileCheck %s
+
+define void @v_5_0(i32* %dummy) {
+; CHECK-LABEL: @v_5_0(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[FOR_BODY:%.*]]
+; CHECK: for.cond.cleanup:
+; CHECK-NEXT: br i1 true, label [[FOR_BODY6_PREHEADER:%.*]], label [[FOR_COND_CLEANUP5:%.*]]
+; CHECK: for.body6.preheader:
+; CHECK-NEXT: br label [[FOR_BODY6:%.*]]
+; CHECK: for.body:
+; CHECK-NEXT: br i1 false, label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
+; CHECK: for.cond.cleanup5:
+; CHECK-NEXT: ret void
+; CHECK: for.body6:
+; CHECK-NEXT: [[V_LOOP_2_0_V_LOOP_2_0_V_LOOP_2_0_18:%.*]] = load volatile i32, i32* [[DUMMY:%.*]], align 1
+; CHECK-NEXT: br label [[FOR_BODY6]]
+;
+entry:
+ br label %for.body
+
+for.cond.cleanup: ; preds = %for.body
+ br i1 true, label %for.body6, label %for.cond.cleanup5
+
+for.body: ; preds = %for.body, %entry
+ br i1 false, label %for.cond.cleanup, label %for.body
+
+for.cond.cleanup5: ; preds = %for.cond.cleanup
+ ret void
+
+for.body6: ; preds = %for.body6, %for.cond.cleanup
+ %v_loop_2.0.v_loop_2.0.v_loop_2.0.18 = load volatile i32, i32* %dummy, align 1
+ br label %for.body6
+}
Index: llvm/lib/Transforms/Scalar/LoopFuse.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -67,6 +67,7 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/CodeMoverUtils.h"
#include "llvm/Transforms/Utils/LoopPeel.h"
+#include "llvm/Transforms/Utils/LoopSimplify.h"
using namespace llvm;
@@ -2077,16 +2078,27 @@
PreservedAnalyses LoopFusePass::run(Function &F, FunctionAnalysisManager &AM) {
auto &LI = AM.getResult<LoopAnalysis>(F);
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
- auto &DI = AM.getResult<DependenceAnalysis>(F);
auto &SE = AM.getResult<ScalarEvolutionAnalysis>(F);
- auto &PDT = AM.getResult<PostDominatorTreeAnalysis>(F);
- auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
auto &AC = AM.getResult<AssumptionAnalysis>(F);
+
+ // Ensure loops are in simplifed form which is a pre-requisite for loop fusion
+ // pass. Added only for new PM since the legacy PM has already added
+ // LoopSimplify pass as a dependency.
+ bool Changed = false;
+ for (auto &L : LI) {
+ if (!L->isLoopSimplifyForm())
+ Changed |= simplifyLoop(L, &DT, &LI, &SE, &AC, nullptr,
+ false /* PreserveLCSSA */);
+ }
+
+ auto &DI = AM.getResult<DependenceAnalysis>(F);
+ auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
+ auto &PDT = AM.getResult<PostDominatorTreeAnalysis>(F);
const TargetTransformInfo &TTI = AM.getResult<TargetIRAnalysis>(F);
const DataLayout &DL = F.getParent()->getDataLayout();
LoopFuser LF(LI, DT, DI, SE, PDT, ORE, DL, AC, TTI);
- bool Changed = LF.fuseLoops(F);
+ Changed |= LF.fuseLoops(F);
if (!Changed)
return PreservedAnalyses::all();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136781.471277.patch
Type: text/x-patch
Size: 3478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221027/d2e18258/attachment.bin>
More information about the llvm-commits
mailing list