Skip to content

Commit d7fa21f

Browse files
committed
[VPlan] Use predicate in VPInstruction::computeCost for selects.
In some cases, the lowering a select depends on the predicate. If the condition of a select is a compare instruction, thread the predicate through to the TTI hook.
1 parent f3f7679 commit d7fa21f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,8 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
10081008

10091009
switch (getOpcode()) {
10101010
case Instruction::Select: {
1011-
// TODO: It may be possible to improve this by analyzing where the
1012-
// condition operand comes from.
1013-
CmpInst::Predicate Pred = CmpInst::BAD_ICMP_PREDICATE;
1011+
llvm::CmpPredicate Pred = CmpInst::BAD_ICMP_PREDICATE;
1012+
match(getOperand(0), m_Cmp(Pred, m_VPValue(), m_VPValue()));
10141013
auto *CondTy = Ctx.Types.inferScalarType(getOperand(0));
10151014
auto *VecTy = Ctx.Types.inferScalarType(getOperand(1));
10161015
if (!vputils::onlyFirstLaneUsed(this)) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ exit:
7676

7777
define i32 @select_vpinst_for_tail_folding(i8 %n) {
7878
; CHECK: LV: Checking a loop in 'select_vpinst_for_tail_folding'
79-
; CHECK: Cost of 6 for VF 2: EMIT vp<{{.+}}> = select vp<{{.+}}>, ir<%red.next>, ir<%red>
80-
; CHECK: Cost of 12 for VF 4: EMIT vp<{{.+}}> = select vp<{{.+}}>, ir<%red.next>, ir<%red>
81-
; CHECK: LV: Selecting VF: 1
79+
; CHECK: Cost of 1 for VF 2: EMIT vp<{{.+}}> = select vp<{{.+}}>, ir<%red.next>, ir<%red>
80+
; CHECK: Cost of 1 for VF 4: EMIT vp<{{.+}}> = select vp<{{.+}}>, ir<%red.next>, ir<%red>
81+
; CHECK: LV: Selecting VF: 4
8282

8383
entry:
8484
%c = icmp ne i8 %n, 0

0 commit comments

Comments
 (0)