Index: lib/Transforms/Scalar/CorrelatedValuePropagation.cpp =================================================================== --- lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -136,7 +136,7 @@ /// --> /// %r = %x static bool simplifyCommonValuePhi(PHINode *P, LazyValueInfo *LVI, - const SimplifyQuery &SQ) { + DominatorTree *DT) { // Collect incoming constants and initialize possible common value. SmallVector, 4> IncomingConstants; Value *CommonValue = nullptr; @@ -159,7 +159,7 @@ // The common value must be valid in all incoming blocks. BasicBlock *ToBB = P->getParent(); if (auto *CommonInst = dyn_cast(CommonValue)) - if (!SQ.DT->dominates(CommonInst, ToBB)) + if (!DT->dominates(CommonInst, ToBB)) return false; // We have a phi with exactly 1 variable incoming value and 1 or more constant @@ -180,7 +180,7 @@ return true; } -static bool processPHI(PHINode *P, LazyValueInfo *LVI, +static bool processPHI(PHINode *P, LazyValueInfo *LVI, DominatorTree *DT, const SimplifyQuery &SQ) { bool Changed = false; @@ -242,7 +242,7 @@ } if (!Changed) - Changed = simplifyCommonValuePhi(P, LVI, SQ); + Changed = simplifyCommonValuePhi(P, LVI, DT); if (Changed) ++NumPhis; @@ -669,7 +669,8 @@ ConstantInt::getFalse(C->getContext()); } -static bool runImpl(Function &F, LazyValueInfo *LVI, const SimplifyQuery &SQ) { +static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT, + const SimplifyQuery &SQ) { bool FnChanged = false; // Visiting in a pre-order depth-first traversal causes us to simplify early // blocks before querying later blocks (which require us to analyze early @@ -685,7 +686,7 @@ BBChanged |= processSelect(cast(II), LVI); break; case Instruction::PHI: - BBChanged |= processPHI(cast(II), LVI, SQ); + BBChanged |= processPHI(cast(II), LVI, DT, SQ); break; case Instruction::ICmp: case Instruction::FCmp: @@ -750,14 +751,17 @@ return false; LazyValueInfo *LVI = &getAnalysis().getLVI(); - return runImpl(F, LVI, getBestSimplifyQuery(*this, F)); + DominatorTree *DT = &getAnalysis().getDomTree(); + + return runImpl(F, LVI, DT, getBestSimplifyQuery(*this, F)); } PreservedAnalyses CorrelatedValuePropagationPass::run(Function &F, FunctionAnalysisManager &AM) { - LazyValueInfo *LVI = &AM.getResult(F); - bool Changed = runImpl(F, LVI, getBestSimplifyQuery(AM, F)); + DominatorTree *DT = &AM.getResult(F); + + bool Changed = runImpl(F, LVI, DT, getBestSimplifyQuery(AM, F)); if (!Changed) return PreservedAnalyses::all(); Index: test/Transforms/CorrelatedValuePropagation/add.ll =================================================================== --- test/Transforms/CorrelatedValuePropagation/add.ll +++ test/Transforms/CorrelatedValuePropagation/add.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -correlated-propagation -cvp-dont-process-adds=false -S | FileCheck %s +; RUN: opt < %s -passes="correlated-propagation" -cvp-dont-process-adds=false -S | FileCheck %s ; CHECK-LABEL: @test0( define void @test0(i32 %a) { Index: test/Transforms/CorrelatedValuePropagation/phi-common-val.ll =================================================================== --- test/Transforms/CorrelatedValuePropagation/phi-common-val.ll +++ test/Transforms/CorrelatedValuePropagation/phi-common-val.ll @@ -1,5 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -correlated-propagation -S | FileCheck %s +; RUN: opt < %s -passes="correlated-propagation" -S | FileCheck %s define i8* @simplify_phi_common_value_op0(i8* %ptr, i32* %b) { ; CHECK-LABEL: @simplify_phi_common_value_op0(