Skip to content

Commit e77246d

Browse files
authored
[VPlan] Use predicate from VPValue VPWidenSelectR::computeCost. (#172915)
Instead of looking up the predicate from the VPValue condition instead of the underlying IR. This improves cost modeling in some cases, e.g. when we can fold operations like negations in compares. On AArch64, this leads to additional vectorization in a few cases in practice. Example lowering for the modified test case: https://llvm.godbolt.org/z/6nc6jo5eG PR: #172915
1 parent cd13170 commit e77246d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,8 @@ InstructionCost VPWidenSelectRecipe::computeCost(ElementCount VF,
19641964
if (!ScalarCond)
19651965
CondTy = VectorType::get(CondTy, VF);
19661966

1967-
CmpInst::Predicate Pred = CmpInst::BAD_ICMP_PREDICATE;
1968-
if (auto *Cmp = dyn_cast<CmpInst>(SI->getCondition()))
1969-
Pred = Cmp->getPredicate();
1967+
llvm::CmpPredicate Pred;
1968+
match(getOperand(0), m_Cmp(Pred, m_VPValue(), m_VPValue()));
19701969
return Ctx.TTI.getCmpSelInstrCost(
19711970
Instruction::Select, VectorTy, CondTy, Pred, Ctx.CostKind,
19721971
{TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None}, SI);

llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ exit:
9292

9393
define i32 @select_xor_cond(ptr %src, i1 %c.0) {
9494
; CHECK: LV: Checking a loop in 'select_xor_cond'
95-
; CHECK: Cost of 6 for VF 2: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
96-
; CHECK: Cost of 12 for VF 4: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
97-
; CHECK: Cost of 24 for VF 8: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
98-
; CHECK: Cost of 48 for VF 16: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
95+
; CHECK: Cost of 1 for VF 2: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
96+
; CHECK: Cost of 1 for VF 4: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
97+
; CHECK: Cost of 1 for VF 8: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
98+
; CHECK: Cost of 1 for VF 16: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
9999
; CHECK: LV: Selecting VF: 4.
100100

101101
entry:

0 commit comments

Comments
 (0)