[llvm] [profcheck] Add indirect call metadata (PR #154657)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 20 21:04:24 PDT 2025


================
@@ -92,12 +97,16 @@ bool ProfileInjector::inject() {
     return false;
   bool Changed = false;
   for (auto &BB : F) {
-    if (AnnotateSelect) {
-      for (auto &I : BB) {
-        if (isa<SelectInst>(I) && !I.getMetadata(LLVMContext::MD_prof))
-          setBranchWeights(I, {SelectTrueWeight, SelectFalseWeight},
-                           /*IsExpected=*/false);
-      }
+    for (auto &I : BB) {
+      if (AnnotateSelect && isa<SelectInst>(I) &&
+          !I.getMetadata(LLVMContext::MD_prof))
----------------
mingmingl-llvm wrote:

> wdym about "and this set-metadata code path runs again on the same instruction"? 
 
Initially I thought this code is about annotating indirect calls based on contextual profile content (which is not the case :)) and wondered when we see some indirect call instructions with `!prof` and some needs additional annotation. Now I realized the motivation of `ProfileVerify.cpp` is to inject profile metadata (earlier in the pipeline) and verify they exists (as opposed to being dropped) later in the pipeline, and in this case we certainly don't want to override the existing `!prof`. Thanks for following up!

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


More information about the llvm-commits mailing list