[llvm] [licm] clone metadata when hoisting conditional branch (PR #152232)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 11:19:34 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(),
+ HoistTarget->getTerminator()->getIterator());
+ HoistTarget->getTerminator()->eraseFromParent();
+ // 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.
----------------
mtrofin wrote:
Oh, if there's precedent re. auto-enabling, sgtm.
Adding the flag and change in behavior is trivial, especially since (my earlier comment) we actually shouldn't just move all the metadata over. The documentation part of Issue #152767 can be addressed separately, imho.
https://github.com/llvm/llvm-project/pull/152232
More information about the llvm-commits
mailing list