From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 3E393395B06F; Thu, 17 Nov 2022 08:53:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E393395B06F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668675239; bh=0A8DtPYywqA/ojDMMGL6WOLEBRRnIBEdrmceb+kkD7Q=; h=From:To:Subject:Date:From; b=xvhLbNfAUNDJNXNy6fb+LJ56Aa9zO1ctm6a9ARcNYYhsQDZBdeThPP54DZoWl01zX Ey9+yiPPiZWwN6gp32ITkJ2bBtW8dWdljqlmHRXH0LZaggdya2qFzCsrRiZqsKVeaf lV+T6z0BOseF6c6n+8OGUNi+gf2AP5LKxSH/4vBI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4125] [PR68097] Try to avoid recursing for floats in gimple_stmt_nonnegative_warnv_p. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 156f523f9582f1e6bcce27ece03f2776960408c8 X-Git-Newrev: 822a0823c012b912f0108a4da257cd97cbcdb7a3 Message-Id: <20221117085359.3E393395B06F@sourceware.org> Date: Thu, 17 Nov 2022 08:53:59 +0000 (GMT) List-Id: https://gcc.gnu.org/g:822a0823c012b912f0108a4da257cd97cbcdb7a3 commit r13-4125-g822a0823c012b912f0108a4da257cd97cbcdb7a3 Author: Aldy Hernandez Date: Sat Nov 12 11:58:07 2022 +0100 [PR68097] Try to avoid recursing for floats in gimple_stmt_nonnegative_warnv_p. 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. Diff: --- gcc/gimple-fold.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index f8a1875ea3e..c2d9c806aee 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -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: