diff options
author | Nick Desaulniers <ndesaulniers@google.com> | 2023-01-24 14:54:50 -0800 |
---|---|---|
committer | Nick Desaulniers <ndesaulniers@google.com> | 2023-01-24 15:09:57 -0800 |
commit | f1764d5b594ff6edbf8d17d196eb0b7a653ac0fc (patch) | |
tree | c741fe038d2e1e8a33a896fd75ef346f94e53bea /llvm/lib | |
parent | 7532e88f38a417d3713cb179dc974948c30f0336 (diff) | |
download | llvm-f1764d5b594ff6edbf8d17d196eb0b7a653ac0fc.zip llvm-f1764d5b594ff6edbf8d17d196eb0b7a653ac0fc.tar.gz llvm-f1764d5b594ff6edbf8d17d196eb0b7a653ac0fc.tar.bz2 |
[InlineCost] model calls to llvm.objectsize.*
Very similar to https://reviews.llvm.org/D111272. We very often can
evaluate calls to llvm.objectsize.* regardless of inlining. Don't count
calls to llvm.objectsize.* against the InlineCost when we can evaluate
the call to a constant.
Link: https://github.com/ClangBuiltLinux/linux/issues/1302
Reviewed By: manojgupta
Differential Revision: https://reviews.llvm.org/D111456
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index bce71b2..5bcc8a2 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -22,6 +22,7 @@ #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h" @@ -419,6 +420,7 @@ protected: bool simplifyCallSite(Function *F, CallBase &Call); bool simplifyInstruction(Instruction &I); bool simplifyIntrinsicCallIsConstant(CallBase &CB); + bool simplifyIntrinsicCallObjectSize(CallBase &CB); ConstantInt *stripAndComputeInBoundsConstantOffsets(Value *&V); /// Return true if the given argument to the function being considered for @@ -1602,6 +1604,20 @@ bool CallAnalyzer::simplifyIntrinsicCallIsConstant(CallBase &CB) { return true; } +bool CallAnalyzer::simplifyIntrinsicCallObjectSize(CallBase &CB) { + // As per the langref, "The fourth argument to llvm.objectsize determines if + // the value should be evaluated at runtime." + if(cast<ConstantInt>(CB.getArgOperand(3))->isOne()) + return false; + + Value *V = lowerObjectSizeCall(&cast<IntrinsicInst>(CB), DL, nullptr, + /*MustSucceed=*/true); + Constant *C = dyn_cast_or_null<Constant>(V); + if (C) + SimplifiedValues[&CB] = C; + return C; +} + bool CallAnalyzer::visitBitCast(BitCastInst &I) { // Propagate constants through bitcasts. if (simplifyInstruction(I)) @@ -2214,6 +2230,8 @@ bool CallAnalyzer::visitCallBase(CallBase &Call) { return true; case Intrinsic::is_constant: return simplifyIntrinsicCallIsConstant(Call); + case Intrinsic::objectsize: + return simplifyIntrinsicCallObjectSize(Call); } } |