@@ -277,6 +277,12 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
277277 llvm_unreachable (" subclasses should implement computeCost" );
278278}
279279
280+ bool VPRecipeBase::isPhi () const {
281+ return (getVPDefID () >= VPFirstPHISC && getVPDefID () <= VPLastPHISC) ||
282+ (isa<VPInstruction>(this ) &&
283+ cast<VPInstruction>(this )->getOpcode () == Instruction::PHI);
284+ }
285+
280286InstructionCost
281287VPPartialReductionRecipe::computeCost (ElementCount VF,
282288 VPCostContext &Ctx) const {
@@ -418,6 +424,7 @@ bool VPInstruction::canGenerateScalarForFirstLane() const {
418424 return true ;
419425 switch (Opcode) {
420426 case Instruction::ICmp:
427+ case Instruction::PHI:
421428 case Instruction::Select:
422429 case VPInstruction::BranchOnCond:
423430 case VPInstruction::BranchOnCount:
@@ -467,6 +474,17 @@ Value *VPInstruction::generate(VPTransformState &State) {
467474 Value *B = State.get (getOperand (1 ), OnlyFirstLaneUsed);
468475 return Builder.CreateCmp (getPredicate (), A, B, Name);
469476 }
477+ case Instruction::PHI: {
478+ assert (getParent () ==
479+ getParent ()->getPlan ()->getVectorLoopRegion ()->getEntry () &&
480+ " VPInstructions with PHI opcodes must be used for header phis only "
481+ " at the moment" );
482+ BasicBlock *VectorPH = State.CFG .getPreheaderBBFor (this );
483+ Value *Start = State.get (getOperand (0 ), VPLane (0 ));
484+ PHINode *Phi = State.Builder .CreatePHI (Start->getType (), 2 , Name);
485+ Phi->addIncoming (Start, VectorPH);
486+ return Phi;
487+ }
470488 case Instruction::Select: {
471489 bool OnlyFirstLaneUsed = vputils::onlyFirstLaneUsed (this );
472490 Value *Cond = State.get (getOperand (0 ), OnlyFirstLaneUsed);
@@ -771,7 +789,8 @@ bool VPInstruction::isVectorToScalar() const {
771789}
772790
773791bool VPInstruction::isSingleScalar () const {
774- return getOpcode () == VPInstruction::ResumePhi;
792+ return getOpcode () == VPInstruction::ResumePhi ||
793+ getOpcode () == Instruction::PHI;
775794}
776795
777796#if !defined(NDEBUG)
@@ -849,6 +868,8 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
849868 switch (getOpcode ()) {
850869 default :
851870 return false ;
871+ case Instruction::PHI:
872+ return true ;
852873 case Instruction::ICmp:
853874 case Instruction::Select:
854875 case Instruction::Or:
@@ -3292,11 +3313,12 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
32923313 BasicBlock *VectorPH = State.CFG .getPreheaderBBFor (this );
32933314 PHINode *NewPointerPhi = nullptr ;
32943315 if (CurrentPart == 0 ) {
3295- auto *IVR = cast<VPHeaderPHIRecipe>(&getParent ()
3296- ->getPlan ()
3297- ->getVectorLoopRegion ()
3298- ->getEntryBasicBlock ()
3299- ->front ());
3316+ auto *IVR = getParent ()
3317+ ->getPlan ()
3318+ ->getVectorLoopRegion ()
3319+ ->getEntryBasicBlock ()
3320+ ->front ()
3321+ .getVPSingleValue ();
33003322 PHINode *CanonicalIV = cast<PHINode>(State.get (IVR, /* IsScalar*/ true ));
33013323 NewPointerPhi = PHINode::Create (ScStValueType, 2 , " pointer.phi" ,
33023324 CanonicalIV->getIterator ());
@@ -3665,22 +3687,3 @@ void VPEVLBasedIVPHIRecipe::print(raw_ostream &O, const Twine &Indent,
36653687 printOperands (O, SlotTracker);
36663688}
36673689#endif
3668-
3669- void VPScalarPHIRecipe::execute (VPTransformState &State) {
3670- BasicBlock *VectorPH = State.CFG .getPreheaderBBFor (this );
3671- Value *Start = State.get (getStartValue (), VPLane (0 ));
3672- PHINode *Phi = State.Builder .CreatePHI (Start->getType (), 2 , Name);
3673- Phi->addIncoming (Start, VectorPH);
3674- Phi->setDebugLoc (getDebugLoc ());
3675- State.set (this , Phi, /* IsScalar=*/ true );
3676- }
3677-
3678- #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3679- void VPScalarPHIRecipe::print (raw_ostream &O, const Twine &Indent,
3680- VPSlotTracker &SlotTracker) const {
3681- O << Indent << " SCALAR-PHI " ;
3682- printAsOperand (O, SlotTracker);
3683- O << " = phi " ;
3684- printOperands (O, SlotTracker);
3685- }
3686- #endif
0 commit comments