From patchwork Sat Jun 10 00:36:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1793265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RQTnUaxy; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QdJx46M9pz20Vx for ; Sat, 10 Jun 2023 10:39:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA21138983A9 for ; Sat, 10 Jun 2023 00:39:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA21138983A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686357558; bh=cRadtxGzEz45BR1HV29dA8LJ24SVuIsmkUNOzOnKY9Y=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=RQTnUaxyLSXQ8XNp+IDXD/y0NnWWpXygw/JcTv9ygOO8igdKKPqoUiOdggwH3OuxW S+hyC0QnKtxclxhXTo5ay8F+CCM8GvaaVmmF3T3bopO3SZiokfuTS//BKJb42oLsOq 5adYCzIXC0uE5VMkpy+7wdgyOt5Xj+NHumIzKBxY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7480E38319C7 for ; Sat, 10 Jun 2023 00:36:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7480E38319C7 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-210-n5Tf_lnRMsCHhKY-v7pTOQ-1; Fri, 09 Jun 2023 20:36:05 -0400 X-MC-Unique: n5Tf_lnRMsCHhKY-v7pTOQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6260cd5068cso27976846d6.2 for ; Fri, 09 Jun 2023 17:36:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686357364; x=1688949364; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yRumLaWvCEcsUlcRfsA7UREiNGXJ3CyCeAhlOn7swzs=; b=dxWEOC+7dy1qxvmOjAByFFCDhldwyDV+4X0lcdih0LocFSoMthBsVYFP21emtsdu27 FRLxldUU9v5jQ+yhl6Za+nYmO7sJggPUvuyAEg55aSR6lcg9Dd+2m5KhYxT0aXtab5XF ODNP6xnnts3W4Y9YgKk01nTP2LtHnXFRF1u1LeZh0V8nKkQqvPwnoT4OIRGIl5Kq66zr XT5b7po83VuIRMwl2hD2wW8cqW4UfrgH4FeJYAveUKGxAhIaYX286Ke480oZ6dnCujgq c1I6LxU+vkwSV1uE75kTWORUgx56V/KEwFyc2RL8JzsyZ8J53Pym8cGFVvIFY0PDanXD t7tA== X-Gm-Message-State: AC+VfDwzl3qhJaDlny9i6y6U3b3FjxFOTHbJ1KicJkUkqG98H7IjFsev o4Fg9Sp9AtmohcnVl9JeiLAHHJIgDeI8qYnEO6iG8bAX6TpCQjnRnY4Dnia5kZbiWWrtD+q44sA kAhXCdbzg85YBTZiEe0xFKVJsXvQQw+1SrmMK3GG5HXnrNd7mm1aC7STvIZ0kjrILy/AAeHe56u u8eA== X-Received: by 2002:ad4:5caf:0:b0:626:1be5:177b with SMTP id q15-20020ad45caf000000b006261be5177bmr2911128qvh.65.1686357364384; Fri, 09 Jun 2023 17:36:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rm2siojpTBjXuxisSLjrzwpdYvZZdg2Os7OOWmL6xf5nT3pxYDVVeRV5gu2n6nRKIL42wqQ== X-Received: by 2002:ad4:5caf:0:b0:626:1be5:177b with SMTP id q15-20020ad45caf000000b006261be5177bmr2911115qvh.65.1686357364111; Fri, 09 Jun 2023 17:36:04 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::ca58? ([2607:fea8:51df:4200::ca58]) by smtp.gmail.com with ESMTPSA id x15-20020a05620a12af00b0075cda118f83sm1373917qki.73.2023.06.09.17.36.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Jun 2023 17:36:03 -0700 (PDT) Message-ID: <37091c54-e7b5-9f84-8b21-b4507f2723bb@redhat.com> Date: Fri, 9 Jun 2023 20:36:02 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED 11/15] Unify PLUS_EXPR range operator X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Bootstrap on x86_64-pc-linux-gnu and pass all regressions. Pushed. Andrew From cc4eaf6f1e1958f920007d4cc7cafb635b5dda64 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 9 Jun 2023 13:41:28 -0400 Subject: [PATCH 11/31] Unify PLUS_EXPR range operator Move the declaration of the class to the range-op-mixed header, add the floating point prototypes as well, and use it in the new unified table. * range-op-float.cc (foperator_plus): Remove. Move prototypes to range-op-mixed.h (operator_plus::fold_range): Rename from foperator_plus. (operator_plus::op1_range): Ditto. (operator_plus::op2_range): Ditto. (operator_plus::rv_fold): Ditto. (float_table::float_table): Remove PLUS_EXPR. * range-op-mixed.h (class operator_plus): Combined from integer and float files. * range-op.cc (op_plus): New object. (unified_table::unified_table): Add PLUS_EXPR. (class operator_plus): Move to range-op-mixed.h. (integral_table::integral_table): Remove PLUS_EXPR. (pointer_table::pointer_table): Remove PLUS_EXPR. --- gcc/range-op-float.cc | 94 ++++++++++++++++++++----------------------- gcc/range-op-mixed.h | 39 ++++++++++++++++++ gcc/range-op.cc | 37 ++++------------- 3 files changed, 90 insertions(+), 80 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 11d76f2ef25..bd1b79281d0 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -2254,54 +2254,49 @@ float_widen_lhs_range (tree type, const frange &lhs) return ret; } -class foperator_plus : public range_operator +bool +operator_plus::op1_range (frange &r, tree type, const frange &lhs, + const frange &op2, relation_trio) const { - using range_operator::op1_range; - using range_operator::op2_range; -public: - virtual bool op1_range (frange &r, tree type, - const frange &lhs, - const frange &op2, - relation_trio = TRIO_VARYING) const final override - { - if (lhs.undefined_p ()) - return false; - range_op_handler minus (MINUS_EXPR, type); - if (!minus) - return false; - frange wlhs = float_widen_lhs_range (type, lhs); - return float_binary_op_range_finish (minus.fold_range (r, type, wlhs, op2), - r, type, wlhs); - } - virtual bool op2_range (frange &r, tree type, - const frange &lhs, - const frange &op1, - relation_trio = TRIO_VARYING) const final override - { - return op1_range (r, type, lhs, op1); - } -private: - void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan, - tree type, - const REAL_VALUE_TYPE &lh_lb, - const REAL_VALUE_TYPE &lh_ub, - const REAL_VALUE_TYPE &rh_lb, - const REAL_VALUE_TYPE &rh_ub, - relation_kind) const final override - { - frange_arithmetic (PLUS_EXPR, type, lb, lh_lb, rh_lb, dconstninf); - frange_arithmetic (PLUS_EXPR, type, ub, lh_ub, rh_ub, dconstinf); + if (lhs.undefined_p ()) + return false; + range_op_handler minus (MINUS_EXPR, type); + if (!minus) + return false; + frange wlhs = float_widen_lhs_range (type, lhs); + return float_binary_op_range_finish (minus.fold_range (r, type, wlhs, op2), + r, type, wlhs); +} - // [-INF] + [+INF] = NAN - if (real_isinf (&lh_lb, true) && real_isinf (&rh_ub, false)) - maybe_nan = true; - // [+INF] + [-INF] = NAN - else if (real_isinf (&lh_ub, false) && real_isinf (&rh_lb, true)) - maybe_nan = true; - else - maybe_nan = false; - } -} fop_plus; +bool +operator_plus::op2_range (frange &r, tree type, + const frange &lhs, const frange &op1, + relation_trio) const +{ + return op1_range (r, type, lhs, op1); +} + +void +operator_plus::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, + bool &maybe_nan, tree type, + const REAL_VALUE_TYPE &lh_lb, + const REAL_VALUE_TYPE &lh_ub, + const REAL_VALUE_TYPE &rh_lb, + const REAL_VALUE_TYPE &rh_ub, + relation_kind) const +{ + frange_arithmetic (PLUS_EXPR, type, lb, lh_lb, rh_lb, dconstninf); + frange_arithmetic (PLUS_EXPR, type, ub, lh_ub, rh_ub, dconstinf); + + // [-INF] + [+INF] = NAN + if (real_isinf (&lh_lb, true) && real_isinf (&rh_ub, false)) + maybe_nan = true; + // [+INF] + [-INF] = NAN + else if (real_isinf (&lh_ub, false) && real_isinf (&rh_lb, true)) + maybe_nan = true; + else + maybe_nan = false; +} class foperator_minus : public range_operator @@ -2317,9 +2312,9 @@ public: if (lhs.undefined_p ()) return false; frange wlhs = float_widen_lhs_range (type, lhs); - return float_binary_op_range_finish (fop_plus.fold_range (r, type, wlhs, - op2), - r, type, wlhs); + return float_binary_op_range_finish ( + range_op_handler (PLUS_EXPR).fold_range (r, type, wlhs, op2), + r, type, wlhs); } virtual bool op2_range (frange &r, tree type, const frange &lhs, @@ -2698,7 +2693,6 @@ float_table::float_table () { set (ABS_EXPR, fop_abs); set (NEGATE_EXPR, fop_negate); - set (PLUS_EXPR, fop_plus); set (MINUS_EXPR, fop_minus); set (MULT_EXPR, fop_mult); } diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 9de8479cd24..fbfe3f825a3 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -328,4 +328,43 @@ private: const irange &outer) const; }; +class operator_plus : public range_operator +{ +public: + using range_operator::op1_range; + using range_operator::op2_range; + using range_operator::lhs_op1_relation; + using range_operator::lhs_op2_relation; + bool op1_range (irange &r, tree type, + const irange &lhs, const irange &op2, + relation_trio) const final override; + bool op1_range (frange &r, tree type, + const frange &lhs, const frange &op2, + relation_trio = TRIO_VARYING) const final override; + + bool op2_range (irange &r, tree type, + const irange &lhs, const irange &op1, + relation_trio) const final override; + bool op2_range (frange &r, tree type, + const frange &lhs, const frange &op1, + relation_trio = TRIO_VARYING) const final override; + + relation_kind lhs_op1_relation (const irange &lhs, const irange &op1, + const irange &op2, + relation_kind rel) const final override; + relation_kind lhs_op2_relation (const irange &lhs, const irange &op1, + const irange &op2, + relation_kind rel) const final override; + void update_bitmask (irange &r, const irange &lh, + const irange &rh) const final override; +private: + void wi_fold (irange &r, tree type, const wide_int &lh_lb, + const wide_int &lh_ub, const wide_int &rh_lb, + const wide_int &rh_ub) const final override; + void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, + bool &maybe_nan, tree type, + const REAL_VALUE_TYPE &lh_lb, const REAL_VALUE_TYPE &lh_ub, + const REAL_VALUE_TYPE &rh_lb, const REAL_VALUE_TYPE &rh_ub, + relation_kind) const final override; +}; #endif // GCC_RANGE_OP_MIXED_H diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 7d89b633da3..1dc5c38ef63 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -71,6 +71,7 @@ operator_ge op_ge; operator_identity op_ident; operator_cst op_cst; operator_cast op_cast; +operator_plus op_plus; // Invoke the initialization routines for each class of range. @@ -93,7 +94,7 @@ unified_table::unified_table () set (INTEGER_CST, op_cst); set (NOP_EXPR, op_cast); set (CONVERT_EXPR, op_cast); - + set (PLUS_EXPR, op_plus); } // The tables are hidden and accessed via a simple extern function. @@ -1498,35 +1499,12 @@ operator_ge::op2_range (irange &r, tree type, } -class operator_plus : public range_operator +void +operator_plus::update_bitmask (irange &r, const irange &lh, + const irange &rh) const { - using range_operator::op1_range; - using range_operator::op2_range; - using range_operator::lhs_op1_relation; - using range_operator::lhs_op2_relation; -public: - virtual bool op1_range (irange &r, tree type, - const irange &lhs, - const irange &op2, - relation_trio) const; - virtual bool op2_range (irange &r, tree type, - const irange &lhs, - const irange &op1, - relation_trio) const; - virtual void wi_fold (irange &r, tree type, - const wide_int &lh_lb, - const wide_int &lh_ub, - const wide_int &rh_lb, - const wide_int &rh_ub) const; - virtual relation_kind lhs_op1_relation (const irange &lhs, const irange &op1, - const irange &op2, - relation_kind rel) const; - virtual relation_kind lhs_op2_relation (const irange &lhs, const irange &op1, - const irange &op2, - relation_kind rel) const; - void update_bitmask (irange &r, const irange &lh, const irange &rh) const - { update_known_bitmask (r, PLUS_EXPR, lh, rh); } -} op_plus; + update_known_bitmask (r, PLUS_EXPR, lh, rh); +} // Check to see if the range of OP2 indicates anything about the relation // between LHS and OP1. @@ -4717,7 +4695,6 @@ pointer_or_operator::wi_fold (irange &r, tree type, integral_table::integral_table () { - set (PLUS_EXPR, op_plus); set (MINUS_EXPR, op_minus); set (MIN_EXPR, op_min); set (MAX_EXPR, op_max); -- 2.40.1