[llvm] [licm] clone metadata when hoisting conditional branch (PR #152232)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 10:31:08 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.
----------------
snehasish wrote:
Filed #152767 to track the addition of a new flag and to update the documentation.
I don't think we should enable it by default for O2/O3 though. I received pushback even when suggesting we add it under `-fdebug-info-for-profiling`. It should be purely opt-in especially for the cases where the location may be non-representable.
To keep this PR moving along can we leave the behaviour for debug information unchanged (add a TODO with the issue number) and only address the profile metadata being dropped?
https://github.com/llvm/llvm-project/pull/152232
More information about the llvm-commits
mailing list