From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id BEEE33858C62; Fri, 14 Oct 2022 16:43:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEEE33858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665765795; bh=G95szdeaamlXoUXpq26DzMFkttx/CeN3StIlpMO2r3k=; h=From:To:Subject:Date:From; b=oxyRyEbpkUnrW4n/v6ggMaU0cEupILz4RhLZfGiRAG1r4s+OwY0HIlAfOLFoyCZv1 pS1qeSOtf8AF59Vxnd8r8p9VTWuJvsP5FpM0H5APZK1/QgM3qEX7IOn+q8QvNhOrNA DSOpQ4uid6XzzlK+llVVTcJjcfrLViVr1hjeJ0v4= 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-3307] Implement range-op entry for __builtin_copysign. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 3760dd553eed21ac5614cf0d0841ca984b4361e2 X-Git-Newrev: 8efc38347a7444dde3fb173f0f2c59a60b7db53d Message-Id: <20221014164315.BEEE33858C62@sourceware.org> Date: Fri, 14 Oct 2022 16:43:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8efc38347a7444dde3fb173f0f2c59a60b7db53d commit r13-3307-g8efc38347a7444dde3fb173f0f2c59a60b7db53d Author: Aldy Hernandez Date: Thu Oct 13 17:51:29 2022 +0200 Implement range-op entry for __builtin_copysign. copysign(MAGNITUDE, SIGN) is implemented as the absolute of MAGNITUDE, with SIGN applied. If the sign of "SIGN" cannot be determined, we return a range of [-MAGNITUDE, +MAGNITUDE]. gcc/ChangeLog: * gimple-range-op.cc (class cfn_copysign): New. (gimple_range_op_handler::maybe_builtin_call): Add CFN_BUILT_IN_COPYSIGN*. Diff: --- gcc/gimple-range-op.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 527893f66af..2662319aadc 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -342,6 +342,38 @@ public: } } op_cfn_signbit; +// Implement range operator for CFN_BUILT_IN_COPYSIGN +class cfn_copysign : public range_operator_float +{ +public: + using range_operator_float::fold_range; + virtual bool fold_range (frange &r, tree type, const frange &lh, + const frange &rh, relation_kind) const override + { + frange neg; + range_op_handler abs_op (ABS_EXPR, type); + range_op_handler neg_op (NEGATE_EXPR, type); + if (!abs_op || !abs_op.fold_range (r, type, lh, frange (type))) + return false; + if (!neg_op || !neg_op.fold_range (neg, type, r, frange (type))) + return false; + + bool signbit; + if (rh.signbit_p (signbit)) + { + // If the sign is negative, flip the result from ABS, + // otherwise leave things positive. + if (signbit) + r = neg; + } + else + // If the sign is unknown, keep the positive and negative + // alternatives. + r.union_ (neg); + return true; + } +} op_cfn_copysign; + // Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. class cfn_toupper_tolower : public range_operator { @@ -762,6 +794,13 @@ gimple_range_op_handler::maybe_builtin_call () m_valid = true; break; + CASE_CFN_COPYSIGN_ALL: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_float = &op_cfn_copysign; + m_valid = true; + break; + case CFN_BUILT_IN_TOUPPER: case CFN_BUILT_IN_TOLOWER: // Only proceed If the argument is compatible with the LHS.