@@ -599,7 +599,7 @@ class InnerLoopVectorizer {
599
599
600
600
// / Fix a reduction cross-iteration phi. This is the second phase of
601
601
// / vectorizing this phi node.
602
- void fixReduction (PHINode *Phi, VPTransformState &State);
602
+ void fixReduction (VPWidenPHIRecipe *Phi, VPTransformState &State);
603
603
604
604
// / Clear NSW/NUW flags from reduction instructions if necessary.
605
605
void clearReductionWrapFlags (RecurrenceDescriptor &RdxDesc,
@@ -4065,12 +4065,16 @@ void InnerLoopVectorizer::fixCrossIterationPHIs(VPTransformState &State) {
4065
4065
// the currently empty PHI nodes. At this point every instruction in the
4066
4066
// original loop is widened to a vector form so we can use them to construct
4067
4067
// the incoming edges.
4068
- for (PHINode &Phi : OrigLoop->getHeader ()->phis ()) {
4069
- // Handle first-order recurrences and reductions that need to be fixed.
4070
- if (Legal->isFirstOrderRecurrence (&Phi))
4071
- fixFirstOrderRecurrence (&Phi, State);
4072
- else if (Legal->isReductionVariable (&Phi))
4073
- fixReduction (&Phi, State);
4068
+ VPBasicBlock *Header = State.Plan ->getEntry ()->getEntryBasicBlock ();
4069
+ for (VPRecipeBase &R : Header->phis ()) {
4070
+ auto *PhiR = dyn_cast<VPWidenPHIRecipe>(&R);
4071
+ if (!PhiR)
4072
+ continue ;
4073
+ auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue ());
4074
+ if (PhiR->getRecurrenceDescriptor ()) {
4075
+ fixReduction (PhiR, State);
4076
+ } else if (Legal->isFirstOrderRecurrence (OrigPhi))
4077
+ fixFirstOrderRecurrence (OrigPhi, State);
4074
4078
}
4075
4079
}
4076
4080
@@ -4265,17 +4269,19 @@ static bool useOrderedReductions(RecurrenceDescriptor &RdxDesc) {
4265
4269
return EnableStrictReductions && RdxDesc.isOrdered ();
4266
4270
}
4267
4271
4268
- void InnerLoopVectorizer::fixReduction (PHINode *Phi, VPTransformState &State) {
4272
+ void InnerLoopVectorizer::fixReduction (VPWidenPHIRecipe *PhiR,
4273
+ VPTransformState &State) {
4274
+ PHINode *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue ());
4269
4275
// Get it's reduction variable descriptor.
4270
- assert (Legal->isReductionVariable (Phi ) &&
4276
+ assert (Legal->isReductionVariable (OrigPhi ) &&
4271
4277
" Unable to find the reduction variable" );
4272
- RecurrenceDescriptor RdxDesc = Legal-> getReductionVars ()[Phi] ;
4278
+ RecurrenceDescriptor RdxDesc = *PhiR-> getRecurrenceDescriptor () ;
4273
4279
4274
4280
RecurKind RK = RdxDesc.getRecurrenceKind ();
4275
4281
TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue ();
4276
4282
Instruction *LoopExitInst = RdxDesc.getLoopExitInstr ();
4277
4283
setDebugLocFromInst (Builder, ReductionStartValue);
4278
- bool IsInLoopReductionPhi = Cost->isInLoopReduction (Phi );
4284
+ bool IsInLoopReductionPhi = Cost->isInLoopReduction (OrigPhi );
4279
4285
4280
4286
VPValue *LoopExitInstDef = State.Plan ->getVPValue (LoopExitInst);
4281
4287
// This is the vector-clone of the value that leaves the loop.
@@ -4289,7 +4295,7 @@ void InnerLoopVectorizer::fixReduction(PHINode *Phi, VPTransformState &State) {
4289
4295
// Reductions do not have to start at zero. They can start with
4290
4296
// any loop invariant values.
4291
4297
BasicBlock *OrigLatch = OrigLoop->getLoopLatch ();
4292
- Value *OrigLoopVal = Phi ->getIncomingValueForBlock (OrigLatch);
4298
+ Value *OrigLoopVal = OrigPhi ->getIncomingValueForBlock (OrigLatch);
4293
4299
BasicBlock *VectorLoopLatch = LI->getLoopFor (LoopVectorBody)->getLoopLatch ();
4294
4300
4295
4301
bool IsOrdered = State.VF .isVector () && IsInLoopReductionPhi &&
@@ -4298,7 +4304,7 @@ void InnerLoopVectorizer::fixReduction(PHINode *Phi, VPTransformState &State) {
4298
4304
for (unsigned Part = 0 ; Part < UF; ++Part) {
4299
4305
if (IsOrdered && Part > 0 )
4300
4306
break ;
4301
- Value *VecRdxPhi = State.get (State. Plan -> getVPValue (Phi ), Part);
4307
+ Value *VecRdxPhi = State.get (PhiR-> getVPSingleValue ( ), Part);
4302
4308
Value *Val = State.get (State.Plan ->getVPValue (OrigLoopVal), Part);
4303
4309
if (IsOrdered)
4304
4310
Val = State.get (State.Plan ->getVPValue (OrigLoopVal), UF - 1 );
@@ -4313,7 +4319,7 @@ void InnerLoopVectorizer::fixReduction(PHINode *Phi, VPTransformState &State) {
4313
4319
4314
4320
setDebugLocFromInst (Builder, LoopExitInst);
4315
4321
4316
- Type *PhiTy = Phi ->getType ();
4322
+ Type *PhiTy = OrigPhi ->getType ();
4317
4323
// If tail is folded by masking, the vector value to leave the loop should be
4318
4324
// a Select choosing between the vectorized LoopExitInst and vectorized Phi,
4319
4325
// instead of the former. For an inloop reduction the reduction will already
@@ -4342,7 +4348,7 @@ void InnerLoopVectorizer::fixReduction(PHINode *Phi, VPTransformState &State) {
4342
4348
RdxDesc.getOpcode (), PhiTy,
4343
4349
TargetTransformInfo::ReductionFlags ())) {
4344
4350
auto *VecRdxPhi =
4345
- cast<PHINode>(State.get (State. Plan -> getVPValue (Phi ), Part));
4351
+ cast<PHINode>(State.get (PhiR-> getVPSingleValue ( ), Part));
4346
4352
VecRdxPhi->setIncomingValueForBlock (
4347
4353
LI->getLoopFor (LoopVectorBody)->getLoopLatch (), Sel);
4348
4354
}
@@ -4444,12 +4450,12 @@ void InnerLoopVectorizer::fixReduction(PHINode *Phi, VPTransformState &State) {
4444
4450
// Fix the scalar loop reduction variable with the incoming reduction sum
4445
4451
// from the vector body and from the backedge value.
4446
4452
int IncomingEdgeBlockIdx =
4447
- Phi ->getBasicBlockIndex (OrigLoop->getLoopLatch ());
4453
+ OrigPhi ->getBasicBlockIndex (OrigLoop->getLoopLatch ());
4448
4454
assert (IncomingEdgeBlockIdx >= 0 && " Invalid block index" );
4449
4455
// Pick the other block.
4450
4456
int SelfEdgeBlockIdx = (IncomingEdgeBlockIdx ? 0 : 1 );
4451
- Phi ->setIncomingValue (SelfEdgeBlockIdx, BCBlockPhi);
4452
- Phi ->setIncomingValue (IncomingEdgeBlockIdx, LoopExitInst);
4457
+ OrigPhi ->setIncomingValue (SelfEdgeBlockIdx, BCBlockPhi);
4458
+ OrigPhi ->setIncomingValue (IncomingEdgeBlockIdx, LoopExitInst);
4453
4459
}
4454
4460
4455
4461
void InnerLoopVectorizer::clearReductionWrapFlags (RecurrenceDescriptor &RdxDesc,
0 commit comments