[PR68097] Try to avoid recursing for floats in gimple_stmt_nonnegative_warnv_p.
authorAldy Hernandez <aldyh@redhat.com>
Sat, 12 Nov 2022 10:58:07 +0000 (11:58 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 17 Nov 2022 08:53:49 +0000 (09:53 +0100)
It irks me that a PR named "we should track ranges for floating-point
hasn't been closed in this release.  This is an attempt to do just
that.

As mentioned in the PR, even though we track ranges for floats, it has
been suggested that avoiding recursing through SSA defs in
gimple_assign_nonnegative_warnv_p is also a goal.  This patch uses a
global range query (no on-demand lookups, just global ranges and
minimal folding) to determine if the range of a statement is known to
be non-negative.

PR tree-optimization/68097

gcc/ChangeLog:

* gimple-fold.cc (gimple_stmt_nonnegative_warnv_p): Call
range_of_stmt for floats.

gcc/gimple-fold.cc

index f8a1875..c2d9c80 100644 (file)
@@ -68,6 +68,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-strlen.h"
 #include "varasm.h"
 #include "internal-fn.h"
+#include "gimple-range.h"
 
 enum strlen_range_kind {
   /* Compute the exact constant string length.  */
@@ -9234,6 +9235,15 @@ bool
 gimple_stmt_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
                                 int depth)
 {
+  tree type = gimple_range_type (stmt);
+  if (type && frange::supports_p (type))
+    {
+      frange r;
+      bool sign;
+      if (get_global_range_query ()->range_of_stmt (r, stmt)
+         && r.signbit_p (sign))
+       return !sign;
+    }
   switch (gimple_code (stmt))
     {
     case GIMPLE_ASSIGN: