Skip to content

Commit 704603a

Browse files
committed
Stitch in loop passes in codegen pipeline
1 parent 45100af commit 704603a

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
@@ -110,13 +110,16 @@
110110
#include "llvm/Target/CGPassBuilderOption.h"
111111
#include "llvm/Target/TargetMachine.h"
112112
#include "llvm/Transforms/CFGuard.h"
113+
#include "llvm/Transforms/ObjCARC.h"
113114
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
114115
#include "llvm/Transforms/Scalar/LoopPassManager.h"
115116
#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
117+
#include "llvm/Transforms/Scalar/LoopTermFold.h"
116118
#include "llvm/Transforms/Scalar/LowerConstantIntrinsics.h"
117119
#include "llvm/Transforms/Scalar/MergeICmps.h"
118120
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
119121
#include "llvm/Transforms/Scalar/ScalarizeMaskedMemIntrin.h"
122+
#include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h"
120123
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
121124
#include "llvm/Transforms/Utils/LowerInvoke.h"
122125
#include <cassert>
@@ -691,7 +694,12 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
691694

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

@@ -736,7 +744,8 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
736744
addPass(ScalarizeMaskedMemIntrinPass());
737745

738746
// Expand reduction intrinsics into shuffle sequences if the target wants to.
739-
addPass(ExpandReductionsPass());
747+
if (!Opt.DisableExpandReductions)
748+
addPass(ExpandReductionsPass());
740749

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

823+
if (getOptLevel() != CodeGenOptLevel::None)
824+
addPass(ObjCARCContractPass());
825+
814826
addPass(CallBrPreparePass());
815827
// Add both the safe stack and the stack protection passes: each of them will
816828
// 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)