[llvm] [VPlan] Use predicate from VPValue VPWidenSelectR::computeCost (NFCI) (PR #172915)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 18 14:09:13 PST 2025
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/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.
>From 1ce9d8d51eb6570bbea8ff95992bae84e9cef1f5 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Thu, 18 Dec 2025 22:02:02 +0000
Subject: [PATCH] [VPlan] Use predicate from VPValue
VPWidenSelectR::computeCost (NFCI)
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.
---
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 5 ++---
.../test/Transforms/LoopVectorize/AArch64/select-costs.ll | 8 ++++----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 25a678e8b37c7..46aa4be786fed 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -1963,9 +1963,8 @@ InstructionCost VPWidenSelectRecipe::computeCost(ElementCount VF,
if (!ScalarCond)
CondTy = VectorType::get(CondTy, VF);
- CmpInst::Predicate Pred = CmpInst::BAD_ICMP_PREDICATE;
- if (auto *Cmp = dyn_cast<CmpInst>(SI->getCondition()))
- Pred = Cmp->getPredicate();
+ llvm::CmpPredicate Pred = CmpInst::BAD_ICMP_PREDICATE;
+ match(getOperand(0), m_Cmp(Pred, m_VPValue(), m_VPValue()));
return Ctx.TTI.getCmpSelInstrCost(
Instruction::Select, VectorTy, CondTy, Pred, Ctx.CostKind,
{TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None}, SI);
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll b/llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll
index 7fcfcf05b89ca..9460705e61c9c 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll
@@ -92,10 +92,10 @@ exit:
define i32 @select_xor_cond(ptr %src, i1 %c.0) {
; CHECK: LV: Checking a loop in 'select_xor_cond'
-; CHECK: Cost of 6 for VF 2: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
-; CHECK: Cost of 12 for VF 4: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
-; CHECK: Cost of 24 for VF 8: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
-; CHECK: Cost of 48 for VF 16: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
+; CHECK: Cost of 1 for VF 2: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
+; CHECK: Cost of 1 for VF 4: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
+; CHECK: Cost of 1 for VF 8: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
+; CHECK: Cost of 1 for VF 16: WIDEN-SELECT ir<%sel> = select ir<%c>, ir<false>, ir<%c.0>
; CHECK: LV: Selecting VF: 4.
entry:
More information about the llvm-commits
mailing list