[llvm] [SLP] Improve cost model for i1 select-as-or/and patterns (PR #188572)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 25 12:56:06 PDT 2026
================
@@ -15999,19 +15999,40 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
CmpPredicate CurrentPred = ScalarTy->isFloatingPointTy()
? CmpInst::BAD_FCMP_PREDICATE
: CmpInst::BAD_ICMP_PREDICATE;
+ Value *LHS = nullptr, *RHS = nullptr;
auto MatchCmp = m_Cmp(CurrentPred, m_Value(), m_Value());
- if ((!match(VI, m_Select(MatchCmp, m_Value(), m_Value())) &&
- !match(VI, MatchCmp)) ||
+ bool IsSelect = ShuffleOrOp == Instruction::Select &&
+ match(VI, m_Select(MatchCmp, m_Value(LHS), m_Value(RHS)));
+ if ((!IsSelect && !match(VI, MatchCmp)) ||
(CurrentPred != static_cast<CmpInst::Predicate>(VecPred) &&
CurrentPred != static_cast<CmpInst::Predicate>(SwappedVecPred)))
VecPred = SwappedVecPred = ScalarTy->isFloatingPointTy()
? CmpInst::BAD_FCMP_PREDICATE
: CmpInst::BAD_ICMP_PREDICATE;
- InstructionCost ScalarCost = TTI->getCmpSelInstrCost(
- E->getOpcode(), OrigScalarTy, Builder.getInt1Ty(), CurrentPred,
- CostKind, getOperandInfo(VI->getOperand(0)),
- getOperandInfo(VI->getOperand(1)), VI);
+ // Check if operands are of i1 types, like a condition expression.
+ InstructionCost ScalarCost = InstructionCost::getInvalid();
+ if (IsSelect && LHS->getType() == VI->getOperand(0)->getType()) {
+ assert(LHS->getType() == RHS->getType() &&
+ "Expected same type for LHS/RHS");
+ // select i1 v, i1 true, i1 b -> or i1 v, i1 b
+ if (match(LHS, m_One())) {
+ ScalarCost = TTI->getArithmeticInstrCost(
+ Instruction::Or, LHS->getType(), CostKind,
+ getOperandInfo(VI->getOperand(0)), getOperandInfo(RHS));
+ } else if (match(RHS, m_Zero())) {
+ // select i1 v, i1 b, i1 false -> and i1 v, i1 b
+ ScalarCost = TTI->getArithmeticInstrCost(
+ Instruction::And, LHS->getType(), CostKind,
+ getOperandInfo(VI->getOperand(0)), getOperandInfo(LHS));
----------------
alexey-bataev wrote:
Nope, need to get info for condition (operand 0) and LHS (operand 1)
https://github.com/llvm/llvm-project/pull/188572
More information about the llvm-commits
mailing list