[llvm-branch-commits] [llvm] [SCEV] Prove monotonic predicates from loop entry in isKnownViaInduction (PR #231697)

Max Kazantsev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Oct 20 10:52:33 PDT 2026


================
@@ -1649,6 +1655,85 @@ TEST_F(ScalarEvolutionsTest, ImpliedNonNegativeFromULT) {
   });
 }
 
+// A predicate that can only change from false to true as the loop iterates
+// holds on every iteration if it holds on loop entry.
+TEST_F(ScalarEvolutionsTest, KnownOnEveryIterationMonotonic) {
+  LLVMContext C;
+  SMDiagnostic Err;
+  std::unique_ptr<Module> M = parseAssemblyString(
+      "define void @nsw(i32 %s, i32 %n, i32 %inv) { "
+      "entry: "
+      "  %g = icmp sge i32 %s, 0 "
+      "  br i1 %g, label %loop, label %exit "
+      "loop: "
+      "  %iv = phi i32 [ %s, %entry ], [ %iv.next, %loop ] "
+      "  %iv.next = add nsw i32 %iv, 1 "
+      "  %var = add i32 %inv, %iv "
+      "  %ec = icmp slt i32 %iv.next, %n "
+      "  br i1 %ec, label %loop, label %exit "
+      "exit: "
+      "  ret void "
+      "} "
+      "define void @nest(i32 %s, i32 %n) { "
----------------
xortator wrote:

Does this unit test really need to have 2 functions?

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


More information about the llvm-branch-commits mailing list