[LV] Clean up uniform induction variable analysis (NFC)

llvm-svn: 281368
This commit is contained in:
Matthew Simpson 2016-09-13 19:01:45 +00:00
parent 88f5ed9430
commit 81335bec96
1 changed files with 31 additions and 23 deletions

View File

@ -5434,29 +5434,37 @@ void LoopVectorizationLegality::collectLoopUniforms() {
} }
// For an instruction to be added into Worklist above, all its users inside // For an instruction to be added into Worklist above, all its users inside
// the current loop should be already added into Worklist. This condition // the loop should also be in Worklist. However, this condition cannot be
// cannot be true for phi instructions which is always in a dependence loop. // true for phi nodes that form a cyclic dependence. We must process phi
// Because any instruction in the dependence cycle always depends on others // nodes separately. An induction variable will remain uniform if all users
// in the cycle to be added into Worklist first, the result is no ones in // of the induction variable and induction variable update remain uniform.
// the cycle will be added into Worklist in the end. for (auto &Induction : Inductions) {
// That is why we process PHI separately. auto *Ind = Induction.first;
for (auto &Induction : *getInductionVars()) { auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch));
auto *PN = Induction.first;
auto *UpdateV = PN->getIncomingValueForBlock(TheLoop->getLoopLatch()); // Determine if all users of the induction variable are uniform after
if (all_of(PN->users(), // vectorization.
[&](User *U) -> bool { auto UniformInd = all_of(Ind->users(), [&](User *U) -> bool {
return U == UpdateV || isOutOfScope(U) || auto *I = cast<Instruction>(U);
Worklist.count(cast<Instruction>(U)); return I == IndUpdate || !TheLoop->contains(I) || Worklist.count(I);
}) && });
all_of(UpdateV->users(), [&](User *U) -> bool { if (!UniformInd)
return U == PN || isOutOfScope(U) || continue;
Worklist.count(cast<Instruction>(U));
})) { // Determine if all users of the induction variable update instruction are
Worklist.insert(cast<Instruction>(PN)); // uniform after vectorization.
Worklist.insert(cast<Instruction>(UpdateV)); auto UniformIndUpdate = all_of(IndUpdate->users(), [&](User *U) -> bool {
DEBUG(dbgs() << "LV: Found uniform instruction: " << *PN << "\n"); auto *I = cast<Instruction>(U);
DEBUG(dbgs() << "LV: Found uniform instruction: " << *UpdateV << "\n"); return I == Ind || !TheLoop->contains(I) || Worklist.count(I);
} });
if (!UniformIndUpdate)
continue;
// The induction variable and its update instruction will remain uniform.
Worklist.insert(Ind);
Worklist.insert(IndUpdate);
DEBUG(dbgs() << "LV: Found uniform instruction: " << *Ind << "\n");
DEBUG(dbgs() << "LV: Found uniform instruction: " << *IndUpdate << "\n");
} }
Uniforms.insert(Worklist.begin(), Worklist.end()); Uniforms.insert(Worklist.begin(), Worklist.end());