Skip to content

Commit 8cfe6aa

Browse files
committed
[VPlan] Optimize reduction-phi if it is constant
1 parent 61b806f commit 8cfe6aa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9682,12 +9682,20 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
96829682
VPBasicBlock *LatchVPBB = VectorLoopRegion->getExitingBasicBlock();
96839683
Builder.setInsertPoint(&*LatchVPBB->begin());
96849684
VPBasicBlock::iterator IP = MiddleVPBB->getFirstNonPhi();
9685-
for (VPRecipeBase &R :
9686-
Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
9685+
for (VPRecipeBase &R : make_early_inc_range(
9686+
Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis())) {
96879687
VPReductionPHIRecipe *PhiR = dyn_cast<VPReductionPHIRecipe>(&R);
96889688
if (!PhiR)
96899689
continue;
96909690

9691+
ScalarEvolution &SE = *PSE.getSE();
9692+
auto *PN = cast<PHINode>(PhiR->getUnderlyingValue());
9693+
if (auto *C = dyn_cast<SCEVConstant>(SE.getSCEV(PN))) {
9694+
VPValue *PV = Plan->getOrAddLiveIn(C->getValue());
9695+
PhiR->replaceAllUsesWith(PV);
9696+
PhiR->eraseFromParent();
9697+
continue;
9698+
}
96919699
const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
96929700
// If tail is folded by masking, introduce selects between the phi
96939701
// and the users outside the vector region of each reduction, at the

0 commit comments

Comments
 (0)