[llvm] [InstCombine] Simplify nested selects with implied condition (PR #83739)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 3 21:37:00 PST 2024
================
@@ -3867,5 +3867,22 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
}
}
+ // Fold nested selects if the inner condition can be implied by the outer
+ // condition.
+ Value *InnerCondVal;
+ const DataLayout &DL = getDataLayout();
+ if (match(TrueVal,
+ m_Select(m_Value(InnerCondVal), m_Value(LHS), m_Value(RHS))) &&
+ CondVal->getType() == InnerCondVal->getType())
+ if (auto Implied =
+ isImpliedCondition(CondVal, InnerCondVal, DL, /*LHSIsTrue=*/true))
+ return replaceOperand(SI, 1, *Implied ? LHS : RHS);
+ if (match(FalseVal,
+ m_Select(m_Value(InnerCondVal), m_Value(LHS), m_Value(RHS))) &&
+ CondVal->getType() == InnerCondVal->getType())
+ if (auto Implied =
+ isImpliedCondition(CondVal, InnerCondVal, DL, /*LHSIsTrue=*/false))
+ return replaceOperand(SI, 2, *Implied ? LHS : RHS);
+
----------------
dtcxzyw wrote:
Fixed.
https://github.com/llvm/llvm-project/pull/83739
More information about the llvm-commits
mailing list