diff options
author | Haicheng Wu <haicheng@codeaurora.org> | 2017-01-20 16:36:34 +0000 |
---|---|---|
committer | Haicheng Wu <haicheng@codeaurora.org> | 2017-01-20 16:36:34 +0000 |
commit | 8f34ae2aae4025d041d5358f00affecd92aa8cae (patch) | |
tree | ee9aeb14cfbad2edb9c3c632c7dfd35c8549ff56 /llvm/lib/Analysis/InlineCost.cpp | |
parent | 56fb6fef50070d92d3137bcf912580f607e465b8 (diff) | |
download | bcm5719-llvm-8f34ae2aae4025d041d5358f00affecd92aa8cae.tar.gz bcm5719-llvm-8f34ae2aae4025d041d5358f00affecd92aa8cae.zip |
Recommit "[InlineCost] Use TTI to check if GEP is free." #2
This is the second attemp to recommit r292526.
The original summary:
Currently, a GEP is considered free only if its indices are all constant.
TTI::getGEPCost() can give target-specific more accurate analysis. TTI is
already used for the cost of many other instructions.
llvm-svn: 292616
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 4109049ecab..b6c3997dae3 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -134,6 +134,7 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> { void accumulateSROACost(DenseMap<Value *, int>::iterator CostIt, int InstructionCost); bool isGEPOffsetConstant(GetElementPtrInst &GEP); + bool isGEPFree(GetElementPtrInst &GEP); bool accumulateGEPOffset(GEPOperator &GEP, APInt &Offset); bool simplifyCallSite(Function *F, CallSite CS); ConstantInt *stripAndComputeInBoundsConstantOffsets(Value *&V); @@ -331,6 +332,21 @@ bool CallAnalyzer::accumulateGEPOffset(GEPOperator &GEP, APInt &Offset) { return true; } +/// \brief Use TTI to check whether a GEP is free. +/// +/// Respects any simplified values known during the analysis of this callsite. +bool CallAnalyzer::isGEPFree(GetElementPtrInst &GEP) { + SmallVector<Value *, 4> Indices; + 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); + else + Indices.push_back(*I); + return TargetTransformInfo::TCC_Free == + TTI.getGEPCost(GEP.getSourceElementType(), GEP.getPointerOperand(), + Indices); +} + bool CallAnalyzer::visitAlloca(AllocaInst &I) { // Check whether inlining will turn a dynamic alloca into a static // alloca and handle that case. @@ -396,7 +412,7 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) { // Non-constant GEPs aren't folded, and disable SROA. if (SROACandidate) disableSROA(CostIt); - return false; + return isGEPFree(I); } // Add the result as a new mapping to Base + Offset. @@ -422,7 +438,7 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) { // Variable GEPs will require math and will disable SROA. if (SROACandidate) disableSROA(CostIt); - return false; + return isGEPFree(I); } bool CallAnalyzer::visitBitCast(BitCastInst &I) { |