[llvm] [licm] clone metadata when hoisting conditional branch (PR #152232)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 12:46:16 PDT 2025


================
@@ -857,9 +859,18 @@ class ControlFlowHoister {
     }
 
     // Now finally clone BI.
-    ReplaceInstWithInst(
-        HoistTarget->getTerminator(),
-        BranchInst::Create(HoistTrueDest, HoistFalseDest, BI->getCondition()));
+    auto *NewBI =
+        BranchInst::Create(HoistTrueDest, HoistFalseDest, BI->getCondition());
+    ReplaceInstWithInst(HoistTarget->getTerminator(), NewBI);
+    // Copy all the metadata. In particular:
+    // - debug info (critical to Sample-based profiling) should be the same as
+    // the original branch, not that of HoistTarget->getTerminator(), which is
+    // what ReplaceInstWithInst would use.
+    // - md_prof should also come from the original branch - since the condition
+    // was hoisted, the branch probabilities shouldn't change.
+    if (!ProfcheckDisableMetadataFixes)
----------------
mtrofin wrote:

For its temporary purpose, it's easier if I just control all these kinds of changes this way. I'll remove it after (basically I want to lump all fixes I can detect via profcheck, and it's OK if some aren't enabled anyway - just want to approximate the benefit)

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


More information about the llvm-commits mailing list