Skip to content

Commit 0d64113

Browse files
committed
Stitch in loop passes in codegen pipeline
1 parent f541a3a commit 0d64113

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,16 @@
107107
#include "llvm/Target/CGPassBuilderOption.h"
108108
#include "llvm/Target/TargetMachine.h"
109109
#include "llvm/Transforms/CFGuard.h"
110+
#include "llvm/Transforms/ObjCARC.h"
110111
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
111112
#include "llvm/Transforms/Scalar/LoopPassManager.h"
112113
#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
114+
#include "llvm/Transforms/Scalar/LoopTermFold.h"
113115
#include "llvm/Transforms/Scalar/LowerConstantIntrinsics.h"
114116
#include "llvm/Transforms/Scalar/MergeICmps.h"
115117
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
116118
#include "llvm/Transforms/Scalar/ScalarizeMaskedMemIntrin.h"
119+
#include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h"
117120
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
118121
#include "llvm/Transforms/Utils/LowerInvoke.h"
119122
#include <cassert>
@@ -690,7 +693,12 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
690693

691694
// Run loop strength reduction before anything else.
692695
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableLSR) {
693-
addPass(createFunctionToLoopPassAdaptor(LoopStrengthReducePass(),
696+
LoopPassManager LPM;
697+
LPM.addPass(CanonicalizeFreezeInLoopsPass());
698+
LPM.addPass(LoopStrengthReducePass());
699+
if (Opt.EnableLoopTermFold)
700+
LPM.addPass(LoopTermFoldPass());
701+
addPass(createFunctionToLoopPassAdaptor(std::move(LPM),
694702
/*UseMemorySSA=*/true));
695703
}
696704

@@ -735,7 +743,8 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
735743
addPass(ScalarizeMaskedMemIntrinPass());
736744

737745
// Expand reduction intrinsics into shuffle sequences if the target wants to.
738-
addPass(ExpandReductionsPass());
746+
if (!Opt.DisableExpandReductions)
747+
addPass(ExpandReductionsPass());
739748

740749
// Convert conditional moves to conditional jumps when profitable.
741750
if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
@@ -810,6 +819,9 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPrepare(
810819
AddIRPass &addPass) const {
811820
derived().addPreISel(addPass);
812821

822+
if (getOptLevel() != CodeGenOptLevel::None)
823+
addPass(ObjCARCContractPass());
824+
813825
addPass(CallBrPreparePass());
814826
// Add both the safe stack and the stack protection passes: each of them will
815827
// only protect functions that have corresponding attributes.

llvm/include/llvm/Target/CGPassBuilderOption.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct CGPassBuilderOption {
5151
bool EnableMachineFunctionSplitter = false;
5252
bool EnableSinkAndFold = false;
5353
bool EnableTailMerge = true;
54+
/// Enable LoopTermFold immediately after LSR
55+
bool EnableLoopTermFold = false;
5456
bool MISchedPostRA = false;
5557
bool EarlyLiveIntervals = false;
5658
bool GCEmptyBlocks = false;

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@
101101
#include "llvm/Transforms/Scalar/FlattenCFG.h"
102102
#include "llvm/Transforms/Scalar/GVN.h"
103103
#include "llvm/Transforms/Scalar/InferAddressSpaces.h"
104+
#include "llvm/Transforms/Scalar/LICM.h"
104105
#include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
106+
#include "llvm/Transforms/Scalar/LoopPassManager.h"
105107
#include "llvm/Transforms/Scalar/NaryReassociate.h"
106108
#include "llvm/Transforms/Scalar/SeparateConstOffsetFromGEP.h"
107109
#include "llvm/Transforms/Scalar/Sink.h"
@@ -2021,7 +2023,11 @@ void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
20212023
// TODO: May want to move later or split into an early and late one.
20222024
addPass(AMDGPUCodeGenPreparePass(TM));
20232025

2024-
// TODO: LICM
2026+
// Try to hoist loop invariant parts of divisions AMDGPUCodeGenPrepare may
2027+
// have expanded.
2028+
if (TM.getOptLevel() > CodeGenOptLevel::Less)
2029+
addPass(createFunctionToLoopPassAdaptor(LICMPass(LICMOptions()),
2030+
/*UseMemorySSA=*/true));
20252031
}
20262032

20272033
Base::addIRPasses(addPass);

0 commit comments

Comments
 (0)