]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix off by one in range_from_loop_direction.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 30 Sep 2025 19:59:38 +0000 (15:59 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Wed, 1 Oct 2025 14:24:37 +0000 (10:24 -0400)
When bounds_of_var_in_loop was converted to range_from_loop_direction,
the final check returned FALSE when the beginning and end bounds were
the same...  The new code was using wi::gt_p, when it should have been
wi::ge_p when checking for the fail condition.

PR tree-optimization/120560
gcc/
* vr-values.cc (range_from_loop_direction): Use wi::ge_p rather
than wi::gt_p.

gcc/testsuite/
* gcc.dg/pr120560.c: New.

gcc/testsuite/gcc.dg/pr120560.c [new file with mode: 0644]
gcc/vr-values.cc

diff --git a/gcc/testsuite/gcc.dg/pr120560.c b/gcc/testsuite/gcc.dg/pr120560.c
new file mode 100644 (file)
index 0000000..deb3c18
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-tree-ccp -fdump-tree-evrp" } */
+int main() {
+  int a = -1, b = 2, c = 1;
+  if (a >= 0)
+    c = 0;
+  while (1) {
+    if (-b + c - 7 >= 0)
+      return 0;
+    b = b - 1000 - 2147482648;
+  }
+}
+/* { dg-final { scan-tree-dump "return 0"  "evrp" } } */
index ff11656559bfffc44caf304aa54cb26008ec5700..44dff35bcf292556bf799fc014dd70cb69762ba0 100644 (file)
@@ -278,14 +278,14 @@ range_from_loop_direction (irange &r, tree type,
     r.set_varying (type);
   else if (dir == EV_DIR_GROWS)
     {
-      if (wi::gt_p (begin.lower_bound (), end.upper_bound (), sign))
+      if (wi::ge_p (begin.lower_bound (), end.upper_bound (), sign))
        r.set_varying (type);
       else
        r = int_range<1> (type, begin.lower_bound (), end.upper_bound ());
     }
   else
     {
-      if (wi::gt_p (end.lower_bound (), begin.upper_bound (), sign))
+      if (wi::ge_p (end.lower_bound (), begin.upper_bound (), sign))
        r.set_varying (type);
       else
        r = int_range<1> (type, end.lower_bound (), begin.upper_bound ());