[LoopFlatten] Use Loop to identify loop induction phi. NFC
authorRosie Sumpter <rosie.sumpter@arm.com>
Thu, 15 Jul 2021 07:51:30 +0000 (08:51 +0100)
committerRosie Sumpter <rosie.sumpter@arm.com>
Mon, 19 Jul 2021 08:06:57 +0000 (09:06 +0100)
Replace code which identifies induction phi with helper function
getInductionVariable to improve robustness.

Differential Revision: https://reviews.llvm.org/D106045

llvm/lib/Transforms/Scalar/LoopFlatten.cpp

index 37bfff4ba67f6080a4f127b2d5702e5641681659..1cad134876a406830c7b58d5c9a8714728b2e68d 100644 (file)
@@ -124,19 +124,12 @@ static bool findLoopComponents(
   // Find the induction PHI. If there is no induction PHI, we can't do the
   // transformation. TODO: could other variables trigger this? Do we have to
   // search for the best one?
-  InductionPHI = nullptr;
-  for (PHINode &PHI : L->getHeader()->phis()) {
-    InductionDescriptor ID;
-    if (InductionDescriptor::isInductionPHI(&PHI, L, SE, ID)) {
-      InductionPHI = &PHI;
-      LLVM_DEBUG(dbgs() << "Found induction PHI: "; InductionPHI->dump());
-      break;
-    }
-  }
+  InductionPHI = L->getInductionVariable(*SE);
   if (!InductionPHI) {
     LLVM_DEBUG(dbgs() << "Could not find induction PHI\n");
     return false;
   }
+  LLVM_DEBUG(dbgs() << "Found induction PHI: "; InductionPHI->dump());
 
   auto IsValidPredicate = [&](ICmpInst::Predicate Pred) {
     if (ContinueOnTrue)