[llvm-branch-commits] [llvm] [NFC] (PR #80762)

Mingming Liu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 7 18:21:08 PST 2024


https://github.com/minglotus-6 updated https://github.com/llvm/llvm-project/pull/80762

>From 2a03c530e775faa79d2e800a38a4228b38dfea35 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Wed, 7 Feb 2024 18:20:51 -0800
Subject: [PATCH] resolve review feedback

Created using spr 1.3.4
---
 .../Instrumentation/IndirectCallPromotion.cpp | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
index 6a44a32bb34dc9..23a7c6a20aecbc 100644
--- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -291,17 +291,21 @@ bool IndirectCallPromoter::tryToPromoteWithFuncCmp(
     NumPromoted++;
   }
 
-  const bool Changed = (NumPromoted != 0);
+  if (NumPromoted == 0)
+    return false;
 
-  if (Changed) {
-    CB.setMetadata(LLVMContext::MD_prof, nullptr);
+  // Adjust the MD.prof metadata. First delete the old one.
+  CB.setMetadata(LLVMContext::MD_prof, nullptr);
 
-    if (TotalCount != 0)
-      annotateValueSite(*F.getParent(), CB, ICallProfDataRef.slice(NumPromoted),
-                        TotalCount, IPVK_IndirectCallTarget, NumCandidates);
-  }
+  assert(NumPromoted <= ICallProfDataRef.size() &&
+         "Number of promoted functions should not be greater than the number "
+         "of values in profile metadata");
+  // Annotate the remaining value profiles if counter is not zero.
+  if (TotalCount != 0)
+    annotateValueSite(*F.getParent(), CB, ICallProfDataRef.slice(NumPromoted),
+                      TotalCount, IPVK_IndirectCallTarget, NumCandidates);
 
-  return Changed;
+  return true;
 }
 
 // Traverse all the indirect-call callsite and get the value profile



More information about the llvm-branch-commits mailing list