@@ -468,6 +468,11 @@ Value *VPInstruction::generate(VPTransformState &State) {
468
468
Value *A = State.get (getOperand (0 ));
469
469
return Builder.CreateNot (A, Name);
470
470
}
471
+ case Instruction::ExtractElement: {
472
+ Value *Vec = State.get (getOperand (0 ));
473
+ Value *Idx = State.get (getOperand (1 ), true );
474
+ return Builder.CreateExtractElement (Vec, Idx, Name);
475
+ }
471
476
case Instruction::ICmp: {
472
477
bool OnlyFirstLaneUsed = vputils::onlyFirstLaneUsed (this );
473
478
Value *A = State.get (getOperand (0 ), OnlyFirstLaneUsed);
@@ -723,12 +728,10 @@ Value *VPInstruction::generate(VPTransformState &State) {
723
728
Value *A = State.get (getOperand (0 ));
724
729
return Builder.CreateOrReduce (A);
725
730
}
726
- case VPInstruction::ExtractFirstActive: {
727
- Value *Vec = State.get (getOperand (0 ));
728
- Value *Mask = State.get (getOperand (1 ));
729
- Value *Ctz = Builder.CreateCountTrailingZeroElems (
730
- Builder.getInt64Ty (), Mask, true , " first.active.lane" );
731
- return Builder.CreateExtractElement (Vec, Ctz, " early.exit.value" );
731
+ case VPInstruction::FirstActiveLane: {
732
+ Value *Mask = State.get (getOperand (0 ));
733
+ return Builder.CreateCountTrailingZeroElems (Builder.getInt64Ty (), Mask,
734
+ true , Name);
732
735
}
733
736
default :
734
737
llvm_unreachable (" Unsupported opcode for instruction" );
@@ -755,22 +758,24 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
755
758
}
756
759
757
760
switch (getOpcode ()) {
761
+ case Instruction::ExtractElement: {
762
+ // Add on the cost of extracting the element.
763
+ auto *VecTy = toVectorTy (Ctx.Types .inferScalarType (getOperand (0 )), VF);
764
+ return Ctx.TTI .getVectorInstrCost (Instruction::ExtractElement, VecTy,
765
+ Ctx.CostKind );
766
+ }
758
767
case VPInstruction::AnyOf: {
759
768
auto *VecTy = toVectorTy (Ctx.Types .inferScalarType (this ), VF);
760
769
return Ctx.TTI .getArithmeticReductionCost (
761
770
Instruction::Or, cast<VectorType>(VecTy), std::nullopt, Ctx.CostKind );
762
771
}
763
- case VPInstruction::ExtractFirstActive : {
772
+ case VPInstruction::FirstActiveLane : {
764
773
// Calculate the cost of determining the lane index.
765
- auto *PredTy = toVectorTy (Ctx.Types .inferScalarType (getOperand (1 )), VF);
774
+ auto *PredTy = toVectorTy (Ctx.Types .inferScalarType (getOperand (0 )), VF);
766
775
IntrinsicCostAttributes Attrs (Intrinsic::experimental_cttz_elts,
767
776
Type::getInt64Ty (Ctx.LLVMCtx ),
768
777
{PredTy, Type::getInt1Ty (Ctx.LLVMCtx )});
769
- InstructionCost Cost = Ctx.TTI .getIntrinsicInstrCost (Attrs, Ctx.CostKind );
770
- // Add on the cost of extracting the element.
771
- auto *VecTy = toVectorTy (Ctx.Types .inferScalarType (getOperand (0 )), VF);
772
- return Cost + Ctx.TTI .getVectorInstrCost (Instruction::ExtractElement, VecTy,
773
- Ctx.CostKind );
778
+ return Ctx.TTI .getIntrinsicInstrCost (Attrs, Ctx.CostKind );
774
779
}
775
780
case VPInstruction::FirstOrderRecurrenceSplice: {
776
781
assert (VF.isVector () && " Scalar FirstOrderRecurrenceSplice?" );
@@ -793,7 +798,8 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
793
798
794
799
bool VPInstruction::isVectorToScalar () const {
795
800
return getOpcode () == VPInstruction::ExtractFromEnd ||
796
- getOpcode () == VPInstruction::ExtractFirstActive ||
801
+ getOpcode () == Instruction::ExtractElement ||
802
+ getOpcode () == VPInstruction::FirstActiveLane ||
797
803
getOpcode () == VPInstruction::ComputeReductionResult ||
798
804
getOpcode () == VPInstruction::AnyOf;
799
805
}
@@ -853,13 +859,14 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
853
859
if (Instruction::isBinaryOp (getOpcode ()))
854
860
return false ;
855
861
switch (getOpcode ()) {
862
+ case Instruction::ExtractElement:
856
863
case Instruction::ICmp:
857
864
case Instruction::Select:
858
865
case VPInstruction::AnyOf:
859
866
case VPInstruction::CalculateTripCountMinusVF:
860
867
case VPInstruction::CanonicalIVIncrementForPart:
861
868
case VPInstruction::ExtractFromEnd:
862
- case VPInstruction::ExtractFirstActive :
869
+ case VPInstruction::FirstActiveLane :
863
870
case VPInstruction::FirstOrderRecurrenceSplice:
864
871
case VPInstruction::LogicalAnd:
865
872
case VPInstruction::Not:
@@ -970,7 +977,6 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
970
977
case VPInstruction::Broadcast:
971
978
O << " broadcast" ;
972
979
break ;
973
-
974
980
case VPInstruction::ExtractFromEnd:
975
981
O << " extract-from-end" ;
976
982
break ;
@@ -986,8 +992,8 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
986
992
case VPInstruction::AnyOf:
987
993
O << " any-of" ;
988
994
break ;
989
- case VPInstruction::ExtractFirstActive :
990
- O << " extract- first-active" ;
995
+ case VPInstruction::FirstActiveLane :
996
+ O << " first-active-lane " ;
991
997
break ;
992
998
default :
993
999
O << Instruction::getOpcodeName (getOpcode ());
0 commit comments