From patchwork Mon Jun 12 15:33:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 106694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2678293vqr; Mon, 12 Jun 2023 08:43:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PVNOrW3U3517BW/5zrpGSKVDAQaY9Icf7zPWo5ChAfE31ns2en8o4XYsCNoK6Q+7uaeZp X-Received: by 2002:a05:6512:2f5:b0:4f1:26f5:7814 with SMTP id m21-20020a05651202f500b004f126f57814mr5022673lfq.20.1686584631315; Mon, 12 Jun 2023 08:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686584631; cv=none; d=google.com; s=arc-20160816; b=xGPckZZ+V7oR249LnvunXECGrtFdBYt4f3Z31z/BMa+8N1SiAMW6b3n6XbjYhxwmbV em5nHMmZvTR4NRiAJvUaA3IiIdN3KXPlgj1a0belsR706UC9JV2zyvlLZEAeoFOQBsYf G9hG0iQxrcPBsCbIdiP03/vfQagEtjnkvvr1EKRjLQ3cWSj/zHcCINg2Vbz6/L2OtXR4 MqslJSsjHZ/F0QNdsQt/LQarjKRUq6UXSr1Ql5gUSE7bgJdU9brlQRVxV14G7UvcjJ0S gXlUmM6+EAadj+2qSXLgNiJX2PPhPYWCh/FazPfY8Mz8nJH+TrJrLZSHFTxLg4AZRJu4 HB/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=KhDJ6zqZyuJU4pxZpP74nMwvJkFnIKwY3FJ9znhaW0g=; b=dWgMy4MtbQGYGtbbvGCfAInQ541ooMKBtzF/eeZeTd/Vvouynq73YB6JawWrBOXZlg BRcE16FzTWoBk38bEWuieP1WToRhb4fjKTXU72Kb4GZP3qqZFNorXTPo4R0B6aPefIp9 FEwDAe9UF2vJ8zq/BQgOsQ+YqKOJtwKUlH1/AHqtKnFfaEh9+aWk+dwAxDNlkAnLFRZG 18JzqRCcPsXT9VqF2/2w+SYn8IHJSefcD20Lk23jo+SYOz7GIhlrz2kAOIuy5RvYXDiw ZYjPPhw5KaK0ZRUW9VZySbKLFunJZeCh0373mCBGS0zOzFNb1ELRbi/jQAy6xI9/rFO+ gIRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DkVvTUNB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c11-20020a056402120b00b0050bca43ff51si6436133edw.277.2023.06.12.08.43.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 08:43:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DkVvTUNB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4592C3939C00 for ; Mon, 12 Jun 2023 15:37:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4592C3939C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686584250; bh=KhDJ6zqZyuJU4pxZpP74nMwvJkFnIKwY3FJ9znhaW0g=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DkVvTUNB6Rnm+G8ZBhSCllQOFJ+9JsnOL+Bfn9iYB2Ug0F7aKaW6sWQ9s37k+G1S8 Y8wtrY4nSDOfv3Rc4jLFl+KGdHYDFFgo6unjIrZxOvIhjL5fQ4/KV6RHVGNmi5KuW9 akc+uZZvnAa84Xg1a2KB29kWAFQmDmObSlOz7GKY= 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 AD3E43858C78 for ; Mon, 12 Jun 2023 15:33:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD3E43858C78 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-Pr6Di9CeP4iI_aBkfoyxYQ-1; Mon, 12 Jun 2023 11:33:21 -0400 X-MC-Unique: Pr6Di9CeP4iI_aBkfoyxYQ-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-39aa9617c6bso2425147b6e.1 for ; Mon, 12 Jun 2023 08:33:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686584000; x=1689176000; 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=0b5GSsjoKmV85Fxg5Q+pSQar09PcscYJupMzWDm0zQU=; b=jnAsiZCV/apVzsOKf6pGozx6chflGvnV2bwqFim8Wk6L8m30oYYe/uP+pTdlMdjknY vSjRRt5Li8a8Bup87xsQWN9kzb0uiPAMQRi6bMen/EVlkXjKuKpRCyv+a4/vU+VvXgBi 4tbfJCYnaGkYg5Btp5eYHZy1AZhcX30mK2dsqK0xH0sN+7AGAHKy/m4rHDVvozLITLDa 9zDsfaDVkmuLei43NzWAR6IUeX0MDKwhYF7Kbxv4+clLxnDfewEpo5juCVaMmVT94WnX CrOn6JdmKV5oSNIQGKgCFNF3yLUtzpHD0AhG9NnAveqXTLwoTURcF722/HHb8/cNh5f5 hFbw== X-Gm-Message-State: AC+VfDwX+n2irdO8FXoAW2JPvLjANTOopNoKYpNkYOUa/Yu6hLCm55XA NWHfPkrTRKUxllucKgIzX4Db6IRk3RPH2lji5rHi4HvffouZ58XUpvO+o/MyDNNMi5D+T5kZUt5 5BrBWbstmt2O+5hkNh9jDfNt3/j+OaF9G0LlD3R9cCIfBQ/J6dJuzw/r2/GswwQxZVpc/IyBcqg Ba+g== X-Received: by 2002:a05:6808:1905:b0:39a:bd0e:449 with SMTP id bf5-20020a056808190500b0039abd0e0449mr5657313oib.26.1686584000292; Mon, 12 Jun 2023 08:33:20 -0700 (PDT) X-Received: by 2002:a05:6808:1905:b0:39a:bd0e:449 with SMTP id bf5-20020a056808190500b0039abd0e0449mr5657276oib.26.1686583999831; Mon, 12 Jun 2023 08:33:19 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::ca58? ([2607:fea8:51df:4200::ca58]) by smtp.gmail.com with ESMTPSA id g16-20020ac84690000000b003f8e6071e43sm3504711qto.3.2023.06.12.08.33.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jun 2023 08:33:19 -0700 (PDT) Message-ID: Date: Mon, 12 Jun 2023 11:33:18 -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 15/17] - Provide a default range_operator via range_op_handler. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.2 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768512165953554363?= X-GMAIL-MSGID: =?utf-8?q?1768512165953554363?= This provides range_op_handler with a default range_operator, so you no longer need to check if it has a valid handler or not. The valid check now turns into a "is this something other than a default operator" check.   IT means you can now simply invoke fold without checking.. ie instead of range_op_handler handler(CONVERT_EXPR); if (handler &&  handler.fold_range (......)) we can simply write if (range_op_handler(CONVERT_EXPR).fold_range (....)) The new method range_op() will return the a pointer to the custom range_operator, or NULL if its the default.   THis allos use of range_op_handler() to behave as if you were indexing a range table/ if that happens to be needed. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 3c4399657d35a0b5bf7caeb88c6ddc0461322d3f Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Sat, 10 Jun 2023 16:59:38 -0400 Subject: [PATCH 15/17] Provide a default range_operator via range_op_handler. range_op_handler now provides a default range_operator for any opcode, so there is no longer a need to check for a valid operator. * gimple-range-op.cc (gimple_range_op_handler): Set m_operator manually as there is no access to the default operator. (cfn_copysign::fold_range): Don't check for validity. (cfn_ubsan::fold_range): Ditto. (gimple_range_op_handler::maybe_builtin_call): Don't set to NULL. * range-op.cc (default_operator): New. (range_op_handler::range_op_handler): Use default_operator instead of NULL. (range_op_handler::operator bool): Move from header, compare against default operator. (range_op_handler::range_op): New. * range-op.h (range_op_handler::operator bool): Move. --- gcc/gimple-range-op.cc | 28 +++++++++++++--------------- gcc/range-op.cc | 32 ++++++++++++++++++++++++++++++-- gcc/range-op.h | 3 ++- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 4cbc981ee04..021a9108ecf 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -120,21 +120,22 @@ gimple_range_op_handler::supported_p (gimple *s) // Construct a handler object for statement S. gimple_range_op_handler::gimple_range_op_handler (gimple *s) - : range_op_handler (get_code (s)) { + range_op_handler oper (get_code (s)); m_stmt = s; m_op1 = NULL_TREE; m_op2 = NULL_TREE; - if (m_operator) + if (oper) switch (gimple_code (m_stmt)) { case GIMPLE_COND: m_op1 = gimple_cond_lhs (m_stmt); m_op2 = gimple_cond_rhs (m_stmt); // Check that operands are supported types. One check is enough. - if (!Value_Range::supports_type_p (TREE_TYPE (m_op1))) - m_operator = NULL; + if (Value_Range::supports_type_p (TREE_TYPE (m_op1))) + m_operator = oper.range_op (); + gcc_checking_assert (m_operator); return; case GIMPLE_ASSIGN: m_op1 = gimple_range_base_of_assignment (m_stmt); @@ -153,7 +154,9 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) m_op2 = gimple_assign_rhs2 (m_stmt); // Check that operands are supported types. One check is enough. if ((m_op1 && !Value_Range::supports_type_p (TREE_TYPE (m_op1)))) - m_operator = NULL; + return; + m_operator = oper.range_op (); + gcc_checking_assert (m_operator); return; default: gcc_unreachable (); @@ -165,6 +168,7 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) maybe_builtin_call (); else maybe_non_standard (); + gcc_checking_assert (m_operator); } // Calculate what we can determine of the range of this unary @@ -364,11 +368,10 @@ public: const frange &rh, relation_trio) const override { frange neg; - range_op_handler abs_op (ABS_EXPR); - range_op_handler neg_op (NEGATE_EXPR); - if (!abs_op || !abs_op.fold_range (r, type, lh, frange (type))) + if (!range_op_handler (ABS_EXPR).fold_range (r, type, lh, frange (type))) return false; - if (!neg_op || !neg_op.fold_range (neg, type, r, frange (type))) + if (!range_op_handler (NEGATE_EXPR).fold_range (neg, type, r, + frange (type))) return false; bool signbit; @@ -1073,14 +1076,11 @@ public: virtual bool fold_range (irange &r, tree type, const irange &lh, const irange &rh, relation_trio rel) const { - range_op_handler handler (m_code); - gcc_checking_assert (handler); - bool saved_flag_wrapv = flag_wrapv; // Pretend the arithmetic is wrapping. If there is any overflow, // we'll complain, but will actually do wrapping operation. flag_wrapv = 1; - bool result = handler.fold_range (r, type, lh, rh, rel); + bool result = range_op_handler (m_code).fold_range (r, type, lh, rh, rel); flag_wrapv = saved_flag_wrapv; // If for both arguments vrp_valueize returned non-NULL, this should @@ -1230,8 +1230,6 @@ gimple_range_op_handler::maybe_builtin_call () m_operator = &op_cfn_constant_p; else if (frange::supports_p (TREE_TYPE (m_op1))) m_operator = &op_cfn_constant_float_p; - else - m_operator = NULL; break; CASE_FLT_FN (CFN_BUILT_IN_SIGNBIT): diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 382f5d50ffa..a271e00fa07 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -121,16 +121,44 @@ range_op_table::range_op_table () // set (MAX_EXPR, op_max); } +// Instantiate a default range operator for opcodes with no entry. + +range_operator default_operator; + +// Create a default range_op_handler. + range_op_handler::range_op_handler () { - m_operator = NULL; + m_operator = &default_operator; } -// Constructing without a type must come from the unified table. +// Create a range_op_handler for CODE. Use a default operatoer if CODE +// does not have an entry. range_op_handler::range_op_handler (tree_code code) { m_operator = operator_table[code]; + if (!m_operator) + m_operator = &default_operator; +} + +// Return TRUE if this handler has a non-default operator. + +range_op_handler::operator bool () const +{ + return m_operator != &default_operator; +} + +// Return a pointer to the range operator assocaited with this handler. +// If it is a default operator, return NULL. +// This is the equivalent of indexing the range table. + +range_operator * +range_op_handler::range_op () const +{ + if (m_operator != &default_operator) + return m_operator; + return NULL; } // Create a dispatch pattern for value range discriminators LHS, OP1, and OP2. diff --git a/gcc/range-op.h b/gcc/range-op.h index 328910d0ec5..8243258eea5 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -186,7 +186,8 @@ class range_op_handler public: range_op_handler (); range_op_handler (enum tree_code code); - inline operator bool () const { return m_operator != NULL; } + operator bool () const; + range_operator *range_op () const; bool fold_range (vrange &r, tree type, const vrange &lh, -- 2.40.1