aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorKirill Naumov <knaumov@azul.com>2020-06-02 19:22:41 +0000
committerKirill Naumov <knaumov@azul.com>2020-06-25 18:09:51 +0000
commitd48c7859fbb911045b34ecd7f816186b9357d894 (patch)
tree6a4e03f91c2ed4e8f9b033d6b599467e0fdd0aef /llvm/lib/Analysis/InlineCost.cpp
parentdbf7603be63957232814bb780de842a1ba84a363 (diff)
downloadllvm-d48c7859fbb911045b34ecd7f816186b9357d894.zip
llvm-d48c7859fbb911045b34ecd7f816186b9357d894.tar.gz
llvm-d48c7859fbb911045b34ecd7f816186b9357d894.tar.bz2
[InlineCost] GetElementPtr with constant operands
If the GEP instruction contanins only constants as its arguments, then it should be recognized as a constant. For now, there was also added a flag to turn off this simplification if it causes any regressions ("disable-gep-const-evaluation") which is off by default. Once I gather needed data of the effectiveness of this simplification, the flag will be deleted. Reviewers: apilipenko, davidxl, mtrofin Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D81026
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index c05d1ee7..33d7144 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -110,6 +110,10 @@ static cl::opt<bool> InlineCallerSupersetNoBuiltin(
cl::desc("Allow inlining when caller has a superset of callee's nobuiltin "
"attributes."));
+static cl::opt<bool> DisableGEPConstOperand(
+ "disable-gep-const-evaluation", cl::Hidden, cl::init(false),
+ cl::desc("Disables evaluation of GetElementPtr with constant operands"));
+
namespace {
class InlineCostCallAnalyzer;
@@ -1019,6 +1023,16 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) {
return true;
};
+ if (!DisableGEPConstOperand)
+ if (simplifyInstruction(I, [&](SmallVectorImpl<Constant *> &COps) {
+ SmallVector<Constant *, 2> Indices;
+ for (unsigned int Index = 1 ; Index < COps.size() ; ++Index)
+ Indices.push_back(COps[Index]);
+ return ConstantExpr::getGetElementPtr(I.getSourceElementType(), COps[0],
+ Indices, I.isInBounds());
+ }))
+ return true;
+
if ((I.isInBounds() && canFoldInboundsGEP(I)) || IsGEPOffsetConstant(I)) {
if (SROAArg)
SROAArgValues[&I] = SROAArg;