leonardchan created this revision. leonardchan added reviewers: chandlerc, arsenm, nhaehnle. leonardchan added a project: LLVM. Herald added subscribers: cfe-commits, dexonsmith, steven_wu, hiraditya, wdng. Herald added a project: clang.
The `SpeculativeExecutionPass` was running under the new PM for non-GPU targets. It appears that the pass would run regardless as long as speed optimizations were available. In this patch: - Split the `SpeculativeExecutionPass` into a separate one (`SpeculativeExecutionIfHasBranchDivergencePass`) that mirrors the 2 passes in the legacy PM - Replace the `SpeculativeExecutionPass` with `SpeculativeExecutionIfHasBranchDivergencePass` in the new PM pipeline - Update tests that expected the previous pass when running Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76389 Files: clang/test/CodeGen/thinlto-distributed-newpm.ll llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h llvm/lib/Passes/PassBuilder.cpp llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp llvm/test/Other/new-pm-defaults.ll llvm/test/Other/new-pm-thinlto-defaults.ll llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll =================================================================== --- llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll +++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll @@ -96,7 +96,7 @@ ; CHECK-O-NEXT: Running pass: SROA ; CHECK-O-NEXT: Running pass: EarlyCSEPass ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis -; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass +; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionIfHasBranchDivergencePass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass Index: llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll =================================================================== --- llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll +++ llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll @@ -126,7 +126,7 @@ ; CHECK-Os-NEXT: Running analysis: TargetIRAnalysis on foo ; CHECK-Oz-NEXT: Running analysis: TargetIRAnalysis on foo ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis -; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass +; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionIfHasBranchDivergencePass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass Index: llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll =================================================================== --- llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll +++ llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll @@ -97,7 +97,7 @@ ; CHECK-O-NEXT: Running pass: SROA ; CHECK-O-NEXT: Running pass: EarlyCSEPass ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis -; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass +; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionIfHasBranchDivergencePass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass Index: llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll =================================================================== --- llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll +++ llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll @@ -89,7 +89,7 @@ ; CHECK-O-NEXT: Running pass: SROA ; CHECK-O-NEXT: Running pass: EarlyCSEPass ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis -; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass +; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionIfHasBranchDivergencePass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass Index: llvm/test/Other/new-pm-thinlto-defaults.ll =================================================================== --- llvm/test/Other/new-pm-thinlto-defaults.ll +++ llvm/test/Other/new-pm-thinlto-defaults.ll @@ -117,7 +117,7 @@ ; CHECK-O-NEXT: Running pass: SROA ; CHECK-O-NEXT: Running pass: EarlyCSEPass ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis -; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass +; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionIfHasBranchDivergencePass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass Index: llvm/test/Other/new-pm-defaults.ll =================================================================== --- llvm/test/Other/new-pm-defaults.ll +++ llvm/test/Other/new-pm-defaults.ll @@ -151,7 +151,7 @@ ; CHECK-O-NEXT: Running pass: SROA ; CHECK-O-NEXT: Running pass: EarlyCSEPass ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis -; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass +; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionIfHasBranchDivergencePass ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis ; CHECK-O23SZ-NEXT: Running pass: CorrelatedValuePropagationPass Index: llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp +++ llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp @@ -123,7 +123,7 @@ // Variable preserved purely for correct name printing. const bool OnlyIfDivergentTarget; - SpeculativeExecutionPass Impl; + SpeculativeExecutionPassImpl Impl; }; } // namespace @@ -150,7 +150,8 @@ namespace llvm { -bool SpeculativeExecutionPass::runImpl(Function &F, TargetTransformInfo *TTI) { +bool SpeculativeExecutionPassImpl::runImpl(Function &F, + TargetTransformInfo *TTI) { if (OnlyIfDivergentTarget && !TTI->hasBranchDivergence()) { LLVM_DEBUG(dbgs() << "Not running SpeculativeExecution because " "TTI->hasBranchDivergence() is false.\n"); @@ -165,7 +166,7 @@ return Changed; } -bool SpeculativeExecutionPass::runOnBasicBlock(BasicBlock &B) { +bool SpeculativeExecutionPassImpl::runOnBasicBlock(BasicBlock &B) { BranchInst *BI = dyn_cast<BranchInst>(B.getTerminator()); if (BI == nullptr) return false; @@ -251,8 +252,8 @@ } } -bool SpeculativeExecutionPass::considerHoistingFromTo( - BasicBlock &FromBlock, BasicBlock &ToBlock) { +bool SpeculativeExecutionPassImpl::considerHoistingFromTo(BasicBlock &FromBlock, + BasicBlock &ToBlock) { SmallPtrSet<const Instruction *, 8> NotHoisted; const auto AllPrecedingUsesFromBlockHoisted = [&NotHoisted](User *U) { for (Value* V : U->operand_values()) { @@ -299,12 +300,13 @@ return new SpeculativeExecutionLegacyPass(/* OnlyIfDivergentTarget = */ true); } -SpeculativeExecutionPass::SpeculativeExecutionPass(bool OnlyIfDivergentTarget) +SpeculativeExecutionPassImpl::SpeculativeExecutionPassImpl( + bool OnlyIfDivergentTarget) : OnlyIfDivergentTarget(OnlyIfDivergentTarget || SpecExecOnlyIfDivergentTarget) {} -PreservedAnalyses SpeculativeExecutionPass::run(Function &F, - FunctionAnalysisManager &AM) { +PreservedAnalyses +SpeculativeExecutionPassImpl::run(Function &F, FunctionAnalysisManager &AM) { auto *TTI = &AM.getResult<TargetIRAnalysis>(F); bool Changed = runImpl(F, TTI); Index: llvm/lib/Passes/PassBuilder.cpp =================================================================== --- llvm/lib/Passes/PassBuilder.cpp +++ llvm/lib/Passes/PassBuilder.cpp @@ -432,7 +432,7 @@ // Speculative execution if the target has divergent branches; otherwise nop. if (Level.getSpeedupLevel() > 1) { - FPM.addPass(SpeculativeExecutionPass()); + FPM.addPass(SpeculativeExecutionIfHasBranchDivergencePass()); // Optimize based on known information about branches, and cleanup afterward. FPM.addPass(JumpThreadingPass()); Index: llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h =================================================================== --- llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h +++ llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h @@ -66,10 +66,9 @@ #include "llvm/IR/PassManager.h" namespace llvm { -class SpeculativeExecutionPass - : public PassInfoMixin<SpeculativeExecutionPass> { +class SpeculativeExecutionPassImpl { public: - SpeculativeExecutionPass(bool OnlyIfDivergentTarget = false); + SpeculativeExecutionPassImpl(bool OnlyIfDivergentTarget = false); PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); @@ -86,6 +85,22 @@ TargetTransformInfo *TTI = nullptr; }; + +class SpeculativeExecutionPass + : public SpeculativeExecutionPassImpl, + public PassInfoMixin<SpeculativeExecutionPass> { +public: + SpeculativeExecutionPass(bool OnlyIfDivergentTarget = false) + : SpeculativeExecutionPassImpl(OnlyIfDivergentTarget) {} +}; + +class SpeculativeExecutionIfHasBranchDivergencePass + : public SpeculativeExecutionPassImpl, + public PassInfoMixin<SpeculativeExecutionIfHasBranchDivergencePass> { +public: + SpeculativeExecutionIfHasBranchDivergencePass() + : SpeculativeExecutionPassImpl(/*OnlyIfDivergentTarget=*/true) {} +}; } #endif //LLVM_TRANSFORMS_SCALAR_SPECULATIVEEXECUTION_H Index: clang/test/CodeGen/thinlto-distributed-newpm.ll =================================================================== --- clang/test/CodeGen/thinlto-distributed-newpm.ll +++ clang/test/CodeGen/thinlto-distributed-newpm.ll @@ -107,7 +107,7 @@ ; CHECK-O: Running analysis: ScopedNoAliasAA on main ; CHECK-O: Running analysis: TypeBasedAA on main ; CHECK-O: Running analysis: OuterAnalysisManagerProxy -; CHECK-O: Running pass: SpeculativeExecutionPass on main +; CHECK-O: Running pass: SpeculativeExecutionIfHasBranchDivergencePass on main ; CHECK-O: Running pass: JumpThreadingPass on main ; CHECK-O: Running analysis: LazyValueAnalysis on main ; CHECK-O: Running pass: CorrelatedValuePropagationPass on main
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits