[llvm] [JumpThreading] NFC: Add comment referencing #199408. (PR #199718)
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 05:04:46 PDT 2026
https://github.com/jlebar updated https://github.com/llvm/llvm-project/pull/199718
>From d9eda95164a5aadaee5884d3e9f613aacc17821d Mon Sep 17 00:00:00 2001
From: Justin Lebar <justin.lebar at gmail.com>
Date: Tue, 26 May 2026 09:16:02 -0700
Subject: [PATCH] [JumpThreading] NFC: Add comment referencing #199408.
Leave a breadcrumb indicating that not `freeze`'ing a select's condition
when turning it into a conditional branch is unsound (unless we can
prove that the cond is never poison). Nonetheless this doesn't seem to
cause real-world problems afaict.
---
llvm/lib/Transforms/Scalar/JumpThreading.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 3e449f1cf2e04..bc9506c987be4 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2800,6 +2800,12 @@ void JumpThreadingPass::unfoldSelectInstr(BasicBlock *Pred, BasicBlock *BB,
PredTerm->removeFromParent();
PredTerm->insertInto(NewBB, NewBB->end());
// Create a conditional branch and update PHI nodes.
+ //
+ // FIXME: We should `freeze` the condition before using it in a conditional
+ // branch, unless we can prove it's not poison: select-on-poison isn't UB,
+ // but branch-on-poison is. But doing this causes performance regressions,
+ // and we haven't been able to find an end-to-end correctness issue it fixes.
+ // 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});
More information about the llvm-commits
mailing list