[llvm] [Inliner] Don't count a call penalty for foldable __memcpy_chk and similar (PR #117876)
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 23:37:28 PST 2024
================
@@ -2260,6 +2271,45 @@ bool CallAnalyzer::simplifyCallSite(Function *F, CallBase &Call) {
return false;
}
+bool CallAnalyzer::isLoweredToCall(Function *F, CallBase &Call) {
+ const TargetLibraryInfo *TLI = GetTLI ? &GetTLI(*F) : nullptr;
+ LibFunc LF;
+ if (!TLI || !TLI->getLibFunc(*F, LF) || !TLI->has(LF))
+ return TTI.isLoweredToCall(F);
+
+ switch (LF) {
+ case LibFunc_memcpy_chk:
+ case LibFunc_memmove_chk:
+ case LibFunc_mempcpy_chk:
+ case LibFunc_memset_chk:
+ // Calls to __memcpy_chk whose length is known to fit within the object
+ // size will eventually be replaced by inline stores. Therefore, these
+ // should not incur a call penalty. This is only really relevant on
+ // platforms whose headers redirect memcpy to __memcpy_chk (e.g. Mac), as
+ // other platforms use memcpy intrinsics, which are already exempt from the
+ // call penalty.
+ {
+ auto LenOp = dyn_cast_or_null<ConstantInt>(Call.getOperand(2));
----------------
aemerson wrote:
`auto *` for pointers. But also it shouldn't be possible for the call operand to be null so a vanilla `dyn_cast` should suffice?
https://github.com/llvm/llvm-project/pull/117876
More information about the llvm-commits
mailing list