[SCEV] Modernize code style of isSCEVExprNeverPoison [NFC]
authorPhilip Reames <listmail@philipreames.com>
Thu, 30 Sep 2021 22:13:00 +0000 (15:13 -0700)
committerPhilip Reames <listmail@philipreames.com>
Thu, 30 Sep 2021 22:13:43 +0000 (15:13 -0700)
Use for-range and all_of to make code easier to read in advance of other changes.

llvm/lib/Analysis/ScalarEvolution.cpp

index 0eff45db61bc8030e77db5ce07406e26903d922d..5c5ca477fd553a5d9a6543ebd9162305a9928e38 100644 (file)
@@ -6591,26 +6591,22 @@ bool ScalarEvolution::isSCEVExprNeverPoison(const Instruction *I) {
   // We check isLoopInvariant to disambiguate in case we are adding recurrences
   // from different loops, so that we know which loop to prove that I is
   // executed in.
-  for (unsigned OpIndex = 0; OpIndex < I->getNumOperands(); ++OpIndex) {
+  for (const Use &Op : I->operands()) {
     // I could be an extractvalue from a call to an overflow intrinsic.
     // TODO: We can do better here in some cases.
-    if (!isSCEVable(I->getOperand(OpIndex)->getType()))
+    if (!isSCEVable(Op->getType()))
       return false;
-    const SCEV *Op = getSCEV(I->getOperand(OpIndex));
-    if (auto *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
-      bool AllOtherOpsLoopInvariant = true;
-      for (unsigned OtherOpIndex = 0; OtherOpIndex < I->getNumOperands();
-           ++OtherOpIndex) {
-        if (OtherOpIndex != OpIndex) {
-          const SCEV *OtherOp = getSCEV(I->getOperand(OtherOpIndex));
-          if (!isLoopInvariant(OtherOp, AddRec->getLoop())) {
-            AllOtherOpsLoopInvariant = false;
-            break;
-          }
-        }
-      }
+    const SCEV *OpS = getSCEV(Op);
+    if (auto *AddRecS = dyn_cast<SCEVAddRecExpr>(OpS)) {
+      const bool AllOtherOpsLoopInvariant =
+        llvm::all_of(I->operands(), [&](const Use &Op2) -> bool {
+          if (Op.getOperandNo() == Op2.getOperandNo())
+            return true;
+          const SCEV *OtherOp = getSCEV(Op2);
+          return isLoopInvariant(OtherOp, AddRecS->getLoop());
+        });
       if (AllOtherOpsLoopInvariant &&
-          isGuaranteedToExecuteForEveryIteration(I, AddRec->getLoop()))
+          isGuaranteedToExecuteForEveryIteration(I, AddRecS->getLoop()))
         return true;
     }
   }