[llvm] c5e491e - [SCEV] Modernize code style of isSCEVExprNeverPoison [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 15:13:54 PDT 2021


Author: Philip Reames
Date: 2021-09-30T15:13:43-07:00
New Revision: c5e491e6ee95ac0243b38b4aa85b627e7d9fc969

URL: https://github.com/llvm/llvm-project/commit/c5e491e6ee95ac0243b38b4aa85b627e7d9fc969
DIFF: https://github.com/llvm/llvm-project/commit/c5e491e6ee95ac0243b38b4aa85b627e7d9fc969.diff

LOG: [SCEV] Modernize code style of isSCEVExprNeverPoison [NFC]

Use for-range and all_of to make code easier to read in advance of other changes.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 0eff45db61bc..5c5ca477fd55 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6591,26 +6591,22 @@ bool ScalarEvolution::isSCEVExprNeverPoison(const Instruction *I) {
   // We check isLoopInvariant to disambiguate in case we are adding recurrences
   // from 
diff erent 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;
     }
   }


        


More information about the llvm-commits mailing list