[llvm] [SCEV] Add implied-cond-ge-via-gt test coverage (PR #225024)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 00:35:53 PDT 2026


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/225024

Add test coverage for a very obscure codepath in howManyLT.

>From fc52b62bd7754419dd186070f445507d4f565060 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Fri, 11 Sep 2026 17:13:53 +0100
Subject: [PATCH] [SCEV] Add implied-cond-ge-via-gt test coverage

Add test coverage for a very obscure codepath in howManyLT.

Co-authored-by: Florian Hahn <flo at fhahn.com>
---
 .../implied-cond-ge-via-gt-minus-one.ll       | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 llvm/test/Analysis/ScalarEvolution/implied-cond-ge-via-gt-minus-one.ll

diff --git a/llvm/test/Analysis/ScalarEvolution/implied-cond-ge-via-gt-minus-one.ll b/llvm/test/Analysis/ScalarEvolution/implied-cond-ge-via-gt-minus-one.ll
new file mode 100644
index 00000000000000..349ded886383d0
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/implied-cond-ge-via-gt-minus-one.ll
@@ -0,0 +1,42 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -disable-output -passes="print<scalar-evolution>" \
+; RUN:   -scalar-evolution-classify-expressions=0 %s 2>&1 | FileCheck %s
+
+; Test for proving X >= Y from a guard of the form X > Y - 1.
+
+define i32 @guarded_nested_loop(i32 %start, i32 %rhs, i32 %end) {
+; CHECK-LABEL: 'guarded_nested_loop'
+; CHECK-NEXT:  Determining loop execution counts for: @guarded_nested_loop
+; CHECK-NEXT:  Loop %inner: backedge-taken count is ({(1 + (-1 * %start) + %rhs),+,-1}<%outer> /u 2)
+; CHECK-NEXT:  Loop %inner: constant max backedge-taken count is i32 2147483647
+; CHECK-NEXT:  Loop %inner: symbolic max backedge-taken count is ({(1 + (-1 * %start) + %rhs),+,-1}<%outer> /u 2)
+; CHECK-NEXT:  Loop %inner: Trip multiple is 1
+; CHECK-NEXT:  Loop %outer: backedge-taken count is (-1 + (-1 * %start) + %end)
+; CHECK-NEXT:  Loop %outer: constant max backedge-taken count is i32 -1
+; CHECK-NEXT:  Loop %outer: symbolic max backedge-taken count is (-1 + (-1 * %start) + %end)
+; CHECK-NEXT:  Loop %outer: Trip multiple is 1
+;
+entry:
+  br label %outer
+
+outer:
+  %outer.iv = phi i32 [ %start, %entry ], [ %outer.iv.next, %outer.latch ]
+  %before = sub i32 %outer.iv, 1
+  %guard = icmp ugt i32 %rhs, %before
+  br i1 %guard, label %inner, label %outer.latch
+
+inner:
+  %iv = phi i32 [ %outer.iv, %outer ], [ %iv.next, %inner ]
+  %iv.next = add nuw i32 %iv, 2
+  %ec = icmp ult i32 %iv, %rhs
+  br i1 %ec, label %inner, label %outer.latch
+
+outer.latch:
+  %res = phi i32 [ %outer.iv, %outer ], [ %iv, %inner ]
+  %outer.iv.next = add i32 %outer.iv, 1
+  %ec.outer = icmp ne i32 %outer.iv.next, %end
+  br i1 %ec.outer, label %outer, label %exit
+
+exit:
+  ret i32 %res
+}



More information about the llvm-commits mailing list