diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -35,6 +35,10 @@ cl::desc("When performing SCEV expansion only if it is cheap to do, this " "controls the budget that is considered cheap (default = 4)")); +cl::opt EliminateSCEVUnknownPHI( + "eliminate-SCEVUnknown-phi", cl::Hidden, cl::init(false), + cl::desc("This controls congruent SCEVUnknown PHI node can be replaced.")); + using namespace PatternMatch; /// ReuseOrCreateCast - Arrange for there to be a cast of V to Ty at IP, @@ -2002,7 +2006,11 @@ if (!SE.isSCEVable(Phi->getType())) continue; - PHINode *&OrigPhiRef = ExprToIVMap[SE.getSCEV(Phi)]; + const SCEV* S = SE.getSCEV(Phi); + if (!EliminateSCEVUnknownPHI && isa(S)) + continue; + + PHINode *&OrigPhiRef = ExprToIVMap[S]; if (!OrigPhiRef) { OrigPhiRef = Phi; if (Phi->getType()->isIntegerTy() && TTI && diff --git a/llvm/test/Transforms/LoopStrengthReduce/phi-unknownscev.ll b/llvm/test/Transforms/LoopStrengthReduce/phi-unknownscev.ll --- a/llvm/test/Transforms/LoopStrengthReduce/phi-unknownscev.ll +++ b/llvm/test/Transforms/LoopStrengthReduce/phi-unknownscev.ll @@ -18,8 +18,8 @@ ; %scevgep9798 = bitcast %_elem_type_of_ap* %scevgep97 to [0 x %_elem_type_of_ap]* ; %lsr.iv99 = phi [0 x %_elem_type_of_ap]* [ %24, %_scf_2_skip_ ], [ %scevgep9798, %_loop_1_do_.lr.ph ] -; CHECK: INDVARS: Eliminated congruent iv: -; CHECK-NEXT: INDVARS: Original iv: +; CHECK-NOT: INDVARS: Eliminated congruent iv: +; CHECK-NOT: INDVARS: Original iv: define void @foo(i64* noalias %.n, float* noalias %.alpha, [0 x %_elem_type_of_x]* noalias %.x, [0 x %_elem_type_of_y]* noalias %.y, [0 x %_elem_type_of_ap]* noalias %.ap, i64* noalias %.lda) { entry: