[llvm] [InstSimplify] Discard unnecessary `select` when the conditions are `ICmps` with EQ (PR #179183)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 06:31:34 PST 2026
================
@@ -5142,6 +5167,36 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
return ConstantVector::get(NewC);
}
+ CmpPredicate Pred1, Pred2;
+ Value *V1, *V2, *EQV;
+ if (match(Cond,
+ m_And(m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(V1), m_Value(EQV)),
+ m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(V2),
+ m_Deferred(EQV)))))
+ if (Value *V = simplifySelectWithEquivalence(
+ {{V2, EQV}, {V1, EQV}}, TrueVal, FalseVal, Q, MaxRecurse)) {
+ // We should only throw away a select if we get a select in place of that
+ // because of the poison barrier property.
+ SelectInst *VasSI = dyn_cast<SelectInst>(V);
+ // Also we have to check if the removing of the current select doesn't
+ // introduce any new poison. We should only remove the current select if
+ // its condition is poison in every case where the new select condition is
+ // poison.
+ if (VasSI && impliesPoison(VasSI->getCondition(), Cond))
----------------
dtcxzyw wrote:
I don't think the refinement check should be placed here. `simplifySelectWithEquivalence` should not refine the result, as it passes `AllowRefinement=false` when simplifying the false arm.
I guess there is something wrong with `simplifyWithOpsReplaced`.
https://github.com/llvm/llvm-project/pull/179183
More information about the llvm-commits
mailing list