@@ -277,6 +277,11 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
277277 VPCostContext &Ctx) const {
278278 llvm_unreachable (" subclasses should implement computeCost" );
279279}
280+ bool VPRecipeBase::isPhi () const {
281+ return (getVPDefID () >= VPFirstPHISC && getVPDefID () <= VPLastPHISC) ||
282+ (isa<VPInstruction>(this ) &&
283+ cast<VPInstruction>(this )->getOpcode () == Instruction::PHI);
284+ }
280285
281286InstructionCost
282287VPPartialReductionRecipe::computeCost (ElementCount VF,
@@ -418,6 +423,7 @@ bool VPInstruction::canGenerateScalarForFirstLane() const {
418423 if (isSingleScalar () || isVectorToScalar ())
419424 return true ;
420425 switch (Opcode) {
426+ case Instruction::PHI:
421427 case Instruction::ICmp:
422428 case Instruction::Select:
423429 case VPInstruction::BranchOnCond:
@@ -458,6 +464,13 @@ Value *VPInstruction::generate(VPTransformState &State) {
458464 }
459465
460466 switch (getOpcode ()) {
467+ case Instruction::PHI: {
468+ BasicBlock *VectorPH = State.CFG .getPreheaderBBFor (this );
469+ Value *Start = State.get (getOperand (0 ), VPLane (0 ));
470+ PHINode *Phi = State.Builder .CreatePHI (Start->getType (), 2 , Name);
471+ Phi->addIncoming (Start, VectorPH);
472+ return Phi;
473+ }
461474 case VPInstruction::Not: {
462475 Value *A = State.get (getOperand (0 ));
463476 return Builder.CreateNot (A, Name);
@@ -838,6 +851,8 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
838851 switch (getOpcode ()) {
839852 default :
840853 return false ;
854+ case Instruction::PHI:
855+ return true ;
841856 case Instruction::ICmp:
842857 case Instruction::Select:
843858 case Instruction::Or:
@@ -3283,11 +3298,12 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
32833298 BasicBlock *VectorPH = State.CFG .getPreheaderBBFor (this );
32843299 PHINode *NewPointerPhi = nullptr ;
32853300 if (CurrentPart == 0 ) {
3286- auto *IVR = cast<VPHeaderPHIRecipe>(&getParent ()
3287- ->getPlan ()
3288- ->getVectorLoopRegion ()
3289- ->getEntryBasicBlock ()
3290- ->front ());
3301+ auto *IVR = getParent ()
3302+ ->getPlan ()
3303+ ->getVectorLoopRegion ()
3304+ ->getEntryBasicBlock ()
3305+ ->front ()
3306+ .getVPSingleValue ();
32913307 PHINode *CanonicalIV = cast<PHINode>(State.get (IVR, /* IsScalar*/ true ));
32923308 NewPointerPhi = PHINode::Create (ScStValueType, 2 , " pointer.phi" ,
32933309 CanonicalIV->getIterator ());
@@ -3666,22 +3682,3 @@ void VPEVLBasedIVPHIRecipe::print(raw_ostream &O, const Twine &Indent,
36663682 printOperands (O, SlotTracker);
36673683}
36683684#endif
3669-
3670- void VPScalarPHIRecipe::execute (VPTransformState &State) {
3671- BasicBlock *VectorPH = State.CFG .getPreheaderBBFor (this );
3672- Value *Start = State.get (getStartValue (), VPLane (0 ));
3673- PHINode *Phi = State.Builder .CreatePHI (Start->getType (), 2 , Name);
3674- Phi->addIncoming (Start, VectorPH);
3675- Phi->setDebugLoc (getDebugLoc ());
3676- State.set (this , Phi, /* IsScalar=*/ true );
3677- }
3678-
3679- #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3680- void VPScalarPHIRecipe::print (raw_ostream &O, const Twine &Indent,
3681- VPSlotTracker &SlotTracker) const {
3682- O << Indent << " SCALAR-PHI " ;
3683- printAsOperand (O, SlotTracker);
3684- O << " = phi " ;
3685- printOperands (O, SlotTracker);
3686- }
3687- #endif
0 commit comments