From: Evgeny Astigeevich Date: Thu, 27 Jul 2017 12:49:27 +0000 (+0000) Subject: [InlineCost, NFC] Change CallAnalyzer::isGEPFree to use TTI::getUserCost instead... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e067bb531a93576aa0af97e720d5c8fd734868de;p=llvm [InlineCost, NFC] Change CallAnalyzer::isGEPFree to use TTI::getUserCost instead of TTI::getGEPCost Currently CallAnalyzer::isGEPFree uses TTI::getGEPCost to check if GEP is free. TTI::getGEPCost cannot handle cases when GEPs participate in Def-Use dependencies (see https://reviews.llvm.org/D31186 for example). There is TTI::getUserCost which can calculate the cost more accurately by taking dependencies into account. Differential Revision: https://reviews.llvm.org/D33685 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309268 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp index 35693666aa0..8be2ee7881a 100644 --- a/lib/Analysis/InlineCost.cpp +++ b/lib/Analysis/InlineCost.cpp @@ -348,15 +348,14 @@ bool CallAnalyzer::accumulateGEPOffset(GEPOperator &GEP, APInt &Offset) { /// /// Respects any simplified values known during the analysis of this callsite. bool CallAnalyzer::isGEPFree(GetElementPtrInst &GEP) { - SmallVector Indices; + SmallVector Operands; + Operands.push_back(GEP.getOperand(0)); for (User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end(); I != E; ++I) if (Constant *SimpleOp = SimplifiedValues.lookup(*I)) - Indices.push_back(SimpleOp); + Operands.push_back(SimpleOp); else - Indices.push_back(*I); - return TargetTransformInfo::TCC_Free == - TTI.getGEPCost(GEP.getSourceElementType(), GEP.getPointerOperand(), - Indices); + Operands.push_back(*I); + return TargetTransformInfo::TCC_Free == TTI.getUserCost(&GEP, Operands); } bool CallAnalyzer::visitAlloca(AllocaInst &I) {