Index: llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp =================================================================== --- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -2184,13 +2184,18 @@ const T *S = cast(WorkItem.S); int Cost = 0; - // Object to help map SCEV operands to expanded IR instructions. + // Object to help map SCEV operands to expanded IR instructions. For each + // operand of the SCEVExpr, in the given WorkItem, we will expand to one or + // more instructions. This struct holds the opcode of that instruction as + // well as the minimum and maximum operand indices that we should consider + // when expanding SCEVExpr, with an arbitary number of operands, to a chain + // of instructions. struct OperationIndices { - OperationIndices(unsigned Opc, size_t min, size_t max) : - Opcode(Opc), MinIdx(min), MaxIdx(max) { } + OperationIndices(unsigned Opc, int Min, int Max) : + Opcode(Opc), MinIdx(Min), MaxIdx(Max) { } unsigned Opcode; - size_t MinIdx; - size_t MaxIdx; + int MinIdx; + int MaxIdx; }; // Collect the operations of all the instructions that will be needed to @@ -2305,8 +2310,8 @@ for (auto &CostOp : Operations) { for (auto SCEVOp : enumerate(S->operands())) { // Clamp the index to account for multiple IR operations being chained. - size_t MinIdx = std::max(SCEVOp.index(), CostOp.MinIdx); - size_t OpIdx = std::min(MinIdx, CostOp.MaxIdx); + int MinIdx = std::max((int)SCEVOp.index(), CostOp.MinIdx); + int OpIdx = std::min(MinIdx, CostOp.MaxIdx); Worklist.emplace_back(CostOp.Opcode, OpIdx, SCEVOp.value()); } } @@ -2341,15 +2346,13 @@ : TargetTransformInfo::TCK_RecipThroughput; if (auto *Constant = dyn_cast(S)) { - // Only evalulate the costs of constants when optimizing for size. + // Consider constants to be free unless we are optimizing for size. if (CostKind != TargetTransformInfo::TCK_CodeSize) return 0; - const APInt &Imm = Constant->getAPInt(); - Type *Ty = S->getType(); BudgetRemaining -= TTI.getIntImmCostInst(WorkItem.ParentOpcode, WorkItem.OperandIdx, - Imm, Ty, CostKind); - return BudgetRemaining < 0; + Constant->getAPInt(), S->getType(), CostKind); + return false; } else if (isa(S)) { int Cost = costAndCollectOperands(WorkItem, TTI, CostKind, Worklist);