From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id 9DD983858D3C; Fri, 9 Jun 2023 16:37:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DD983858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686328656; bh=jncEag51kKOfxDf17i3xnsZxQttxsCKai++2k6xS+5A=; h=From:To:Subject:Date:From; b=QQuu5paIVxQzmEufxgsN9XjYHzh1f2OjdOooP7R0gSJ4BQ2JUoMP77P2G1PbqrIVc zXZu5UkIE+gHhsss93tMhBYMTdzoZRUP4ohUzVXN5JOdCD4HDUoudYg3+6p829zWuG NwdLEdZehGu5FDemTzK4qUJTt51D7ooFMh7urfKU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Macleod To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1661] Relocate range_cast to header, and add a generic version. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/master X-Git-Oldrev: 953bbeaeff050f4d0b670568a587aa1ce82ed711 X-Git-Newrev: c570818b436fde04bbb86755601c741711fd72a0 Message-Id: <20230609163736.9DD983858D3C@sourceware.org> Date: Fri, 9 Jun 2023 16:37:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c570818b436fde04bbb86755601c741711fd72a0 commit r14-1661-gc570818b436fde04bbb86755601c741711fd72a0 Author: Andrew MacLeod Date: Wed May 31 17:02:00 2023 -0400 Relocate range_cast to header, and add a generic version. Make range_cast inlinable by moving it to the header file. Also trap if the destination is not capable of representing the cast type. Add a generic version which can change range classes.. ie float to int. * range-op.cc (range_cast): Move to... * range-op.h (range_cast): Here and add generic a version. Diff: --- gcc/range-op.cc | 18 ------------------ gcc/range-op.h | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 4d122de3026..44a95b20ffa 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4929,24 +4929,6 @@ pointer_table::pointer_table () set (BIT_XOR_EXPR, op_bitwise_xor); } -// Cast the range in R to TYPE. - -bool -range_cast (vrange &r, tree type) -{ - Value_Range tmp (r); - Value_Range varying (type); - varying.set_varying (type); - range_op_handler op (CONVERT_EXPR, type); - // Call op_convert, if it fails, the result is varying. - if (!op || !op.fold_range (r, type, tmp, varying)) - { - r.set_varying (type); - return false; - } - return true; -} - #if CHECKING_P #include "selftest.h" diff --git a/gcc/range-op.h b/gcc/range-op.h index 7af58736c3f..2abec3299ef 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -216,7 +216,49 @@ protected: range_operator *m_operator; }; -extern bool range_cast (vrange &, tree type); +// Cast the range in R to TYPE if R supports TYPE. + +inline bool +range_cast (vrange &r, tree type) +{ + gcc_checking_assert (r.supports_type_p (type)); + Value_Range tmp (r); + Value_Range varying (type); + varying.set_varying (type); + range_op_handler op (CONVERT_EXPR, type); + // Call op_convert, if it fails, the result is varying. + if (!op || !op.fold_range (r, type, tmp, varying)) + { + r.set_varying (type); + return false; + } + return true; +} + +// Range cast which is capable of switching range kinds. +// ie for float to int. + +inline bool +range_cast (Value_Range &r, tree type) +{ + Value_Range tmp (r); + Value_Range varying (type); + varying.set_varying (type); + + // Ensure we are in the correct mode for the call to fold. + r.set_type (type); + + range_op_handler op (CONVERT_EXPR, type); + // Call op_convert, if it fails, the result is varying. + if (!op || !op.fold_range (r, type, tmp, varying)) + { + r.set_varying (type); + return false; + } + return true; +} + + extern void wi_set_zero_nonzero_bits (tree type, const wide_int &, const wide_int &, wide_int &maybe_nonzero,