@@ -713,6 +713,11 @@ Value *VPInstruction::generate(VPTransformState &State) {
713713 Builder.getInt64Ty (), Mask, true , " first.active.lane" );
714714 return Builder.CreateExtractElement (Vec, Ctz, " early.exit.value" );
715715 }
716+ case VPInstruction::StepVector: {
717+ Type *EltTy = State.get (getOperand (0 ), true )->getType ();
718+ return State.Builder .CreateStepVector (VectorType::get (EltTy, State.VF ));
719+ }
720+
716721 default :
717722 llvm_unreachable (" Unsupported opcode for instruction" );
718723 }
@@ -824,6 +829,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
824829 case VPInstruction::LogicalAnd:
825830 case VPInstruction::Not:
826831 case VPInstruction::PtrAdd:
832+ case VPInstruction::StepVector:
827833 return false ;
828834 default :
829835 return true ;
@@ -850,6 +856,7 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
850856 case VPInstruction::BranchOnCount:
851857 case VPInstruction::BranchOnCond:
852858 case VPInstruction::ResumePhi:
859+ case VPInstruction::StepVector:
853860 return true ;
854861 case VPInstruction::PtrAdd:
855862 return Op == getOperand (0 ) || vputils::onlyFirstLaneUsed (this );
@@ -947,6 +954,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
947954 case VPInstruction::ExtractFirstActive:
948955 O << " extract-first-active" ;
949956 break ;
957+ case VPInstruction::StepVector:
958+ O << " step-vector" ;
959+ break ;
950960 default :
951961 O << Instruction::getOpcodeName (getOpcode ());
952962 }
@@ -1710,7 +1720,8 @@ InstructionCost VPHeaderPHIRecipe::computeCost(ElementCount VF,
17101720// / (0 * Step, 1 * Step, 2 * Step, ...)
17111721// / to each vector element of Val.
17121722// / \p Opcode is relevant for FP induction variable.
1713- static Value *getStepVector (Value *Val, Value *Step,
1723+ // / \p InitVec is an integer step vector from 0 with a step of 1.
1724+ static Value *getStepVector (Value *Val, Value *Step, Value *InitVec,
17141725 Instruction::BinaryOps BinOp, ElementCount VF,
17151726 IRBuilderBase &Builder) {
17161727 assert (VF.isVector () && " only vector VFs are supported" );
@@ -1726,15 +1737,6 @@ static Value *getStepVector(Value *Val, Value *Step,
17261737
17271738 SmallVector<Constant *, 8 > Indices;
17281739
1729- // Create a vector of consecutive numbers from zero to VF.
1730- VectorType *InitVecValVTy = ValVTy;
1731- if (STy->isFloatingPointTy ()) {
1732- Type *InitVecValSTy =
1733- IntegerType::get (STy->getContext (), STy->getScalarSizeInBits ());
1734- InitVecValVTy = VectorType::get (InitVecValSTy, VLen);
1735- }
1736- Value *InitVec = Builder.CreateStepVector (InitVecValVTy);
1737-
17381740 if (STy->isIntegerTy ()) {
17391741 Step = Builder.CreateVectorSplat (VLen, Step);
17401742 assert (Step->getType () == Val->getType () && " Invalid step vec" );
@@ -1800,8 +1802,11 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) {
18001802 }
18011803
18021804 Value *SplatStart = Builder.CreateVectorSplat (State.VF , Start);
1803- Value *SteppedStart = getStepVector (SplatStart, Step, ID.getInductionOpcode (),
1804- State.VF , State.Builder );
1805+ assert (cast<VPInstruction>(getStepVector ())->getOpcode () ==
1806+ VPInstruction::StepVector);
1807+ Value *SteppedStart =
1808+ ::getStepVector (SplatStart, Step, State.get(getStepVector()),
1809+ ID.getInductionOpcode(), State.VF, State.Builder);
18051810
18061811 // We create vector phi nodes for both integer and floating-point induction
18071812 // variables. Here, we determine the kind of arithmetic we will perform.
0 commit comments