[llvm] [licm] clone metadata when hoisting conditional branch (PR #152232)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 11:20:13 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 (!DisableProfilingInfoCorrectPropagation)
+ NewBI->copyMetadata(*BI);
----------------
snehasish wrote:
For debug information, it looks like ReplaceInstWithInst first copies over the wrong debug info, then we update it to the right one as part of this copyMetadata call? The hidden manipulation of some types of metadata seems like a design that could be improved.
https://github.com/llvm/llvm-project/pull/152232
More information about the llvm-commits
mailing list