@@ -746,9 +746,10 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
746
746
case VPInstruction::BranchOnCount: {
747
747
Type *ValTy = Ctx.Types .inferScalarType (getOperand (0 ));
748
748
749
- // If the vector loop only executed once, ignore the cost.
749
+ // If the vector loop only executed once (VF == original trip count), ignore
750
+ // the cost of cmp.
750
751
// TODO: We can remove this after hoist `unrollByUF` and
751
- // `optimizeForVFandUF` which will should optimize BranchOnCount out.
752
+ // `optimizeForVFandUF` which will optimize BranchOnCount out.
752
753
auto TC = dyn_cast_if_present<ConstantInt>(
753
754
getParent ()->getPlan ()->getTripCount ()->getUnderlyingValue ());
754
755
if (TC && VF.isFixed () && TC->getSExtValue () == VF.getFixedValue ())
@@ -760,22 +761,19 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
760
761
CmpInst::ICMP_EQ, Ctx.CostKind );
761
762
}
762
763
case VPInstruction::BranchOnCond: {
763
- // BranchOnCond will generate `extractelement` when the condition is vector
764
- // type.
765
- VPValue *Op = getOperand (0 );
766
- VPRecipeBase *R = Op->getDefiningRecipe ();
767
- if (R &&
768
- any_of (R->operands (), [&](VPValue *V) { return !R->usesScalars (V); }) &&
769
- VF.isVector ())
770
- return Ctx.TTI .getVectorInstrCost (
771
- Instruction::ExtractElement,
772
- cast<VectorType>(
773
- toVectorTy (Ctx.Types .inferScalarType (getOperand (0 )), VF)),
774
- Ctx.CostKind , 0 , nullptr , nullptr );
775
-
776
- // Otherwise, BranchOnCond is free since the branch cost is already
764
+
765
+ // BranchOnCond is free since the branch cost is already
777
766
// calculated by VPBB.
778
- return 0 ;
767
+ if (vputils::onlyFirstLaneUsed (getOperand (0 )))
768
+ return 0 ;
769
+
770
+ // Otherwise, BranchOnCond will generate `extractelement` to extract the
771
+ // condition from vector type.
772
+ return Ctx.TTI .getVectorInstrCost (
773
+ Instruction::ExtractElement,
774
+ cast<VectorType>(
775
+ toVectorTy (Ctx.Types .inferScalarType (getOperand (0 )), VF)),
776
+ Ctx.CostKind , 0 , nullptr , nullptr );
779
777
}
780
778
default :
781
779
// TODO: Compute cost other VPInstructions once the legacy cost model has
0 commit comments