[llvm] [TailCallElim] Only suppress tail call elim for cold calls in cold funcs (PR #215842)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 10:45:20 PDT 2026


================
@@ -114,20 +114,29 @@ static bool shouldDisableTailCallsForCold(const CallBase *CB,
   if (CB && CB->isMustTailCall())
     return false;
 
-  if (CB && (CB->hasFnAttr(Attribute::Cold) ||
-             CB->getCallingConv() == CallingConv::Cold))
-    return true;
-
   if (Caller && (Caller->hasFnAttribute(Attribute::Cold) ||
                  Caller->getCallingConv() == CallingConv::Cold))
     return true;
 
   if (!PSI || !PSI->hasProfileSummary())
     return false;
 
-  if (CB && BFI &&
-      (PSI->isColdCallSite(*CB, BFI) || PSI->isColdBlock(CB->getParent(), BFI)))
-    return true;
+  // We require both the function entry and the call site/block/callee to be
+  // cold.
+  // 1. Checking that the function entry is cold ensures we don't disable tail
+  //    call elimination in hot functions (with calls on cold conditional
+  //    paths), which would force stack frame setup and teardown on hot paths.
+  // 2. Checking that the call site/block/callee is also cold ensures that if a
+  //    function has a cold entry count but contains a hot loop, we don't
+  //    disable tail call elimination for calls within that hot loop.
+  if (Caller && PSI->isFunctionEntryCold(Caller) && CB) {
----------------
teresajohnson wrote:

Done in PR218153.

https://github.com/llvm/llvm-project/pull/215842


More information about the llvm-commits mailing list