[llvm] [InstCombine] Fold its select user into select (PR #83405)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 16 11:52:56 PDT 2024
================
@@ -500,6 +500,48 @@ static bool isSelect01(const APInt &C1I, const APInt &C2I) {
return C1I.isOne() || C1I.isAllOnes() || C2I.isOne() || C2I.isAllOnes();
}
+/// Try to simplify a select instruction when the user of its select user
+/// indicates the condition.
+static bool simplifySeqSelectWithSameCond(SelectInst &SI,
+ const SimplifyQuery &SQ,
+ InstCombinerImpl &IC) {
+ Value *CondVal = SI.getCondition();
+ if (isa<Constant>(CondVal))
+ return false;
+
+ auto TrysimplifySeqSelect = [=, &SI, &IC](unsigned OpIndex) {
+ assert((OpIndex == 1 || OpIndex == 2) && "Unexpected operand index");
+ Type *CondType = CondVal->getType();
+ Value *RepOp = OpIndex == 1 ? ConstantInt::getTrue(CondType)
+ : ConstantInt::getFalse(CondType);
+ SelectInst *SINext = &SI;
+ Value *ValOp = SINext->getOperand(OpIndex);
+ Value *CondNext;
+ while (match(ValOp, m_Select(m_Value(CondNext), m_Value(), m_Value()))) {
+ if (CondNext == CondVal)
+ if (Value *S = simplifyWithOpReplaced(ValOp, CondVal, RepOp, SQ,
----------------
goldsteinn wrote:
Think this is invalid if `ValOp` has multiple uses as you are simplifying based on the context of a single use.
Think you can just do `IC.replaceOperand(*SINext, OpIndx, cast<SelectInst>(ValOp)->getOperand(OpIndex)`.
https://github.com/llvm/llvm-project/pull/83405
More information about the llvm-commits
mailing list