[llvm] [JumpThreading] Infer constants from correlated PHIs (PR #190184)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 07:39:37 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/Scalar/JumpThreading.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 9712fb716..47d7626aa 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -591,14 +591,14 @@ getIncomingBlockConditionValue(Value *Cond, PHINode *GuardPN,
if (CmpPN != GuardPN)
return std::nullopt;
- Value *LHS = GuardOnLHS ? GuardPN->getIncomingValue(IncomingIdx)
- : Cmp->getOperand(0)->DoPHITranslation(PhiBB,
- IncomingBB);
- Value *RHS = GuardOnLHS ? Cmp->getOperand(1)->DoPHITranslation(PhiBB,
- IncomingBB)
- : GuardPN->getIncomingValue(IncomingIdx);
- if (auto *C = dyn_cast_or_null<ConstantInt>(
- simplifyCmpInst(Cmp->getPredicate(), LHS, RHS, {PhiBB->getDataLayout()})))
+ Value *LHS = GuardOnLHS
+ ? GuardPN->getIncomingValue(IncomingIdx)
+ : Cmp->getOperand(0)->DoPHITranslation(PhiBB, IncomingBB);
+ Value *RHS = GuardOnLHS
+ ? Cmp->getOperand(1)->DoPHITranslation(PhiBB, IncomingBB)
+ : GuardPN->getIncomingValue(IncomingIdx);
+ if (auto *C = dyn_cast_or_null<ConstantInt>(simplifyCmpInst(
+ Cmp->getPredicate(), LHS, RHS, {PhiBB->getDataLayout()})))
return !C->isZero();
return std::nullopt;
}
@@ -607,11 +607,9 @@ getIncomingBlockConditionValue(Value *Cond, PHINode *GuardPN,
/// the same block that controls the branch in FromBB. If the branch condition
/// makes exactly one incoming block feasible, use the corresponding incoming
/// value of V.
-static Constant *
-getKnownConstantFromCorrelatedPHI(Value *V, BasicBlock *FromBB,
- BasicBlock *ToBB,
- ConstantPreference Preference,
- LazyValueInfo *LVI) {
+static Constant *getKnownConstantFromCorrelatedPHI(
+ Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
+ ConstantPreference Preference, LazyValueInfo *LVI) {
auto *ValPN = dyn_cast<PHINode>(V);
if (!ValPN)
return nullptr;
@@ -703,8 +701,7 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
// predecessor, use that information to try to thread this block.
Constant *PredCst = LVI->getConstantOnEdge(V, P, BB, CxtI);
if (!PredCst)
- PredCst = getKnownConstantFromCorrelatedPHI(
- V, P, BB, Preference, LVI);
+ PredCst = getKnownConstantFromCorrelatedPHI(V, P, BB, Preference, LVI);
// If I is a non-local compare-with-constant instruction, use more-rich
// 'getPredicateOnEdge' method. This would be able to handle value
// inequalities better, for example if the compare is "X < 4" and "X < 3"
``````````
</details>
https://github.com/llvm/llvm-project/pull/190184
More information about the llvm-commits
mailing list