@@ -475,6 +475,7 @@ unsigned VPInstruction::getNumOperandsForOpcode(unsigned Opcode) {
475475 case VPInstruction::FirstOrderRecurrenceSplice:
476476 case VPInstruction::LogicalAnd:
477477 case VPInstruction::PtrAdd:
478+ case VPInstruction::WidePtrAdd:
478479 case VPInstruction::WideIVStep:
479480 return 2 ;
480481 case Instruction::Select:
@@ -494,9 +495,8 @@ unsigned VPInstruction::getNumOperandsForOpcode(unsigned Opcode) {
494495}
495496#endif
496497
497- bool VPInstruction::doesGeneratePerAllLanes (VPTransformState &State) const {
498- return Opcode == VPInstruction::PtrAdd && !vputils::onlyFirstLaneUsed (this ) &&
499- !State.hasVectorValue (getOperand (1 ));
498+ bool VPInstruction::doesGeneratePerAllLanes () const {
499+ return Opcode == VPInstruction::PtrAdd && !vputils::onlyFirstLaneUsed (this );
500500}
501501
502502bool VPInstruction::canGenerateScalarForFirstLane () const {
@@ -514,6 +514,7 @@ bool VPInstruction::canGenerateScalarForFirstLane() const {
514514 case VPInstruction::CalculateTripCountMinusVF:
515515 case VPInstruction::CanonicalIVIncrementForPart:
516516 case VPInstruction::PtrAdd:
517+ case VPInstruction::WidePtrAdd:
517518 case VPInstruction::ExplicitVectorLength:
518519 case VPInstruction::AnyOf:
519520 return true ;
@@ -849,7 +850,14 @@ Value *VPInstruction::generate(VPTransformState &State) {
849850 return Builder.CreateLogicalAnd (A, B, Name);
850851 }
851852 case VPInstruction::PtrAdd: {
853+ assert (vputils::onlyFirstLaneUsed (this ) &&
854+ " can only generate first lane for PtrAdd" );
852855 Value *Ptr = State.get (getOperand (0 ), VPLane (0 ));
856+ Value *Addend = State.get (getOperand (1 ), VPLane (0 ));
857+ return Builder.CreatePtrAdd (Ptr, Addend, Name, getGEPNoWrapFlags ());
858+ }
859+ case VPInstruction::WidePtrAdd: {
860+ Value *Ptr = State.get (getOperand (0 ), true );
853861 Value *Addend = State.get (getOperand (1 ), vputils::onlyFirstLaneUsed (this ));
854862 return Builder.CreatePtrAdd (Ptr, Addend, Name, getGEPNoWrapFlags ());
855863 }
@@ -910,6 +918,9 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
910918 }
911919 }
912920
921+ assert (!doesGeneratePerAllLanes () &&
922+ " Should only generate a vector value or single scalar, not scalars "
923+ " for all lanes." );
913924 return Ctx.TTI .getArithmeticInstrCost (getOpcode (), ResTy, Ctx.CostKind );
914925 }
915926
@@ -997,7 +1008,7 @@ void VPInstruction::execute(VPTransformState &State) {
9971008 bool GeneratesPerFirstLaneOnly = canGenerateScalarForFirstLane () &&
9981009 (vputils::onlyFirstLaneUsed (this ) ||
9991010 isVectorToScalar () || isSingleScalar ());
1000- bool GeneratesPerAllLanes = doesGeneratePerAllLanes (State );
1011+ bool GeneratesPerAllLanes = doesGeneratePerAllLanes ();
10011012 if (GeneratesPerAllLanes) {
10021013 for (unsigned Lane = 0 , NumLanes = State.VF .getFixedValue ();
10031014 Lane != NumLanes; ++Lane) {
@@ -1041,6 +1052,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
10411052 case VPInstruction::LogicalAnd:
10421053 case VPInstruction::Not:
10431054 case VPInstruction::PtrAdd:
1055+ case VPInstruction::WidePtrAdd:
10441056 case VPInstruction::WideIVStep:
10451057 case VPInstruction::StepVector:
10461058 case VPInstruction::ReductionStartVector:
@@ -1078,6 +1090,7 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
10781090 case VPInstruction::ReductionStartVector:
10791091 return true ;
10801092 case VPInstruction::PtrAdd:
1093+ case VPInstruction::WidePtrAdd:
10811094 return Op == getOperand (0 ) || vputils::onlyFirstLaneUsed (this );
10821095 case VPInstruction::ComputeAnyOfResult:
10831096 case VPInstruction::ComputeFindIVResult:
@@ -1181,6 +1194,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
11811194 case VPInstruction::PtrAdd:
11821195 O << " ptradd" ;
11831196 break ;
1197+ case VPInstruction::WidePtrAdd:
1198+ O << " wide-ptradd" ;
1199+ break ;
11841200 case VPInstruction::AnyOf:
11851201 O << " any-of" ;
11861202 break ;
@@ -1765,7 +1781,8 @@ bool VPIRFlags::flagsValidForOpcode(unsigned Opcode) const {
17651781 return Opcode == Instruction::AShr;
17661782 case OperationType::GEPOp:
17671783 return Opcode == Instruction::GetElementPtr ||
1768- Opcode == VPInstruction::PtrAdd;
1784+ Opcode == VPInstruction::PtrAdd ||
1785+ Opcode == VPInstruction::WidePtrAdd;
17691786 case OperationType::FPMathOp:
17701787 return Opcode == Instruction::FAdd || Opcode == Instruction::FMul ||
17711788 Opcode == Instruction::FSub || Opcode == Instruction::FNeg ||
0 commit comments