[llvm] [Passes] Add option for LoopVersioningLICM pass. (PR #67107)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 03:36:46 PDT 2023
https://github.com/lcvon007 updated https://github.com/llvm/llvm-project/pull/67107
>From 2f48cf7403652799227210bdc432ebed153324be Mon Sep 17 00:00:00 2001
From: laichunfeng <laichunfeng at tencent.com>
Date: Fri, 22 Sep 2023 09:51:31 +0800
Subject: [PATCH 1/3] [Passes] Add option for LoopVersioningLICM pass.
This option was deleted before when removing cl::opts
controling optimization pass manager passes in
https://reviews.llvm.org/D137915
---
llvm/lib/Passes/PassBuilderPipelines.cpp | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 5f5d92d277c1bfc..1cad0697927064e 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -105,6 +105,7 @@
#include "llvm/Transforms/Scalar/LoopSink.h"
#include "llvm/Transforms/Scalar/LoopUnrollAndJamPass.h"
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
+#include "llvm/Transforms/Scalar/LoopVersioningLICM.h"
#include "llvm/Transforms/Scalar/LowerConstantIntrinsics.h"
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
#include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h"
@@ -271,6 +272,10 @@ static cl::opt<AttributorRunOption> AttributorRun(
clEnumValN(AttributorRunOption::NONE, "none",
"disable attributor runs")));
+static cl::opt<bool> UseLoopVersioningLICM(
+ "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
+ cl::desc("Enable the experimental Loop Versioning LICM pass"));
+
cl::opt<bool> EnableMemProfContextDisambiguation(
"enable-memprof-context-disambiguation", cl::init(false), cl::Hidden,
cl::ZeroOrMore, cl::desc("Enable MemProf context disambiguation"));
@@ -1293,6 +1298,21 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
if (RunPartialInlining)
MPM.addPass(PartialInlinerPass());
+ // Scheduling LoopVersioningLICM when inlining is over, because after that
+ // we may see more accurate aliasing. Reason to run this late is that too
+ // early versioning may prevent further inlining due to increase of code
+ // size. By placing it just after inlining other optimizations which runs
+ // later might get benefit of no-alias assumption in clone loop.
+ if (UseLoopVersioningLICM) {
+ MPM.addPass(createModuleToFunctionPassAdaptor(
+ createFunctionToLoopPassAdaptor(LoopVersioningLICMPass())));
+ MPM.addPass(
+ createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor(
+ LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+ /*AllowSpeculation=*/true),
+ /*USeMemorySSA=*/true, /*UseBlockFrequencyInfo=*/false)));
+ }
+
// Remove avail extern fns and globals definitions since we aren't compiling
// an object file for later LTO. For LTO we want to preserve these so they
// are eligible for inlining at link-time. Note if they are unreferenced they
>From 7b099488af8894215ba0ea0c5ccebb986f1759f1 Mon Sep 17 00:00:00 2001
From: laichunfeng <laichunfeng at tencent.com>
Date: Tue, 26 Sep 2023 22:16:47 +0800
Subject: [PATCH 2/3] [Passes] Mov licm pass into OptimizePM.
---
llvm/lib/Passes/PassBuilderPipelines.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 1cad0697927064e..48f272492bbf5f9 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1303,15 +1303,9 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
// early versioning may prevent further inlining due to increase of code
// size. By placing it just after inlining other optimizations which runs
// later might get benefit of no-alias assumption in clone loop.
- if (UseLoopVersioningLICM) {
+ if (UseLoopVersioningLICM)
MPM.addPass(createModuleToFunctionPassAdaptor(
createFunctionToLoopPassAdaptor(LoopVersioningLICMPass())));
- MPM.addPass(
- createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor(
- LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
- /*AllowSpeculation=*/true),
- /*USeMemorySSA=*/true, /*UseBlockFrequencyInfo=*/false)));
- }
// Remove avail extern fns and globals definitions since we aren't compiling
// an object file for later LTO. For LTO we want to preserve these so they
@@ -1363,6 +1357,12 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
invokeOptimizerEarlyEPCallbacks(MPM, Level);
FunctionPassManager OptimizePM;
+ // LoopVersioningLICM pass may increase new LICM opportunities.
+ if (UseLoopVersioningLICM)
+ OptimizePM.addPass(createFunctionToLoopPassAdaptor(
+ LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
+ /*AllowSpeculation=*/true),
+ /*USeMemorySSA=*/true, /*UseBlockFrequencyInfo=*/false));
OptimizePM.addPass(Float2IntPass());
OptimizePM.addPass(LowerConstantIntrinsicsPass());
>From 06bc923c61f8ee6694f1070581dc9eb779cf9d3d Mon Sep 17 00:00:00 2001
From: laichunfeng <laichunfeng at tencent.com>
Date: Wed, 27 Sep 2023 18:34:44 +0800
Subject: [PATCH 3/3] [Passes] Mov LoopVersioningLICM into OptimizePM.
---
llvm/lib/Passes/PassBuilderPipelines.cpp | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 48f272492bbf5f9..0f81a909572e30c 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1298,15 +1298,6 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
if (RunPartialInlining)
MPM.addPass(PartialInlinerPass());
- // Scheduling LoopVersioningLICM when inlining is over, because after that
- // we may see more accurate aliasing. Reason to run this late is that too
- // early versioning may prevent further inlining due to increase of code
- // size. By placing it just after inlining other optimizations which runs
- // later might get benefit of no-alias assumption in clone loop.
- if (UseLoopVersioningLICM)
- MPM.addPass(createModuleToFunctionPassAdaptor(
- createFunctionToLoopPassAdaptor(LoopVersioningLICMPass())));
-
// Remove avail extern fns and globals definitions since we aren't compiling
// an object file for later LTO. For LTO we want to preserve these so they
// are eligible for inlining at link-time. Note if they are unreferenced they
@@ -1357,12 +1348,21 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
invokeOptimizerEarlyEPCallbacks(MPM, Level);
FunctionPassManager OptimizePM;
- // LoopVersioningLICM pass may increase new LICM opportunities.
- if (UseLoopVersioningLICM)
+ // Scheduling LoopVersioningLICM when inlining is over, because after that
+ // we may see more accurate aliasing. Reason to run this late is that too
+ // early versioning may prevent further inlining due to increase of code
+ // size. Other optimizations which runs later might get benefit of no-alias
+ // assumption in clone loop.
+ if (UseLoopVersioningLICM) {
+ OptimizePM.addPass(
+ createFunctionToLoopPassAdaptor(LoopVersioningLICMPass()));
+ // LoopVersioningLICM pass may increase new LICM opportunities.
OptimizePM.addPass(createFunctionToLoopPassAdaptor(
LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap,
/*AllowSpeculation=*/true),
/*USeMemorySSA=*/true, /*UseBlockFrequencyInfo=*/false));
+ }
+
OptimizePM.addPass(Float2IntPass());
OptimizePM.addPass(LowerConstantIntrinsicsPass());
More information about the llvm-commits
mailing list