Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp =================================================================== --- lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1674,7 +1674,7 @@ SmallPtrSet IVIncSet; void OptimizeShadowIV(); - bool FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse); + bool FindIVUserForInst(Instruction *Inst, IVStrideUse *&InstUse); ICmpInst *OptimizeMax(ICmpInst *Cond, IVStrideUse* &CondUse); void OptimizeLoopTermCond(); @@ -1896,15 +1896,15 @@ } } -/// If Cond has an operand that is an expression of an IV, set the IV user and +/// If Inst has an operand that is an expression of an IV, set the IV user and /// stride information and return true, otherwise return false. -bool LSRInstance::FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse) { +bool LSRInstance::FindIVUserForInst(Instruction *Inst, IVStrideUse *&InstUse) { for (IVStrideUse &U : IU) - if (U.getUser() == Cond) { + if (U.getUser() == Inst) { // NOTE: we could handle setcc instructions with multiple uses here, but // InstCombine does it as well for simple uses, it's not clear that it // occurs enough in real life to handle. - CondUse = &U; + InstUse = &U; return true; } return false; @@ -2114,7 +2114,7 @@ // Search IVUsesByStride to find Cond's IVUse if there is one. IVStrideUse *CondUse = nullptr; ICmpInst *Cond = cast(TermBr->getCondition()); - if (!FindIVUserForCond(Cond, CondUse)) + if (!FindIVUserForInst(Cond, CondUse)) continue; // If the trip count is computed in terms of a max (due to ScalarEvolution @@ -2815,7 +2815,7 @@ DEBUG(dbgs() << "Final Chain: " << *Chain.Incs[0].UserInst << "\n"); for (const IVInc &Inc : Chain) { - DEBUG(dbgs() << " Inc: " << Inc.UserInst << "\n"); + DEBUG(dbgs() << " Inc: " << *Inc.UserInst << "\n"); auto UseI = find(Inc.UserInst->operands(), Inc.IVOperand); assert(UseI != Inc.UserInst->op_end() && "cannot find IV operand"); IVIncSet.insert(UseI); @@ -4144,9 +4144,10 @@ for (const SCEV *Reg : RegUses) { if (Taken.count(Reg)) continue; - if (!Best) + if (!Best) { Best = Reg; - else { + BestNum = RegUses.getUsedByIndices(Reg).count(); + } else { unsigned Count = RegUses.getUsedByIndices(Reg).count(); if (Count > BestNum) { Best = Reg;