diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 415136b612ac2..602228bcb8289 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -2789,6 +2789,13 @@ void JumpThreadingPass::unfoldSelectInstr(BasicBlock *Pred, BasicBlock *BB, PredTerm->removeFromParent(); PredTerm->insertInto(NewBB, NewBB->end()); // Create a conditional branch and update PHI nodes. + // + // Note: Technically we should `freeze` the condition before using it in a + // conditional branch, unless we can prove it's not poison: select-on-on + // poison isn't UB, but branch-on-poison is. But doing this causes + // performance regressions, and we haven't been able to find a source-level + // correctness issue it fixes. See + // https://github.com/llvm/llvm-project/pull/199408#issuecomment-4545013881. auto *BI = CondBrInst::Create(SI->getCondition(), NewBB, BB, Pred); BI->applyMergedLocation(PredTerm->getDebugLoc(), SI->getDebugLoc()); BI->copyMetadata(*SI, {LLVMContext::MD_prof});