Index: llvm/lib/Transforms/IPO/IROutliner.cpp =================================================================== --- llvm/lib/Transforms/IPO/IROutliner.cpp +++ llvm/lib/Transforms/IPO/IROutliner.cpp @@ -1292,7 +1292,7 @@ } unsigned IROutliner::findCostOutputReloads(OutlinableGroup &CurrentGroup) { - unsigned OverallCost = 0; + InstructionCost OverallCost = 0; for (OutlinableRegion *Region : CurrentGroup.Regions) { TargetTransformInfo &TTI = getTTI(*Region->StartBB->getParent()); @@ -1301,7 +1301,7 @@ Optional OV = Region->Candidate->fromGVN(OutputGVN); assert(OV.hasValue() && "Could not find value for GVN?"); Value *V = OV.getValue(); - unsigned LoadCost = + InstructionCost LoadCost = TTI.getMemoryOpCost(Instruction::Load, V->getType(), Align(1), 0, TargetTransformInfo::TCK_CodeSize); @@ -1312,7 +1312,8 @@ } } - return OverallCost; + assert(OverallCost.isValid() && "Invalid cost found"); + return *OverallCost.getValue(); } /// Find the extra instructions needed to handle any output values for the @@ -1326,7 +1327,7 @@ static unsigned findCostForOutputBlocks(Module &M, OutlinableGroup &CurrentGroup, TargetTransformInfo &TTI) { - unsigned OutputCost = 0; + InstructionCost OutputCost = 0; for (const ArrayRef &OutputUse : CurrentGroup.OutputGVNCombinations) { @@ -1335,7 +1336,7 @@ Optional OV = Candidate.fromGVN(GVN); assert(OV.hasValue() && "Could not find value for GVN?"); Value *V = OV.getValue(); - unsigned StoreCost = + InstructionCost StoreCost = TTI.getMemoryOpCost(Instruction::Load, V->getType(), Align(1), 0, TargetTransformInfo::TCK_CodeSize); @@ -1348,7 +1349,7 @@ OutputCost += StoreCost; } - unsigned BranchCost = + InstructionCost BranchCost = TTI.getCFInstrCost(Instruction::Br, TargetTransformInfo::TCK_CodeSize); LLVM_DEBUG(dbgs() << "Adding " << BranchCost << " to the current cost for" << " a branch instruction\n"); @@ -1358,15 +1359,15 @@ // If there is more than one output scheme, we must have a comparison and // branch for each different item in the switch statement. if (CurrentGroup.OutputGVNCombinations.size() > 1) { - unsigned ComparisonCost = TTI.getCmpSelInstrCost( + InstructionCost ComparisonCost = TTI.getCmpSelInstrCost( Instruction::ICmp, Type::getInt32Ty(M.getContext()), Type::getInt32Ty(M.getContext()), CmpInst::BAD_ICMP_PREDICATE, TargetTransformInfo::TCK_CodeSize); - unsigned BranchCost = + InstructionCost BranchCost = TTI.getCFInstrCost(Instruction::Br, TargetTransformInfo::TCK_CodeSize); unsigned DifferentBlocks = CurrentGroup.OutputGVNCombinations.size(); - unsigned TotalCost = ComparisonCost * BranchCost * DifferentBlocks; + InstructionCost TotalCost = ComparisonCost * BranchCost * DifferentBlocks; LLVM_DEBUG(dbgs() << "Adding: " << TotalCost << " instructions for each switch case for each different" @@ -1374,7 +1375,8 @@ OutputCost += TotalCost; } - return OutputCost; + assert(OutputCost.isValid() && "Invalid cost found"); + return *OutputCost.getValue(); } void IROutliner::findCostBenefit(Module &M, OutlinableGroup &CurrentGroup) {