[llvm] change contents of ScalarEvolution from private to protected (PR #83052)

Joshua Ferguson via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 20 14:23:24 PDT 2024


================
@@ -9184,18 +9247,37 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
     if (EL.hasAnyInfo()) return EL;
     break;
   }
+
   case ICmpInst::ICMP_SLE:
   case ICmpInst::ICMP_ULE:
-    // Since the loop is finite, an invariant RHS cannot include the boundary
-    // value, otherwise it would loop forever.
-    if (!EnableFiniteLoopControl || !ControllingFiniteLoop ||
-        !isLoopInvariant(RHS, L))
-      break;
-    RHS = getAddExpr(getOne(RHS->getType()), RHS);
+    if (!AssumeLoopExits) {
+      // Since the loop is finite, an invariant RHS cannot include the boundary
+      // value, otherwise it would loop forever.
+      if (!EnableFiniteLoopControl || !ControllingFiniteLoop ||
+          !isLoopInvariant(RHS, L))
+        break;
+      RHS = getAddExpr(getOne(RHS->getType()), RHS);
+    }
     [[fallthrough]];
+
   case ICmpInst::ICMP_SLT:
   case ICmpInst::ICMP_ULT: { // while (X < Y)
     bool IsSigned = ICmpInst::isSigned(Pred);
+    if (AssumeLoopExits) {
+      if (Pred == ICmpInst::ICMP_SLE || Pred == ICmpInst::ICMP_ULE) {
+        if (!isa<IntegerType>(RHS->getType()))
+          break;
+        SmallVector<const SCEV *, 2> sv = {
+            RHS, getConstant(
+                     ConstantInt::get(cast<IntegerType>(RHS->getType()), 1))};
+        // Since this is not an infinite loop by induction, RHS cannot be
+        // int_max/uint_max Therefore adding 1 does not wrap.
+        if (IsSigned)
+          RHS = getAddExpr(sv, SCEV::FlagNSW);
+        else
+          RHS = getAddExpr(sv, SCEV::FlagNUW);
+      }
+    }
----------------
skewballfox wrote:

removed this section

https://github.com/llvm/llvm-project/pull/83052


More information about the llvm-commits mailing list