From patchwork Thu Sep 22 18:53:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681282 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=2620:52:3:1:0:246e:9693:128c; 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=fdeNxUrT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPZS055sz1yqH for ; Fri, 23 Sep 2022 04:53:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B57B838582B8 for ; Thu, 22 Sep 2022 18:53:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B57B838582B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663872828; bh=aOOVUbiGlHSHbdvEA41qXLTaXw9zF5f7lspgc0P05oQ=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fdeNxUrTYqL8ousq/KsbTl5d1yfZreNEIl5tL2CgE1Kf4P2IBysl/k5A+tB8TfwbX CR1n14OWo8X44H4VMpDH/P6bfqfpF5W06uvYaLCmEK0yJGnPMXdrcU4e2k4dxHR05n IlI82VdMnW/+cw2v7Dr0kwHWADW5fzWRebUJllxg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 29F423858005 for ; Thu, 22 Sep 2022 18:53:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29F423858005 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-63-rwInK-5NM4iQjtmN5s7siw-1; Thu, 22 Sep 2022 14:53:27 -0400 X-MC-Unique: rwInK-5NM4iQjtmN5s7siw-1 Received: by mail-il1-f199.google.com with SMTP id a8-20020a92c548000000b002f6440ff96bso5520795ilj.22 for ; Thu, 22 Sep 2022 11:53:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=ZzQiHJqOmQYwc66TesGqVlGBQLNDhJ6XH1ltH3oGKkY=; b=S0mNGzafAkft2tp448kaTkJ/t9jzpP5b5N4P3KdWxBUgVfNuo8VdlnPHSumQun1oPd LugpqHPpjdBeDjxsVHd7ZkU1+S6VPF29tne/kJgKJuglgmpD6/OsbDql3yOBGnYRR+vr N2Men8Mu5ebolkb+pzm8hgWnDTWAHYAh2xsLWk156xqIaOlOKZICs+9xrIbFC32FGJYy o9xhUBsS7SCpWFGjpftcTcZnLknbttO3KYZK+sDZsFSgzBFsIHW+jjuOL88BhBOg+APH fQ/yc0fNVdk2Rb47EQT18gqaemVBhw9DqaaNr3r5uwx7UtUMTPI0tcdOb0yrwwFSx/NG 6dVQ== X-Gm-Message-State: ACrzQf31XVqneO9zvioBmaa9Y4fFD2xHOZG4Zi8efQn4Q0fzkkNIbhTS fLbwkRYCg6iXYsLvuxIxMS/NrZWR4iD+etp7CG3Sj25GouzFN+0USKQzP8RsJwY3+18Tio8UmHb 91WZzUxw+y98w6H57Ixnv+BKOWjdJ7TvDBurlLuzpXXD3eBAoUprDid8NNaNrMWav3n9FTg== X-Received: by 2002:a05:6e02:1be9:b0:2f1:f016:f00 with SMTP id y9-20020a056e021be900b002f1f0160f00mr2487408ilv.208.1663872806413; Thu, 22 Sep 2022 11:53:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56SBuM2LAJTALb241lhNUoXAA0jxo6IC7a6Xdg+0ynS44yrzrpqWwCrOUAHszv05m4ci3L6w== X-Received: by 2002:a05:6e02:1be9:b0:2f1:f016:f00 with SMTP id y9-20020a056e021be900b002f1f0160f00mr2487400ilv.208.1663872806174; Thu, 22 Sep 2022 11:53:26 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id m15-20020a026a4f000000b00349e5bf727fsm2553508jaf.21.2022.09.22.11.53.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 11:53:25 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 14:53:24 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 01/17] Replace another snippet with a call to, gimple_range_ssa_names. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" When the original patch was applied, I missed a spot which could also be rewritten to use gimple_range_ssa_names. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 3cba5cd6e019182dbff756f621af048d55cdda98 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 31 Aug 2022 17:28:09 -0400 Subject: [PATCH 01/17] Replace another snippet with a call to gimple_range_ssa_names. When the original patch was applied, I missed a spot which could also be rewritten to use gimple_range_ssa_names. * tree-ssa-threadbackward.cc (back_threader::find_paths_to_names): Replace sequence with a call to gimple_range_ssa_names. --- gcc/tree-ssa-threadbackward.cc | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc index 9725f50e639..2a8cfa3ee01 100644 --- a/gcc/tree-ssa-threadbackward.cc +++ b/gcc/tree-ssa-threadbackward.cc @@ -435,28 +435,14 @@ back_threader::find_paths_to_names (basic_block bb, bitmap interesting, } /* For other local defs process their uses, amending imports on the way. */ - else if (gassign *ass = dyn_cast (def_stmt)) + else { tree ssa[3]; - if (range_op_handler (ass)) - { - ssa[0] = gimple_range_ssa_p (gimple_range_operand1 (ass)); - ssa[1] = gimple_range_ssa_p (gimple_range_operand2 (ass)); - ssa[2] = NULL_TREE; - } - else if (gimple_assign_rhs_code (ass) == COND_EXPR) - { - ssa[0] = gimple_range_ssa_p (gimple_assign_rhs1 (ass)); - ssa[1] = gimple_range_ssa_p (gimple_assign_rhs2 (ass)); - ssa[2] = gimple_range_ssa_p (gimple_assign_rhs3 (ass)); - } - else - continue; - for (unsigned j = 0; j < 3; ++j) + unsigned lim = gimple_range_ssa_names (ssa, 3, def_stmt); + for (unsigned j = 0; j < lim; ++j) { tree rhs = ssa[j]; if (rhs - && TREE_CODE (rhs) == SSA_NAME && bitmap_set_bit (m_imports, SSA_NAME_VERSION (rhs))) { -- 2.37.3 From patchwork Thu Sep 22 18:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681284 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=lrBoRat4; 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 4MYPdb5bmcz1ypf for ; Fri, 23 Sep 2022 04:56:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B276D3858422 for ; Thu, 22 Sep 2022 18:56:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B276D3858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663872992; bh=uurvdmFJndByZoPIzm5jGG91F/2JgZsck2Zevdd4ivU=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lrBoRat42zFZZgilOcFDjWx6eiNLr/kyXXUMrRiFK6yME2tBLtt+csHbdV2BZJcb2 uPFYw+nV+iqBfrW5rLlqzzd0seCLTqu/Zdqo4yB51zYcLuDDZWTYnDd8TYEfLI0lsa G5S57n5MRSlg1qUOrSLVFI/JNB8GnewGX0mcuvoc= 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 9D4B83858D38 for ; Thu, 22 Sep 2022 18:55:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9D4B83858D38 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-WJ7-eTngM_SGWg8SRxJEVw-1; Thu, 22 Sep 2022 14:55:24 -0400 X-MC-Unique: WJ7-eTngM_SGWg8SRxJEVw-1 Received: by mail-io1-f69.google.com with SMTP id x22-20020a6bda16000000b006a123cb02beso5269615iob.18 for ; Thu, 22 Sep 2022 11:55:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=97NnmpUTJjO568PXvlnekEPyNeu3tD6AmprRIu4ZoHI=; b=A5Abc2x9c/uUQf5o3hadZ5EGdDxD1CGzPATpQmLGpYTHk/Ac5raNHdYwTt2ficwCHo Qpq1vIKC7ZHOH6Z/UVCKppDFsevViNPYG8kzOPKkzIqyfppIBmeHmHc4M4kmhfH09EH0 beoLebJZoxf8O6786cB6DjymUgAPmKjLTIQ/88mvayIYiVwkvitdg29Rwa1UaLITX/MA oSoNyMw5PzXGMDNO6lgHDY7pp7HKSOYFVVFbjuEi0bPTfFp+GkHt5NCfIOf8poYSN5lx hqFAUU2djn1fLCdQgG/ayWnzuzhUd43V4mY8q6o+5R8zEQGLp88JMBgmls2ezJnXtKVg ogKA== X-Gm-Message-State: ACrzQf2QQ4yS8tWw/WklHs0EidjeSa6y9hXJZWfyirtW6l54LxdbSQPw vqZ6wsMuxy0RWsOWBBPrKxwDGTE5cu5nEkNEpf/pGv3Eztv1Lcct4oyk3RUQkWhN6EOO6AAmxcN V+/BeNgBP5GAX2ERIYuzcBRk5lODSGdX4/Jg01mG4ds0SpFdA51xt1JbfmklX1dM0X5hmqQ== X-Received: by 2002:a05:6e02:1148:b0:2f6:8c53:acb8 with SMTP id o8-20020a056e02114800b002f68c53acb8mr2446460ill.207.1663872923038; Thu, 22 Sep 2022 11:55:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SXTFRncyk98nudyprFKbK58cYt5Vi7aOLbqGmRpYllFkYD10CkKo3CeC2PonH9f9+2ldyUw== X-Received: by 2002:a05:6e02:1148:b0:2f6:8c53:acb8 with SMTP id o8-20020a056e02114800b002f68c53acb8mr2446442ill.207.1663872922657; Thu, 22 Sep 2022 11:55:22 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id z7-20020a92cb87000000b002f54ab12613sm2297698ilo.1.2022.09.22.11.55.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 11:55:21 -0700 (PDT) Message-ID: <1c18ea06-495c-52f5-67ea-b116ef0df3bc@redhat.com> Date: Thu, 22 Sep 2022 14:55:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 02/17] Adjust range_op_handler to store the handler directly. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.3 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Range_op_handler currently stores a tree code and a type.  It defers checking to see if there is a valid handler until asked. This change checks at constructor time and store a pointer to the handler if there is one. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 24c473a14d3cbe6fc44997122b532cb9406497cb Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 31 Aug 2022 14:07:13 -0400 Subject: [PATCH 02/17] Adjust range_op_handler to store the handler directly. Range_op_handler currently stores a tree code and a type. It defers checking to see if there is a valid handler until asked. This change checks at constuctor time and store a pointer to the handler if there is one. * range-op.cc (range_op_handler::set_op_handler): Set new fields. (ange_op_handler::range_op_handler): Likewise. (range_op_handler::operator bool): Remove. (range_op_handler::fold_range): Use appropriate handler. (range_op_handler::op1_range): Likewise. (range_op_handler::op2_range): Likewise. (range_op_handler::lhs_op1_relation): Likewise. (range_op_handler::lhs_op2_relation): Likewise. (range_op_handler::op1_op2_relation): Likewise. * range-op.h (class range_op_handler): Store handler pointers. (range_op_handler:: operator bool): Inline. --- gcc/range-op.cc | 246 +++++++++++++++++++++--------------------------- gcc/range-op.h | 8 +- 2 files changed, 114 insertions(+), 140 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 806edf1012e..f642b3f26de 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4159,48 +4159,63 @@ get_float_handler (enum tree_code code, tree) return (*floating_tree_table)[code]; } +void +range_op_handler::set_op_handler (tree_code code, tree type) +{ + if (irange::supports_p (type)) + { + m_float = NULL; + m_int = get_handler (code, type); + m_valid = m_int != NULL; + } + else if (frange::supports_p (type)) + { + m_int = NULL; + m_float = get_float_handler (code, type); + m_valid = m_float != NULL; + } + else + { + m_int = NULL; + m_float = NULL; + m_valid = false; + } +} + range_op_handler::range_op_handler (tree_code code, tree type) - : m_code (code), m_type (type) { + set_op_handler (code, type); } range_op_handler::range_op_handler (const gimple *s) { + tree_code code = NOP_EXPR; + tree type = NULL_TREE; + if (const gassign *ass = dyn_cast (s)) { - m_code = gimple_assign_rhs_code (ass); + code = gimple_assign_rhs_code (ass); // The LHS of a comparison is always an int, so we must look at // the operands. - if (TREE_CODE_CLASS (m_code) == tcc_comparison) - m_type = TREE_TYPE (gimple_assign_rhs1 (ass)); + if (TREE_CODE_CLASS (code) == tcc_comparison) + type = TREE_TYPE (gimple_assign_rhs1 (ass)); else - m_type = TREE_TYPE (gimple_assign_lhs (ass)); + type = TREE_TYPE (gimple_assign_lhs (ass)); } else if (const gcond *cond = dyn_cast (s)) { - m_code = gimple_cond_code (cond); - m_type = TREE_TYPE (gimple_cond_lhs (cond)); + code = gimple_cond_code (cond); + type = TREE_TYPE (gimple_cond_lhs (cond)); } - else + + if (!type) { - // A null type means there is no handler for this combination, - // but the decision whether there is one or not, is delayed - // until operator bool below is queried. - m_code = NOP_EXPR; - m_type = nullptr; + m_int = NULL; + m_float = NULL; + m_valid = false; } -} - -// Return TRUE if there is a handler available for the current -// combination of tree_code and type. - -range_op_handler::operator bool () const -{ - if (!m_type) - return false; - if (frange::supports_p (m_type)) - return get_float_handler (m_code, m_type); - return get_handler (m_code, m_type); + else + set_op_handler (code, type); } bool @@ -4209,26 +4224,19 @@ range_op_handler::fold_range (vrange &r, tree type, const vrange &rh, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (r)) - return op->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); - return op->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); - } - gcc_unreachable (); - return false; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + + if (is_a (r)) + return m_float->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + return m_float->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); } bool @@ -4237,26 +4245,19 @@ range_op_handler::op1_range (vrange &r, tree type, const vrange &op2, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->op1_range (as_a (r), type, - as_a (lhs), - as_a (op2), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->op1_range (as_a (r), type, - as_a (lhs), - as_a (op2), rel); - return op->op1_range (as_a (r), type, - as_a (lhs), - as_a (op2), rel); - } - gcc_unreachable (); - return false; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + + if (is_a (lhs)) + return m_float->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + return m_float->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); } bool @@ -4265,26 +4266,19 @@ range_op_handler::op2_range (vrange &r, tree type, const vrange &op1, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->op2_range (as_a (r), type, - as_a (lhs), - as_a (op1), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->op2_range (as_a (r), type, - as_a (lhs), - as_a (op1), rel); - return op->op2_range (as_a (r), type, - as_a (lhs), - as_a (op1), rel); - } - gcc_unreachable (); - return false; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); + + if (is_a (lhs)) + return m_float->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); + return m_float->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); } relation_kind @@ -4293,26 +4287,19 @@ range_op_handler::lhs_op1_relation (const vrange &lhs, const vrange &op2, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->lhs_op1_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->lhs_op1_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - return op->lhs_op1_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - gcc_unreachable (); - return VREL_VARYING; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + + if (is_a (lhs)) + return m_float->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + return m_float->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); } relation_kind @@ -4321,43 +4308,28 @@ range_op_handler::lhs_op2_relation (const vrange &lhs, const vrange &op2, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->lhs_op2_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->lhs_op2_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - return op->lhs_op2_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - gcc_unreachable (); - return VREL_VARYING; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->lhs_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + + if (is_a (lhs)) + return m_float->lhs_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + return m_float->lhs_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); } relation_kind range_op_handler::op1_op2_relation (const vrange &lhs) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->op1_op2_relation (as_a (lhs)); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - return op->op1_op2_relation (as_a (lhs)); - } - gcc_unreachable (); - return VREL_VARYING; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->op1_op2_relation (as_a (lhs)); + return m_float->op1_op2_relation (as_a (lhs)); } // Cast the range in R to TYPE. diff --git a/gcc/range-op.h b/gcc/range-op.h index 37d9aa91c46..56c57c46a8e 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -162,7 +162,7 @@ class range_op_handler public: range_op_handler (enum tree_code code, tree type); range_op_handler (const gimple *s); - operator bool () const; + inline operator bool () const { return m_valid; } bool fold_range (vrange &r, tree type, const vrange &lh, @@ -186,8 +186,10 @@ public: relation_kind = VREL_VARYING) const; relation_kind op1_op2_relation (const vrange &lhs) const; private: - enum tree_code m_code; - tree m_type; + void set_op_handler (enum tree_code code, tree type); + bool m_valid; + range_operator *m_int; + range_operator_float *m_float; }; extern bool range_cast (vrange &, tree type); -- 2.37.3 From patchwork Thu Sep 22 18:56:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681285 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=aPIG/zsN; 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 4MYPfN3mkvz1ypf for ; Fri, 23 Sep 2022 04:57:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 860D93857C4E for ; Thu, 22 Sep 2022 18:57:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 860D93857C4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873034; bh=mJ1WhW9AsBVAxd5cCTggc+MwGJPa4SSKJjstfEwSsZE=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aPIG/zsNFjxulzPUxSFlkn7dgQejwXR7KWgQe8oFWD7yY8R7gePo+y9oz5HzTlNEz g0yPK7IaR5kYyxuvjqlKUv6IiGykSIW1y8Fxx/yI2VavdKQ03PoxAx84d9hEqsDTSa 5QbbGKc2A3Q0Bea4S0F+cpBmKKDTs0OQ5d2vqfxk= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id F1FAF3858D38 for ; Thu, 22 Sep 2022 18:56:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F1FAF3858D38 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-373-j-5ANvjcMymt8eVKuz0IOQ-1; Thu, 22 Sep 2022 14:56:33 -0400 X-MC-Unique: j-5ANvjcMymt8eVKuz0IOQ-1 Received: by mail-il1-f199.google.com with SMTP id c7-20020a056e020bc700b002e59be6ce85so6194778ilu.12 for ; Thu, 22 Sep 2022 11:56:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=STZfviEEDRDJkKywvZnSMW+STbnK4vr6joSYOTS5iJw=; b=NaTssx7KPl6cStjbxEY4R8bwFCHkub7WSG5GSsEI+91IPdAOdtBBiZWubIZQ3YOwVB ZYjdl3gfJhCzQ0e7obnfXBdOe0C8vh4FGbOYlmKQcvIIJ01hI5KLGhTKkzZdPyx/f2KN TA2tOhqQ9jhUeU12DTTx9sHkK8cslepShWa6IaKxFmen9sdl41/E4aFv2BWIX2JUIyez MFaZ0iA0PGjAC04Fk20wcbJI2LgErbY3gRyG1C87weJjHFelkLKZXoIcNPi6zQOYzVPK Ccx6uxtLSOlNfmAeF8Ag5d+CCFAnpqimb31izVbeapmJ+h52j7kDhvqhuv4EwZEX5MaA 1H3g== X-Gm-Message-State: ACrzQf3rFYr8MLswGmrpsKjGNRG9ZuuEUrWld9T3NzGEeYMFqTdHtB0y MIM6Tr+Zb4JHDoUY3exOkybwTVXrcssmV+I+2f4/qazNvIaIq+nmVamvKnyY0l0btaoqkw9XYyi Cg/DoyPRO1HaH8mxiWtZH7PhIVFE2XQ053rKtV2p3HNxVLWCvziNbH9iqqAnHkHVWgW0OHg== X-Received: by 2002:a05:6638:430c:b0:35a:1c37:a343 with SMTP id bt12-20020a056638430c00b0035a1c37a343mr2766083jab.183.1663872992228; Thu, 22 Sep 2022 11:56:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6VJqf5vOJoysUjTuJk/e1107CJyvhBDZjTUAiqETIgd8db828BdCd/N0ZRyH96DruVN8NmEw== X-Received: by 2002:a05:6638:430c:b0:35a:1c37:a343 with SMTP id bt12-20020a056638430c00b0035a1c37a343mr2766068jab.183.1663872991894; Thu, 22 Sep 2022 11:56:31 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id m5-20020a023c05000000b0035ad6807a98sm2467092jaa.119.2022.09.22.11.56.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 11:56:31 -0700 (PDT) Message-ID: <6d24be24-0924-f56b-7dfe-18b251b42ed5@redhat.com> Date: Thu, 22 Sep 2022 14:56:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 03/17] Create gimple_range_op_handler in a new source file. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> 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, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Range-ops is meant to be IL independent.  Some gimple processing has be placed in range-ops, and some is located in gori.  Split it all into a file and isolate it in a new class gimple_range_op_handler. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 51ce06385bf259a092f830f1a6dcc4b98757919e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 1 Sep 2022 10:34:55 -0400 Subject: [PATCH 03/17] Create gimple_range_op_handler in a new source file. Range-ops is meant to be IL independent. Some gimple processing has be placed in range-ops, and some is located in gori. Split it all into a file and isolate it in a new class gimple_range_op_handler. * Makefile.in (OBJS): Add gimple-range-op.o. * gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Use gimple_range_op_handler. * gimple-range-fold.cc (gimple_range_base_of_assignment): Move to a method in gimple_range_op_handler. (gimple_range_operand1): Ditto. (gimple_range_operand2): Ditto. (fold_using_range::fold_stmt): Use gimple_range_op_handler. (fold_using_range::range_of_range_op): Ditto. (fold_using_range::relation_fold_and_or): Ditto. (fur_source::register_outgoing_edges): Ditto. (gimple_range_ssa_names): Relocate to gimple-range-op.cc. * gimple-range-fold.h: Adjust prototypes. * gimple-range-gori.cc (gimple_range_calc_op1): Move to a method in gimple_range_op_handler. (gimple_range_calc_op2): Ditto. (gori_compute::compute_operand_range): Use gimple_range_op_handler. (gori_compute::compute_logical_operands): Ditto. (compute_operand1_range): Ditto. (gori_compute::compute_operand2_range): Ditto. (gori_compute::compute_operand1_and_operand2_range): Ditto. * gimple-range-gori.h: Adjust protoypes. * gimple-range-op.cc: New. Supply gimple_range_op_handler methods. * gimple-range-op.h: New. Supply gimple_range_op_handler class. * gimple-range.cc (gimple_ranger::prefill_name): Use gimple_range_op_handler. (gimple_ranger::prefill_stmt_dependencies): Ditto. * gimple-range.h: Include gimple-range-op.h. * range-op.cc (range_op_handler::range_op_handler): Adjust and remove gimple * parameter option. * range-op.h: Adjust prototypes. --- gcc/Makefile.in | 1 + gcc/gimple-range-edge.cc | 2 +- gcc/gimple-range-fold.cc | 153 +++++------------------- gcc/gimple-range-fold.h | 12 +- gcc/gimple-range-gori.cc | 134 ++++++--------------- gcc/gimple-range-gori.h | 27 ++--- gcc/gimple-range-op.cc | 245 +++++++++++++++++++++++++++++++++++++++ gcc/gimple-range-op.h | 51 ++++++++ gcc/gimple-range.cc | 11 +- gcc/gimple-range.h | 2 +- gcc/range-op.cc | 37 ++---- gcc/range-op.h | 4 +- 12 files changed, 386 insertions(+), 293 deletions(-) create mode 100644 gcc/gimple-range-op.cc create mode 100644 gcc/gimple-range-op.h diff --git a/gcc/Makefile.in b/gcc/Makefile.in index a4689d52e36..59b67d99441 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1416,6 +1416,7 @@ OBJS = \ gimple-range-fold.o \ gimple-range-gori.o \ gimple-range-infer.o \ + gimple-range-op.o \ gimple-range-trace.o \ gimple-ssa-backprop.o \ gimple-ssa-isolate-paths.o \ diff --git a/gcc/gimple-range-edge.cc b/gcc/gimple-range-edge.cc index 194e8f87a4b..95deadffc55 100644 --- a/gcc/gimple-range-edge.cc +++ b/gcc/gimple-range-edge.cc @@ -43,7 +43,7 @@ gimple_outgoing_range_stmt_p (basic_block bb) if (!gsi_end_p (gsi)) { gimple *s = gsi_stmt (gsi); - if (is_a (s) && range_op_handler (s)) + if (is_a (s) && gimple_range_op_handler::supported_p (s)) return gsi_stmt (gsi); if (is_a (s)) return gsi_stmt (gsi); diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index a45fc7ad4c6..addf3e7f254 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -42,7 +42,7 @@ along with GCC; see the file COPYING3. If not see #include "vr-values.h" #include "range.h" #include "value-query.h" -#include "range-op.h" +#include "gimple-range-op.h" #include "gimple-range.h" // Construct a fur_source, and set the m_query field. @@ -463,73 +463,6 @@ gimple_range_adjustment (vrange &res, const gimple *stmt) } } -// Return the base of the RHS of an assignment. - -static tree -gimple_range_base_of_assignment (const gimple *stmt) -{ - gcc_checking_assert (gimple_code (stmt) == GIMPLE_ASSIGN); - tree op1 = gimple_assign_rhs1 (stmt); - if (gimple_assign_rhs_code (stmt) == ADDR_EXPR) - return get_base_address (TREE_OPERAND (op1, 0)); - return op1; -} - -// Return the first operand of this statement if it is a valid operand -// supported by ranges, otherwise return NULL_TREE. Special case is -// &(SSA_NAME expr), return the SSA_NAME instead of the ADDR expr. - -tree -gimple_range_operand1 (const gimple *stmt) -{ - gcc_checking_assert (range_op_handler (stmt)); - - switch (gimple_code (stmt)) - { - case GIMPLE_COND: - return gimple_cond_lhs (stmt); - case GIMPLE_ASSIGN: - { - tree base = gimple_range_base_of_assignment (stmt); - if (base && TREE_CODE (base) == MEM_REF) - { - // If the base address is an SSA_NAME, we return it - // here. This allows processing of the range of that - // name, while the rest of the expression is simply - // ignored. The code in range_ops will see the - // ADDR_EXPR and do the right thing. - tree ssa = TREE_OPERAND (base, 0); - if (TREE_CODE (ssa) == SSA_NAME) - return ssa; - } - return base; - } - default: - break; - } - return NULL; -} - -// Return the second operand of statement STMT, otherwise return NULL_TREE. - -tree -gimple_range_operand2 (const gimple *stmt) -{ - gcc_checking_assert (range_op_handler (stmt)); - - switch (gimple_code (stmt)) - { - case GIMPLE_COND: - return gimple_cond_rhs (stmt); - case GIMPLE_ASSIGN: - if (gimple_num_ops (stmt) >= 3) - return gimple_assign_rhs2 (stmt); - default: - break; - } - return NULL_TREE; -} - // Calculate a range for statement S and return it in R. If NAME is provided it // represents the SSA_NAME on the LHS of the statement. It is only required // if there is more than one lhs/output. If a range cannot @@ -551,8 +484,9 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name) && gimple_assign_rhs_code (s) == ADDR_EXPR) return range_of_address (as_a (r), s, src); - if (range_op_handler (s)) - res = range_of_range_op (r, s, src); + gimple_range_op_handler handler (s); + if (handler) + res = range_of_range_op (r, handler, src); else if (is_a(s)) res = range_of_phi (r, as_a (s), src); else if (is_a(s)) @@ -587,17 +521,19 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name) // If a range cannot be calculated, return false. bool -fold_using_range::range_of_range_op (vrange &r, gimple *s, fur_source &src) +fold_using_range::range_of_range_op (vrange &r, + gimple_range_op_handler &handler, + fur_source &src) { + gcc_checking_assert (handler); + gimple *s = handler.stmt (); tree type = gimple_range_type (s); if (!type) return false; - range_op_handler handler (s); - gcc_checking_assert (handler); - tree lhs = gimple_get_lhs (s); - tree op1 = gimple_range_operand1 (s); - tree op2 = gimple_range_operand2 (s); + tree lhs = handler.lhs (); + tree op1 = handler.operand1 (); + tree op2 = handler.operand2 (); Value_Range range1 (TREE_TYPE (op1)); Value_Range range2 (op2 ? TREE_TYPE (op2) : TREE_TYPE (op1)); @@ -1430,9 +1366,10 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, else if (code != BIT_IOR_EXPR && code != TRUTH_OR_EXPR) return; - tree lhs = gimple_get_lhs (s); - tree ssa1 = gimple_range_ssa_p (gimple_range_operand1 (s)); - tree ssa2 = gimple_range_ssa_p (gimple_range_operand2 (s)); + gimple_range_op_handler handler (s); + tree lhs = handler.lhs (); + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); // Deal with || and && only when there is a full set of symbolics. if (!lhs || !ssa1 || !ssa2 @@ -1448,18 +1385,18 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, gimple *ssa1_stmt = SSA_NAME_DEF_STMT (ssa1); gimple *ssa2_stmt = SSA_NAME_DEF_STMT (ssa2); - range_op_handler handler1 (SSA_NAME_DEF_STMT (ssa1)); - range_op_handler handler2 (SSA_NAME_DEF_STMT (ssa2)); + gimple_range_op_handler handler1 (ssa1_stmt); + gimple_range_op_handler handler2 (ssa2_stmt); // If either handler is not present, no relation can be found. if (!handler1 || !handler2) return; // Both stmts will need to have 2 ssa names in the stmt. - tree ssa1_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa1_stmt)); - tree ssa1_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa1_stmt)); - tree ssa2_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa2_stmt)); - tree ssa2_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa2_stmt)); + tree ssa1_dep1 = gimple_range_ssa_p (handler1.operand1 ()); + tree ssa1_dep2 = gimple_range_ssa_p (handler1.operand2 ()); + tree ssa2_dep1 = gimple_range_ssa_p (handler2.operand1 ()); + tree ssa2_dep2 = gimple_range_ssa_p (handler2.operand2 ()); if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2) return; @@ -1516,7 +1453,7 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge tree name; basic_block bb = gimple_bb (s); - range_op_handler handler (s); + gimple_range_op_handler handler (s); if (!handler) return; @@ -1529,7 +1466,6 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge e0 = NULL; } - if (e1) { // If this edge is never taken, ignore it. @@ -1544,8 +1480,8 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge // First, register the gcond itself. This will catch statements like // if (a_2 < b_5) - tree ssa1 = gimple_range_ssa_p (gimple_range_operand1 (s)); - tree ssa2 = gimple_range_ssa_p (gimple_range_operand2 (s)); + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); if (ssa1 && ssa2) { if (e0) @@ -1575,11 +1511,11 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE) continue; gimple *stmt = SSA_NAME_DEF_STMT (name); - range_op_handler handler (stmt); + gimple_range_op_handler handler (stmt); if (!handler) continue; - tree ssa1 = gimple_range_ssa_p (gimple_range_operand1 (stmt)); - tree ssa2 = gimple_range_ssa_p (gimple_range_operand2 (stmt)); + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); Value_Range r (TREE_TYPE (name)); if (ssa1 && ssa2) { @@ -1600,36 +1536,3 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge } } } - -// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names -// on the statement. For efficiency, it is an error to not pass in enough -// elements for the vector. Return the number of ssa-names. - -unsigned -gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt) -{ - tree ssa; - int count = 0; - - if (range_op_handler (stmt)) - { - gcc_checking_assert (vec_size >= 2); - if ((ssa = gimple_range_ssa_p (gimple_range_operand1 (stmt)))) - vec[count++] = ssa; - if ((ssa = gimple_range_ssa_p (gimple_range_operand2 (stmt)))) - vec[count++] = ssa; - } - else if (is_a (stmt) - && gimple_assign_rhs_code (stmt) == COND_EXPR) - { - gcc_checking_assert (vec_size >= 3); - gassign *st = as_a (stmt); - if ((ssa = gimple_range_ssa_p (gimple_assign_rhs1 (st)))) - vec[count++] = ssa; - if ((ssa = gimple_range_ssa_p (gimple_assign_rhs2 (st)))) - vec[count++] = ssa; - if ((ssa = gimple_range_ssa_p (gimple_assign_rhs3 (st)))) - vec[count++] = ssa; - } - return count; -} diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index f2eab720213..ce18c66b8e7 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -96,15 +96,6 @@ range_compatible_p (tree type1, tree type2) && TYPE_SIGN (type1) == TYPE_SIGN (type2)); } -extern tree gimple_range_operand1 (const gimple *s); -extern tree gimple_range_operand2 (const gimple *s); - -// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names -// on the statement. For efficiency, it is an error to not pass in enough -// elements for the vector. Return the number of ssa-names. - -unsigned gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt); - // Source of all operands for fold_using_range and gori_compute. // It abstracts out the source of an operand so it can come from a stmt or // and edge or anywhere a derived class of fur_source wants. @@ -169,7 +160,8 @@ public: bool fold_stmt (vrange &r, gimple *s, class fur_source &src, tree name = NULL_TREE); protected: - bool range_of_range_op (vrange &r, gimple *s, fur_source &src); + bool range_of_range_op (vrange &r, gimple_range_op_handler &handler, + fur_source &src); bool range_of_call (vrange &r, gcall *call, fur_source &src); bool range_of_cond_expr (vrange &r, gassign* cond, fur_source &src); bool range_of_address (irange &r, gimple *s, fur_source &src); diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 957b8d543fa..40b2f2f6ae9 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -29,83 +29,6 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "gimple-range.h" -// Calculate what we can determine of the range of this unary -// statement's operand if the lhs of the expression has the range -// LHS_RANGE. Return false if nothing can be determined. - -bool -gimple_range_calc_op1 (vrange &r, const gimple *stmt, const vrange &lhs_range) -{ - gcc_checking_assert (gimple_num_ops (stmt) < 3); - // Give up on empty ranges. - if (lhs_range.undefined_p ()) - return false; - - // Unary operations require the type of the first operand in the - // second range position. - tree type = TREE_TYPE (gimple_range_operand1 (stmt)); - Value_Range type_range (type); - type_range.set_varying (type); - return range_op_handler (stmt).op1_range (r, type, lhs_range, type_range); -} - -// Calculate what we can determine of the range of this statement's -// first operand if the lhs of the expression has the range LHS_RANGE -// and the second operand has the range OP2_RANGE. Return false if -// nothing can be determined. - -bool -gimple_range_calc_op1 (vrange &r, const gimple *stmt, - const vrange &lhs_range, const vrange &op2_range) -{ - // Give up on empty ranges. - if (lhs_range.undefined_p ()) - return false; - - // Unary operation are allowed to pass a range in for second operand - // as there are often additional restrictions beyond the type which - // can be imposed. See operator_cast::op1_range(). - tree type = TREE_TYPE (gimple_range_operand1 (stmt)); - // If op2 is undefined, solve as if it is varying. - if (op2_range.undefined_p ()) - { - // This is sometimes invoked on single operand stmts. - if (gimple_num_ops (stmt) < 3) - return false; - tree op2_type = TREE_TYPE (gimple_range_operand2 (stmt)); - Value_Range trange (op2_type); - trange.set_varying (op2_type); - return range_op_handler (stmt).op1_range (r, type, lhs_range, trange); - } - return range_op_handler (stmt).op1_range (r, type, lhs_range, op2_range); -} - -// Calculate what we can determine of the range of this statement's -// second operand if the lhs of the expression has the range LHS_RANGE -// and the first operand has the range OP1_RANGE. Return false if -// nothing can be determined. - -bool -gimple_range_calc_op2 (vrange &r, const gimple *stmt, - const vrange &lhs_range, const vrange &op1_range) -{ - // Give up on empty ranges. - if (lhs_range.undefined_p ()) - return false; - - tree type = TREE_TYPE (gimple_range_operand2 (stmt)); - // If op1 is undefined, solve as if it is varying. - if (op1_range.undefined_p ()) - { - tree op1_type = TREE_TYPE (gimple_range_operand1 (stmt)); - Value_Range trange (op1_type); - trange.set_varying (op1_type); - return range_op_handler (stmt).op2_range (r, type, lhs_range, trange); - } - return range_op_handler (stmt).op2_range (r, type, lhs_range, - op1_range); -} - // Return TRUE if GS is a logical && or || expression. static inline bool @@ -695,17 +618,18 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, if (is_a (stmt)) return compute_operand_range_switch (r, as_a (stmt), lhs, name, src); - if (!range_op_handler (stmt)) + gimple_range_op_handler handler (stmt); + if (!handler) return false; - tree op1 = gimple_range_ssa_p (gimple_range_operand1 (stmt)); - tree op2 = gimple_range_ssa_p (gimple_range_operand2 (stmt)); + tree op1 = gimple_range_ssa_p (handler.operand1 ()); + tree op2 = gimple_range_ssa_p (handler.operand2 ()); // Handle end of lookup first. if (op1 == name) - return compute_operand1_range (r, stmt, lhs, name, src); + return compute_operand1_range (r, handler, lhs, name, src); if (op2 == name) - return compute_operand2_range (r, stmt, lhs, name, src); + return compute_operand2_range (r, handler, lhs, name, src); // NAME is not in this stmt, but one of the names in it ought to be // derived from it. @@ -733,10 +657,10 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, tree type = TREE_TYPE (name); Value_Range op1_trange (type), op1_frange (type); Value_Range op2_trange (type), op2_frange (type); - compute_logical_operands (op1_trange, op1_frange, stmt, + compute_logical_operands (op1_trange, op1_frange, handler, as_a (lhs), name, src, op1, op1_in_chain); - compute_logical_operands (op2_trange, op2_frange, stmt, + compute_logical_operands (op2_trange, op2_frange, handler, as_a (lhs), name, src, op2, op2_in_chain); res = logical_combine (r, @@ -748,11 +672,11 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, } // Follow the appropriate operands now. else if (op1_in_chain && op2_in_chain) - res = compute_operand1_and_operand2_range (r, stmt, lhs, name, src); + res = compute_operand1_and_operand2_range (r, handler, lhs, name, src); else if (op1_in_chain) - res = compute_operand1_range (r, stmt, lhs, name, src); + res = compute_operand1_range (r, handler, lhs, name, src); else if (op2_in_chain) - res = compute_operand2_range (r, stmt, lhs, name, src); + res = compute_operand2_range (r, handler, lhs, name, src); else gcc_unreachable (); @@ -944,13 +868,14 @@ gori_compute::logical_combine (vrange &r, enum tree_code code, void gori_compute::compute_logical_operands (vrange &true_range, vrange &false_range, - gimple *stmt, + gimple_range_op_handler &handler, const irange &lhs, tree name, fur_source &src, tree op, bool op_in_chain) { + gimple *stmt = handler.stmt (); gimple *src_stmt = gimple_range_ssa_p (op) ? SSA_NAME_DEF_STMT (op) : NULL; - if (!op_in_chain || !src_stmt || chain_import_p (gimple_get_lhs (stmt), op)) + if (!op_in_chain || !src_stmt || chain_import_p (handler.lhs (), op)) { // If op is not in the def chain, or defined in this block, // use its known value on entry to the block. @@ -999,12 +924,15 @@ gori_compute::compute_logical_operands (vrange &true_range, vrange &false_range, // R, or false if no range could be calculated. bool -gori_compute::compute_operand1_range (vrange &r, gimple *stmt, +gori_compute::compute_operand1_range (vrange &r, + gimple_range_op_handler &handler, const vrange &lhs, tree name, fur_source &src) { - tree op1 = gimple_range_operand1 (stmt); - tree op2 = gimple_range_operand2 (stmt); + gimple *stmt = handler.stmt (); + tree op1 = handler.operand1 (); + tree op2 = handler.operand2 (); + Value_Range op1_range (TREE_TYPE (op1)); Value_Range tmp (TREE_TYPE (op1)); Value_Range op2_range (op2 ? TREE_TYPE (op2) : TREE_TYPE (op1)); @@ -1016,7 +944,7 @@ gori_compute::compute_operand1_range (vrange &r, gimple *stmt, if (op2) { src.get_operand (op2_range, op2); - if (!gimple_range_calc_op1 (tmp, stmt, lhs, op2_range)) + if (!handler.calc_op1 (tmp, lhs, op2_range)) return false; } else @@ -1024,7 +952,7 @@ gori_compute::compute_operand1_range (vrange &r, gimple *stmt, // We pass op1_range to the unary operation. Nomally it's a // hidden range_for_type parameter, but sometimes having the // actual range can result in better information. - if (!gimple_range_calc_op1 (tmp, stmt, lhs, op1_range)) + if (!handler.calc_op1 (tmp, lhs, op1_range)) return false; } @@ -1079,12 +1007,15 @@ gori_compute::compute_operand1_range (vrange &r, gimple *stmt, // R, or false if no range could be calculated. bool -gori_compute::compute_operand2_range (vrange &r, gimple *stmt, +gori_compute::compute_operand2_range (vrange &r, + gimple_range_op_handler &handler, const vrange &lhs, tree name, fur_source &src) { - tree op1 = gimple_range_operand1 (stmt); - tree op2 = gimple_range_operand2 (stmt); + gimple *stmt = handler.stmt (); + tree op1 = handler.operand1 (); + tree op2 = handler.operand2 (); + Value_Range op1_range (TREE_TYPE (op1)); Value_Range op2_range (TREE_TYPE (op2)); Value_Range tmp (TREE_TYPE (op2)); @@ -1093,7 +1024,7 @@ gori_compute::compute_operand2_range (vrange &r, gimple *stmt, src.get_operand (op2_range, op2); // Intersect with range for op2 based on lhs and op1. - if (!gimple_range_calc_op2 (tmp, stmt, lhs, op1_range)) + if (!handler.calc_op2 (tmp, lhs, op1_range)) return false; unsigned idx; @@ -1148,7 +1079,8 @@ gori_compute::compute_operand2_range (vrange &r, gimple *stmt, bool gori_compute::compute_operand1_and_operand2_range (vrange &r, - gimple *stmt, + gimple_range_op_handler + &handler, const vrange &lhs, tree name, fur_source &src) @@ -1157,11 +1089,11 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r, // Calculate a good a range for op2. Since op1 == op2, this will // have already included whatever the actual range of name is. - if (!compute_operand2_range (op_range, stmt, lhs, name, src)) + if (!compute_operand2_range (op_range, handler, lhs, name, src)) return false; // Now get the range thru op1. - if (!compute_operand1_range (r, stmt, lhs, name, src)) + if (!compute_operand1_range (r, handler, lhs, name, src)) return false; // Both operands have to be simultaneously true, so perform an intersection. diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 3d57ab94624..0c776ef853f 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -170,17 +170,18 @@ private: tree name, class fur_source &src); bool compute_operand_range_switch (vrange &r, gswitch *s, const vrange &lhs, tree name, fur_source &src); - bool compute_operand1_range (vrange &r, gimple *stmt, const vrange &lhs, - tree name, fur_source &src); - bool compute_operand2_range (vrange &r, gimple *stmt, const vrange &lhs, - tree name, fur_source &src); - bool compute_operand1_and_operand2_range (vrange &r, gimple *stmt, + bool compute_operand1_range (vrange &r, gimple_range_op_handler &handler, + const vrange &lhs, tree name, fur_source &src); + bool compute_operand2_range (vrange &r, gimple_range_op_handler &handler, + const vrange &lhs, tree name, fur_source &src); + bool compute_operand1_and_operand2_range (vrange &r, + gimple_range_op_handler &handler, const vrange &lhs, tree name, fur_source &src); void compute_logical_operands (vrange &true_range, vrange &false_range, - gimple *stmt, const irange &lhs, - tree name, fur_source &src, tree op, - bool op_in_chain); + gimple_range_op_handler &handler, + const irange &lhs, tree name, fur_source &src, + tree op, bool op_in_chain); bool logical_combine (vrange &r, enum tree_code code, const irange &lhs, const vrange &op1_true, const vrange &op1_false, const vrange &op2_true, const vrange &op2_false); @@ -192,16 +193,6 @@ private: int m_not_executable_flag; }; -// These routines provide a GIMPLE interface to the range-ops code. -extern bool gimple_range_calc_op1 (vrange &r, const gimple *s, - const vrange &lhs_range); -extern bool gimple_range_calc_op1 (vrange &r, const gimple *s, - const vrange &lhs_range, - const vrange &op2_range); -extern bool gimple_range_calc_op2 (vrange &r, const gimple *s, - const vrange &lhs_range, - const vrange &op1_range); - // For each name that is an import into BB's exports.. #define FOR_EACH_GORI_IMPORT_NAME(gori, bb, name) \ for (gori_export_iterator iter ((gori).imports ((bb))); \ diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc new file mode 100644 index 00000000000..f03125a0fc5 --- /dev/null +++ b/gcc/gimple-range-op.cc @@ -0,0 +1,245 @@ +/* Code for GIMPLE range op related routines. + Copyright (C) 2019-2022 Free Software Foundation, Inc. + Contributed by Andrew MacLeod + and Aldy Hernandez . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "insn-codes.h" +#include "tree.h" +#include "gimple.h" +#include "ssa.h" +#include "gimple-pretty-print.h" +#include "optabs-tree.h" +#include "gimple-iterator.h" +#include "gimple-fold.h" +#include "wide-int.h" +#include "fold-const.h" +#include "case-cfn-macros.h" +#include "omp-general.h" +#include "cfgloop.h" +#include "tree-ssa-loop.h" +#include "tree-scalar-evolution.h" +#include "langhooks.h" +#include "vr-values.h" +#include "range.h" +#include "value-query.h" +#include "gimple-range.h" + +// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names +// on the statement. For efficiency, it is an error to not pass in enough +// elements for the vector. Return the number of ssa-names. + +unsigned +gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt) +{ + tree ssa; + int count = 0; + + gimple_range_op_handler handler (stmt); + if (handler) + { + gcc_checking_assert (vec_size >= 2); + if ((ssa = gimple_range_ssa_p (handler.operand1 ()))) + vec[count++] = ssa; + if ((ssa = gimple_range_ssa_p (handler.operand2 ()))) + vec[count++] = ssa; + } + else if (is_a (stmt) + && gimple_assign_rhs_code (stmt) == COND_EXPR) + { + gcc_checking_assert (vec_size >= 3); + gassign *st = as_a (stmt); + if ((ssa = gimple_range_ssa_p (gimple_assign_rhs1 (st)))) + vec[count++] = ssa; + if ((ssa = gimple_range_ssa_p (gimple_assign_rhs2 (st)))) + vec[count++] = ssa; + if ((ssa = gimple_range_ssa_p (gimple_assign_rhs3 (st)))) + vec[count++] = ssa; + } + return count; +} + +// Return the base of the RHS of an assignment. + +static tree +gimple_range_base_of_assignment (const gimple *stmt) +{ + gcc_checking_assert (gimple_code (stmt) == GIMPLE_ASSIGN); + tree op1 = gimple_assign_rhs1 (stmt); + if (gimple_assign_rhs_code (stmt) == ADDR_EXPR) + return get_base_address (TREE_OPERAND (op1, 0)); + return op1; +} + +// If statement is supported by range-ops, set the CODE and return the TYPE. + +static tree +get_code_and_type (gimple *s, enum tree_code &code) +{ + tree type = NULL_TREE; + code = NOP_EXPR; + + if (const gassign *ass = dyn_cast (s)) + { + code = gimple_assign_rhs_code (ass); + // The LHS of a comparison is always an int, so we must look at + // the operands. + if (TREE_CODE_CLASS (code) == tcc_comparison) + type = TREE_TYPE (gimple_assign_rhs1 (ass)); + else + type = TREE_TYPE (gimple_assign_lhs (ass)); + } + else if (const gcond *cond = dyn_cast (s)) + { + code = gimple_cond_code (cond); + type = TREE_TYPE (gimple_cond_lhs (cond)); + } + return type; +} + +// If statement S has a supported range_op handler return TRUE. + +bool +gimple_range_op_handler::supported_p (gimple *s) +{ + enum tree_code code; + tree type = get_code_and_type (s, code); + return (type && range_op_handler (code, type)); +} + +// Construct a handler object for statement S. + +gimple_range_op_handler::gimple_range_op_handler (gimple *s) +{ + enum tree_code code; + tree type = get_code_and_type (s, code); + m_stmt = s; + if (type) + set_op_handler (code, type); + + if (m_valid) + switch (gimple_code (m_stmt)) + { + case GIMPLE_COND: + m_op1 = gimple_cond_lhs (m_stmt); + m_op2 = gimple_cond_rhs (m_stmt); + break; + case GIMPLE_ASSIGN: + m_op1 = gimple_range_base_of_assignment (m_stmt); + if (m_op1 && TREE_CODE (m_op1) == MEM_REF) + { + // If the base address is an SSA_NAME, we return it + // here. This allows processing of the range of that + // name, while the rest of the expression is simply + // ignored. The code in range_ops will see the + // ADDR_EXPR and do the right thing. + tree ssa = TREE_OPERAND (m_op1, 0); + if (TREE_CODE (ssa) == SSA_NAME) + m_op1 = ssa; + } + if (gimple_num_ops (m_stmt) >= 3) + m_op2 = gimple_assign_rhs2 (m_stmt); + else + m_op2 = NULL_TREE; + break; + default: + m_op1 = NULL_TREE; + m_op2 = NULL_TREE; + break; + } +} + +// Calculate what we can determine of the range of this unary +// statement's operand if the lhs of the expression has the range +// LHS_RANGE. Return false if nothing can be determined. + +bool +gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range) +{ + gcc_checking_assert (gimple_num_ops (m_stmt) < 3); + // Give up on empty ranges. + if (lhs_range.undefined_p ()) + return false; + + // Unary operations require the type of the first operand in the + // second range position. + tree type = TREE_TYPE (operand1 ()); + Value_Range type_range (type); + type_range.set_varying (type); + return op1_range (r, type, lhs_range, type_range); +} + +// Calculate what we can determine of the range of this statement's +// first operand if the lhs of the expression has the range LHS_RANGE +// and the second operand has the range OP2_RANGE. Return false if +// nothing can be determined. + +bool +gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range, + const vrange &op2_range) +{ + // Give up on empty ranges. + if (lhs_range.undefined_p ()) + return false; + + // Unary operation are allowed to pass a range in for second operand + // as there are often additional restrictions beyond the type which + // can be imposed. See operator_cast::op1_range(). + tree type = TREE_TYPE (operand1 ()); + // If op2 is undefined, solve as if it is varying. + if (op2_range.undefined_p ()) + { + // This is sometimes invoked on single operand stmts. + if (gimple_num_ops (m_stmt) < 3) + return false; + tree op2_type = TREE_TYPE (operand2 ()); + Value_Range trange (op2_type); + trange.set_varying (op2_type); + return op1_range (r, type, lhs_range, trange); + } + return op1_range (r, type, lhs_range, op2_range); +} + +// Calculate what we can determine of the range of this statement's +// second operand if the lhs of the expression has the range LHS_RANGE +// and the first operand has the range OP1_RANGE. Return false if +// nothing can be determined. + +bool +gimple_range_op_handler::calc_op2 (vrange &r, const vrange &lhs_range, + const vrange &op1_range) +{ + // Give up on empty ranges. + if (lhs_range.undefined_p ()) + return false; + + tree type = TREE_TYPE (operand2 ()); + // If op1 is undefined, solve as if it is varying. + if (op1_range.undefined_p ()) + { + tree op1_type = TREE_TYPE (operand1 ()); + Value_Range trange (op1_type); + trange.set_varying (op1_type); + return op2_range (r, type, lhs_range, trange); + } + return op2_range (r, type, lhs_range, op1_range); +} diff --git a/gcc/gimple-range-op.h b/gcc/gimple-range-op.h new file mode 100644 index 00000000000..8bc0a8fbe11 --- /dev/null +++ b/gcc/gimple-range-op.h @@ -0,0 +1,51 @@ +/* Header file for the GIMPLE range-op interface. + Copyright (C) 2022 Free Software Foundation, Inc. + Contributed by Andrew MacLeod + and Aldy Hernandez . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_GIMPLE_RANGE_OP_H +#define GCC_GIMPLE_RANGE_OP_H + +#include "range-op.h" + + +class gimple_range_op_handler : public range_op_handler +{ +public: + static bool supported_p (gimple *s); + gimple_range_op_handler (gimple *s); + inline gimple *stmt () const { return m_stmt; } + inline tree lhs () const { return gimple_get_lhs (m_stmt); } + tree operand1 () const { gcc_checking_assert (m_valid); return m_op1; } + tree operand2 () const { gcc_checking_assert (m_valid); return m_op2; } + bool calc_op1 (vrange &r, const vrange &lhs_range); + bool calc_op1 (vrange &r, const vrange &lhs_range, const vrange &op2_range); + bool calc_op2 (vrange &r, const vrange &lhs_range, const vrange &op1_range); +private: + gimple *m_stmt; + tree m_op1, m_op2; +}; + +// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names +// on the statement. For efficiency, it is an error to not pass in enough +// elements for the vector. Return the number of ssa-names. + +unsigned gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt); + +#endif // GCC_GIMPLE_RANGE_OP_H diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index eb347eee45b..d67d6499c78 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -341,7 +341,7 @@ gimple_ranger::prefill_name (vrange &r, tree name) if (!gimple_range_ssa_p (name)) return; gimple *stmt = SSA_NAME_DEF_STMT (name); - if (!range_op_handler (stmt) && !is_a (stmt)) + if (!gimple_range_op_handler::supported_p (stmt) && !is_a (stmt)) return; bool current; @@ -364,7 +364,7 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa) gcc_checking_assert (stmt && gimple_bb (stmt)); // Only pre-process range-ops and phis. - if (!range_op_handler (stmt) && !is_a (stmt)) + if (!gimple_range_op_handler::supported_p (stmt) && !is_a (stmt)) return; // Mark where on the stack we are starting. @@ -422,14 +422,15 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa) } else { - gcc_checking_assert (range_op_handler (stmt)); - tree op = gimple_range_operand2 (stmt); + gimple_range_op_handler handler (stmt); + gcc_checking_assert (handler); + tree op = handler.operand2 (); if (op) { Value_Range r (TREE_TYPE (op)); prefill_name (r, op); } - op = gimple_range_operand1 (stmt); + op = handler.operand1 (); if (op) { Value_Range r (TREE_TYPE (op)); diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 34f61025ac3..8b2ff5685e5 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "range.h" #include "value-query.h" -#include "range-op.h" +#include "gimple-range-op.h" #include "gimple-range-trace.h" #include "gimple-range-edge.h" #include "gimple-range-fold.h" diff --git a/gcc/range-op.cc b/gcc/range-op.cc index f642b3f26de..9ae42b8331f 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4182,42 +4182,19 @@ range_op_handler::set_op_handler (tree_code code, tree type) } } -range_op_handler::range_op_handler (tree_code code, tree type) +range_op_handler::range_op_handler () { - set_op_handler (code, type); + m_int = NULL; + m_float = NULL; + m_valid = false; } -range_op_handler::range_op_handler (const gimple *s) +range_op_handler::range_op_handler (tree_code code, tree type) { - tree_code code = NOP_EXPR; - tree type = NULL_TREE; - - if (const gassign *ass = dyn_cast (s)) - { - code = gimple_assign_rhs_code (ass); - // The LHS of a comparison is always an int, so we must look at - // the operands. - if (TREE_CODE_CLASS (code) == tcc_comparison) - type = TREE_TYPE (gimple_assign_rhs1 (ass)); - else - type = TREE_TYPE (gimple_assign_lhs (ass)); - } - else if (const gcond *cond = dyn_cast (s)) - { - code = gimple_cond_code (cond); - type = TREE_TYPE (gimple_cond_lhs (cond)); - } - - if (!type) - { - m_int = NULL; - m_float = NULL; - m_valid = false; - } - else - set_op_handler (code, type); + set_op_handler (code, type); } + bool range_op_handler::fold_range (vrange &r, tree type, const vrange &lh, diff --git a/gcc/range-op.h b/gcc/range-op.h index 56c57c46a8e..b4b5101a9e0 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -160,8 +160,8 @@ public: class range_op_handler { public: + range_op_handler (); range_op_handler (enum tree_code code, tree type); - range_op_handler (const gimple *s); inline operator bool () const { return m_valid; } bool fold_range (vrange &r, tree type, @@ -185,7 +185,7 @@ public: const vrange &op2, relation_kind = VREL_VARYING) const; relation_kind op1_op2_relation (const vrange &lhs) const; -private: +protected: void set_op_handler (enum tree_code code, tree type); bool m_valid; range_operator *m_int; -- 2.37.3 From patchwork Thu Sep 22 18:58:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681286 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=2620:52:3:1:0:246e:9693:128c; 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=eSN8+ppb; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPgq3fxFz1ypf for ; Fri, 23 Sep 2022 04:58:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EA503858034 for ; Thu, 22 Sep 2022 18:58:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EA503858034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873109; bh=6JMa1pAoEkayK/taNSC9m72iDiyFxEx8NRpa5VE+wFg=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=eSN8+ppbPLCrBNS/bGc74HtA7a8tW9jpmC1YZ9oMr+Mq+nQReb3D3jmcrrXEuVqdd 1kJ7sYUVX9N0nPzdAPCdt0FYbFKTs2EUrCt7TyQmWX6LFR6ikqf94rBarLGWPvDn2L GxskbG9xClLFeeo26iiBXtZmX+ixrjMzqJtEuSyI= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 6A0353858D38 for ; Thu, 22 Sep 2022 18:58:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A0353858D38 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-501-dsb31I5GN9yUFF_ij0RMew-1; Thu, 22 Sep 2022 14:58:07 -0400 X-MC-Unique: dsb31I5GN9yUFF_ij0RMew-1 Received: by mail-il1-f197.google.com with SMTP id x14-20020a056e021cae00b002f1d5aca8c6so6187026ill.5 for ; Thu, 22 Sep 2022 11:58:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=VSbtD4CdDgKEejVvpmC1byUdAG2SgCCLHf8d73tloKY=; b=u3rD5btt4j6lKEPTWseLka7Nqi7KmPA/a4Pb3JBotzwtzXZ5mfv9tL2gS6dm/7Xwo0 OoNdQ2WkGvpZ3VVWyIHQ8TdLmmsPf2neMl6jnbRYKt55lr13Reu8NZOhh5ngrM/R3Gyl hWBWVY+8FyoU1P0ugev3x2h1K20YYh6lK3AtvXuEQfM3N/v8XE5d6aIplcNfCDRQcrCA eVjhqo6kM7GUIVwBOeYl+54PqHkI4CJMWqIfKQg+/j74nThhmEnyoTXZLrwMexKXGzLZ 5EuY65N1BRmxEay6/LbXFK5EKjNXZu0/xb6Zy8mwV/alOK7rWTpGixc+1CcL8n96KxRp 4CoA== X-Gm-Message-State: ACrzQf0xjRg6AW9yNe1+D1YQhz/BPQYj9inyudAFykbGio5CP40BM9oc L5yRkIt8HEtzJMTzZ8/NixUJ8iX32RQ9jd/psFy65e5qeXW7oEsTPt1IvbYlbRNZKR+kgEZ2cAP bRpsY3F1vZXv338YqLlRrbEnnY8Zhj7Y4t5KZoo5p8ist08s7Sj/uvk4Y9BVPggC48BCuaA== X-Received: by 2002:a02:5108:0:b0:35a:eca0:92c1 with SMTP id s8-20020a025108000000b0035aeca092c1mr2844287jaa.81.1663873086656; Thu, 22 Sep 2022 11:58:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6FfyPl6eMpFAgDhdmdMrD/xScXWreYIhT8YmhP3uC6ZdszCJk4+a40Ks9/tYwSjdX8iYJ6lw== X-Received: by 2002:a02:5108:0:b0:35a:eca0:92c1 with SMTP id s8-20020a025108000000b0035aeca092c1mr2844275jaa.81.1663873086436; Thu, 22 Sep 2022 11:58:06 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id i11-20020a023b4b000000b00358437173c3sm2501709jaf.53.2022.09.22.11.58.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 11:58:05 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 14:58:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 04/17] Fix calc_op1 for undefined op2_range. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.5 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Unary operations pass the type of operand 1 into op1_range.  If that range is undefined, the routine blindly picks the type of operand 2,which in the case of a unary op, does not exist and traps. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From a7a6649f4e7c459a95dee1600554ad06aaeb1cf6 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 22 Sep 2022 10:27:17 -0400 Subject: [PATCH 04/17] Fix calc_op1 for undefined op2_range. Unary operations pass the type of operand 1 into op1_range. If that range is undefined, the routine blindly picks the type of operand 2, which in the case of a unary op, does not exist and traps. * gimple-range-op.cc (gimple_range_op_handler::calc_op1): Use operand 1 for second range if there is no operand 2. --- gcc/gimple-range-op.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index f03125a0fc5..ab5b389449d 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -208,10 +208,14 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range, // If op2 is undefined, solve as if it is varying. if (op2_range.undefined_p ()) { - // This is sometimes invoked on single operand stmts. if (gimple_num_ops (m_stmt) < 3) return false; - tree op2_type = TREE_TYPE (operand2 ()); + tree op2_type; + // This is sometimes invoked on single operand stmts. + if (operand2 ()) + op2_type = TREE_TYPE (operand2 ()); + else + op2_type = TREE_TYPE (operand1 ()); Value_Range trange (op2_type); trange.set_varying (op2_type); return op1_range (r, type, lhs_range, trange); -- 2.37.3 From patchwork Thu Sep 22 18:59:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681288 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=2620:52:3:1:0:246e:9693:128c; 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=gS0sTZe/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPjL0S6Zz1ypf for ; Fri, 23 Sep 2022 04:59:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A88A6385801C for ; Thu, 22 Sep 2022 18:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A88A6385801C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873187; bh=8O/pu2z+HCoJ09fyjwSJ+QkjB9sKIptGthJccMVpsFw=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=gS0sTZe/x139qvxl/mOIlMhSp0bJr4YcowWGTgdi3LVXEZ9c7xwKIcCv+F0xS8raY P5WgfqAqtKDPmxwJ7vT6n9AiEKT30LjH27ap8bagyf3fgSHdRPt5alD12swnMWY4Cw +Q3Y4h3t+lT1wzP75MZX1VLYJHF3DmeF4pywowDo= 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 334253858D38 for ; Thu, 22 Sep 2022 18:59:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 334253858D38 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-208-MM4-4DcUNey1gOJv-dK1rw-1; Thu, 22 Sep 2022 14:59:25 -0400 X-MC-Unique: MM4-4DcUNey1gOJv-dK1rw-1 Received: by mail-il1-f200.google.com with SMTP id x14-20020a056e021cae00b002f1d5aca8c6so6189443ill.5 for ; Thu, 22 Sep 2022 11:59:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=fHXmkP1Yf6lby4J0qDdJ7NpbCdWLEKhr4JWy9B+I/bE=; b=1n2xxM8aaDs4BLGabyVZNryO+obcpz0mIGH5JB3gJ5teDnzota3x6wRBABpaEeomf9 ZV+8/swS72GvKMlau0uCt3JxUsiJkekjRsi4c1oziYEbu1Ny49CpRx0aSKlnFBb99KDf LGkpvigFnD9kmEskB1aD0ISvyAGWa5Qw39bJ+ZrL2q49UqJwSDDbRcGGQvN4Z+02aZnr SUbYlhXrFkD1J/BcHyDtZiaGK0F37kNJHsS0exD3V/AJl4Wz5T6wXIgUVbUTp/aPux0W R4GnCG59A/k4izZ+q9MaBYzD/Q+l3R+zgv5OVwzvxY7bExmabqUHRgPjjLmuBqoYyjqJ p5ow== X-Gm-Message-State: ACrzQf1ioT2tmcHOezN/Nqk8IArnRP49/rO4y42HKhcxZMZrEkTc2kGY Hnpijnsjy+W2FUEWiSIeTlwIhipXXjVTWojpKlmH3Ufz6+UC/5v2314KUkPhhh0xcCtRP4QGavG Odhs+17QtGPXZPNus+1jxaZtfA7TnfaDSXnj9qTxn34XM24jXY4WjUw6psj9rtpcYId+Tgw== X-Received: by 2002:a05:6e02:1c2d:b0:2f6:572b:1931 with SMTP id m13-20020a056e021c2d00b002f6572b1931mr2443997ilh.209.1663873164537; Thu, 22 Sep 2022 11:59:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4rQCQgt+xIvnzcprDF3TtNCdd/dv05Cci1oLb4gAAwYonKs55Y7H0LKuestfS4qBE2r4rGIg== X-Received: by 2002:a05:6e02:1c2d:b0:2f6:572b:1931 with SMTP id m13-20020a056e021c2d00b002f6572b1931mr2443986ilh.209.1663873164261; Thu, 22 Sep 2022 11:59:24 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id t1-20020a028781000000b003428c21ed12sm2502209jai.167.2022.09.22.11.59.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 11:59:23 -0700 (PDT) Message-ID: <78509fb2-e386-0cbe-db5f-abca5cfe48f6@redhat.com> Date: Thu, 22 Sep 2022 14:59:22 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 05/17] Add missing float fold_range prototype for floats. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.5 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Unary operations require op2 to be the range of the type of the LHS. This is so the type for the LHS can be properly set.  There are is a missing prototype for this combination. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From be2a25adbdc76a770f7470cc9f47892f7a4139ae Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 12:34:08 -0400 Subject: [PATCH 05/17] Add missing float fold_range prototype for floats. Unary operations require op2 to be the range of the type of the LHS. This is so the type for the LHS can be properly set. * range-op-float.cc (range_operator_float::fold_range): New base method for "int = float op int". * range-op.cc (range_op_handler::fold_range): New case. * range-op.h: Update prototypes. --- gcc/range-op-float.cc | 10 ++++++++++ gcc/range-op.cc | 13 ++++++++++--- gcc/range-op.h | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 2bd3dc9253f..aa5b7ed073d 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -58,6 +58,16 @@ range_operator_float::fold_range (frange &r ATTRIBUTE_UNUSED, return false; } +bool +range_operator_float::fold_range (irange &r ATTRIBUTE_UNUSED, + tree type ATTRIBUTE_UNUSED, + const frange &lh ATTRIBUTE_UNUSED, + const irange &rh ATTRIBUTE_UNUSED, + relation_kind rel ATTRIBUTE_UNUSED) const +{ + return false; +} + bool range_operator_float::fold_range (irange &r ATTRIBUTE_UNUSED, tree type ATTRIBUTE_UNUSED, diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 9ae42b8331f..072ebd32109 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4208,9 +4208,16 @@ range_op_handler::fold_range (vrange &r, tree type, as_a (rh), rel); if (is_a (r)) - return m_float->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); + { + if (is_a (rh)) + return m_float->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + else + return m_float->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + } return m_float->fold_range (as_a (r), type, as_a (lh), as_a (rh), rel); diff --git a/gcc/range-op.h b/gcc/range-op.h index b4b5101a9e0..b2f063afb07 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -117,6 +117,11 @@ public: const frange &lh, const frange &rh, relation_kind rel = VREL_VARYING) const; + // Unary operations have the range of the LHS as op2. + virtual bool fold_range (irange &r, tree type, + const frange &lh, + const irange &rh, + relation_kind rel = VREL_VARYING) const; virtual bool fold_range (irange &r, tree type, const frange &lh, const frange &rh, -- 2.37.3 From patchwork Thu Sep 22 19:00:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681290 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=2620:52:3:1:0:246e:9693:128c; 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=NhaTpZF5; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPlv5NvVz1yqL for ; Fri, 23 Sep 2022 05:02:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AB753857BA1 for ; Thu, 22 Sep 2022 19:02:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AB753857BA1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873320; bh=q9jcDor9udpn1yLfD6osPFEGPymjGpENs6e98L6SQVs=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NhaTpZF5b1WtND5js5arfyYT/hh+kp7d6ergzVhnwmgmxEbMSCDlZCkdfteoxK55k r5A/LSqL0iyWy3YCM550kabHBi9fZ9cnO+3TaOGDRRpOm2ZPlu+OKHG4KEbLb8fuir vJWr/xB+PcltwpTfpdQk7OB0caoZhIG7GHrykhrE= 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 4CBBF3858400 for ; Thu, 22 Sep 2022 19:00:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4CBBF3858400 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-114-a3M6QIedP6GatNpJI3MnBQ-1; Thu, 22 Sep 2022 15:00:31 -0400 X-MC-Unique: a3M6QIedP6GatNpJI3MnBQ-1 Received: by mail-il1-f200.google.com with SMTP id k3-20020a056e02156300b002f5623faa62so6247685ilu.0 for ; Thu, 22 Sep 2022 12:00:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=lDKFnSHxu1YlwOOfaG35eg/oUUBm3ZcoQ+S4wNGrQcU=; b=Y/ja2bA9Xf+1IWh1hMwDqpFjss+S1PUjQ+cczHJWappi+sEI1fTuKuOoVjUhGEMjCY gJn1rScyan0k/f8jFBIOsfNgo90dJyBxS8C2fqDO6A/K1Ob86FLwn+As3cdTsJALTUf7 pQsmTk0/DMjmN2wgrBUuzMvZD0EHsd0+dekfP7m19xUCLsV9ZVDBbWkulzYIVXMyrFE4 rSBgm4b0yZiJYl3qwqLrjVVKbslKWn3cDCMIVVyFYnwS0vojW4ulNBcWpc5MeFA1JWt9 qaJCpVNAbcnjWSTsPEPOnTCKQ3Yd/RIW6QvmXMWA95cZAiLUoXmeESZKoxrynfKPo4Y4 uVXQ== X-Gm-Message-State: ACrzQf2RwBNv48M2MdNFzbaFeWQ/0916dUtSSRs3ovfbWLeWrUW6Kfn+ 0jgkwsCXlrTn5shgcpCWLZeSzAEXvrW5zvrnm45qcV5BM43K/lfBc/saMG1tH2zt3tRekNyKPBQ 4xzBICXCL3J/6+iWtjZ6XgTc7vTXF3UNyA1dRswBbsjEYtDmUYQQdJVgodIX9synCfR7Dvw== X-Received: by 2002:a92:c266:0:b0:2f5:f5eb:3510 with SMTP id h6-20020a92c266000000b002f5f5eb3510mr2413049ild.24.1663873229801; Thu, 22 Sep 2022 12:00:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Db7OZaf6LxVQ/b+5O7XY0yGJKwzF6p2qrrxwoKNRyS45HyaBaD4SI831bylntXBubeAi/sw== X-Received: by 2002:a92:c266:0:b0:2f5:f5eb:3510 with SMTP id h6-20020a92c266000000b002f5f5eb3510mr2413037ild.24.1663873229591; Thu, 22 Sep 2022 12:00:29 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id n17-20020a027151000000b0034c14a6ea76sm2463362jaf.51.2022.09.22.12.00.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:00:28 -0700 (PDT) Message-ID: <35eb7b99-9e99-dded-2dbc-1bc400df0a48@redhat.com> Date: Thu, 22 Sep 2022 15:00:27 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 06/17] Always check the return value of fold_range. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.6 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" The fold_range routine in range-ops returns FALSE if the operation fails.  There are a few places which assume the operation was successful.  Fix those. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 2f92f685da2ef9e82ee6262519919180df8f2dd9 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 21 Sep 2022 16:15:02 -0400 Subject: [PATCH 06/17] Always check the return value of fold_range. The fold_range routine in range-ops returns FALSE if the operation fails. There are a few places which assume the operation was successful. Fix those. * gimple-range-fold.cc (range_of_range_op): Set result to VARYING if the call to fold_range fails. * tree-data-ref.cc (compute_distributive_range): Ditto. * tree-vrp.cc (range_fold_binary_expr): Ditto. (range_fold_unary_expr): Ditto. * value-query.cc (range_query::get_tree_range): Ditto. --- gcc/gimple-range-fold.cc | 6 ++++-- gcc/tree-data-ref.cc | 6 ++++-- gcc/tree-vrp.cc | 6 ++++-- gcc/value-query.cc | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index addf3e7f254..42408254c35 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -544,7 +544,8 @@ fold_using_range::range_of_range_op (vrange &r, // Fold range, and register any dependency if available. Value_Range r2 (type); r2.set_varying (type); - handler.fold_range (r, type, range1, r2); + if (!handler.fold_range (r, type, range1, r2)) + r.set_varying (type); if (lhs && gimple_range_ssa_p (op1)) { if (src.gori ()) @@ -567,7 +568,8 @@ fold_using_range::range_of_range_op (vrange &r, fputc ('\n', dump_file); } // Fold range, and register any dependency if available. - handler.fold_range (r, type, range1, range2, rel); + if (!handler.fold_range (r, type, range1, range2, rel)) + r.set_varying (type); if (irange::supports_p (type)) relation_fold_and_or (as_a (r), s, src); if (lhs) diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc index ff9327f6deb..91bfb619d66 100644 --- a/gcc/tree-data-ref.cc +++ b/gcc/tree-data-ref.cc @@ -594,7 +594,8 @@ compute_distributive_range (tree type, value_range &op0_range, if (result_range) { range_op_handler op (code, type); - op.fold_range (*result_range, type, op0_range, op1_range); + if (!op.fold_range (*result_range, type, op0_range, op1_range)) + result_range->set_varying (type); } /* The distributive property guarantees that if TYPE is no narrower @@ -642,7 +643,8 @@ compute_distributive_range (tree type, value_range &op0_range, range_op_handler op (code, ssizetype); bool saved_flag_wrapv = flag_wrapv; flag_wrapv = 1; - op.fold_range (wide_range, ssizetype, op0_range, op1_range); + if (!op.fold_range (wide_range, ssizetype, op0_range, op1_range)) + wide_range.set_varying (ssizetype);; flag_wrapv = saved_flag_wrapv; if (wide_range.num_pairs () != 1 || !range_int_cst_p (&wide_range)) return false; diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index c3030a1b130..93482e5d102 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -1069,7 +1069,8 @@ range_fold_binary_expr (value_range *vr, vr1.set_varying (expr_type); vr0.normalize_addresses (); vr1.normalize_addresses (); - op.fold_range (*vr, expr_type, vr0, vr1); + if (!op.fold_range (*vr, expr_type, vr0, vr1)) + vr->set_varying (expr_type); } /* Perform a unary operation on a range. */ @@ -1095,7 +1096,8 @@ range_fold_unary_expr (value_range *vr, value_range vr0_cst (*vr0); vr0_cst.normalize_addresses (); - op.fold_range (*vr, expr_type, vr0_cst, value_range (expr_type)); + if (!op.fold_range (*vr, expr_type, vr0_cst, value_range (expr_type))) + vr->set_varying (expr_type); } /* If the range of values taken by OP can be inferred after STMT executes, diff --git a/gcc/value-query.cc b/gcc/value-query.cc index 0bdd670982b..296784be31d 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -252,7 +252,8 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) Value_Range r1 (TREE_TYPE (TREE_OPERAND (expr, 1))); range_of_expr (r0, TREE_OPERAND (expr, 0), stmt); range_of_expr (r1, TREE_OPERAND (expr, 1), stmt); - op.fold_range (r, type, r0, r1); + if (!op.fold_range (r, type, r0, r1)) + r.set_varying (type); } else r.set_varying (type); @@ -268,7 +269,8 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) Value_Range r1 (type); r1.set_varying (type); range_of_expr (r0, TREE_OPERAND (expr, 0), stmt); - op.fold_range (r, type, r0, r1); + if (!op.fold_range (r, type, r0, r1)) + r.set_varying (type); } else r.set_varying (type); -- 2.37.3 From patchwork Thu Sep 22 19:01:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681291 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=2620:52:3:1:0:246e:9693:128c; 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=RLACD8ez; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPm46vHnz1yqL for ; Fri, 23 Sep 2022 05:02:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EEF1A3858034 for ; Thu, 22 Sep 2022 19:02:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEF1A3858034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873331; bh=kK0FQJbAK71p8IOyH+H0aw9znpAxAoTdiSdzVUY+Nak=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RLACD8ezj4kLUUj6dHO/b/MqlmVjAb2D3o0092qorpMmkOKkuKa1Yp8yE0duCyf/q ULcMwXRY7makM7JBVmOzFgTZ940gubkcKG6j9HnIbmj+N1kxq310VZNZAIHPdc0HJV c+iJb26UopAcK33+ZkfgzxOV+b6ZIIt+vU1uQzlg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 9372538582B2 for ; Thu, 22 Sep 2022 19:01:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9372538582B2 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-275-jaBIDfLDO-irhBEidCgNIQ-1; Thu, 22 Sep 2022 15:01:40 -0400 X-MC-Unique: jaBIDfLDO-irhBEidCgNIQ-1 Received: by mail-io1-f71.google.com with SMTP id e15-20020a5d8acf000000b006a3ed059e49so1632193iot.14 for ; Thu, 22 Sep 2022 12:01:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=XwpzxSles3mwN9YpT4Vbd8BI7WiDolADYXFnosYLvgw=; b=bN2dfJOASqgVpuw/t/bsVQJPvqIiq8BlmRRRSIUZ+7v8UcRKwtzmyFUVIRrIpyD+Dp 0qbCV8HNBjt1OO9o22eg5n0moKY5Hn5itOiAiQTZgTrKuPdH8igI1J9yMAWjjlf0F+Qy QQz+tllK5wwa+ypQPNIBv1jcFV/bbs3WO4R+YlZvWbzhOgjYH78+hP8Hktpr8+Y5ZxPt 725H4N7OfmdCuqWOiDoCqSrRgAbRA9FUXc7XYbEQfWODBnHSle4bntNz8M1LVRyxNcsz uksQr+yi/FPWutHABIVfPXiKS5cIxMqEotUyjR5s256tM8gKB5CRxHtfv5g91nNr28kH ZaSA== X-Gm-Message-State: ACrzQf1WxZ9AY2dFuWsMO9nU42B0UtxBwTdYt3SAjqXAnAaEZhb5vzBC z6+6NV1oMXoqh9bLYkYWOE42+ZDcMJFz19kKe68pE8asVh1lDc6UQ0/E48dbX5rRofSctJGVEUt NR/9qPKD8KWUqFOGkXGcdeUTJYIk8y9oWbaQL6yJ6w4yR6rXACOwDSolRHMP57+yLos2UCQ== X-Received: by 2002:a05:6602:1594:b0:6a1:ce0d:e1b4 with SMTP id e20-20020a056602159400b006a1ce0de1b4mr2313219iow.104.1663873299552; Thu, 22 Sep 2022 12:01:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UhRJG30IcfmOQz8tWsI2GfqWjQ9lxU0d2oagqr60pm3GFTW2aaUtOSn1H9vpigPEVFtM5aw== X-Received: by 2002:a05:6602:1594:b0:6a1:ce0d:e1b4 with SMTP id e20-20020a056602159400b006a1ce0de1b4mr2313203iow.104.1663873299219; Thu, 22 Sep 2022 12:01:39 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id l187-20020a6b3ec4000000b006a102cb4900sm2647261ioa.39.2022.09.22.12.01.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:01:38 -0700 (PDT) Message-ID: <4ca8b041-459d-6fbc-794f-d1d93a266f95@redhat.com> Date: Thu, 22 Sep 2022 15:01:37 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 07/17] Add range-ops support for builtin functions. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.6 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Check for builtins that can be a range-op entry and Convert CFN_BUILT_IN_CONSTANT_P as first POC. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From b40b3035879cf695b72010858b9705a344292bdb Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 16:53:37 -0400 Subject: [PATCH 07/17] Add range-ops support for builtin functions. Convert CFN_BUILT_IN_CONSTANT_P as first POC. * gimple-range-fold.cc (fold_using_range::range_of_builtin_int_call): Remove case for CFN_BUILT_IN_CONSTANT_P. * gimple-range-op.cc (gimple_range_op_handler::supported_p): Check if a call also creates a range-op object. (gimple_range_op_handler): Also check builtin calls. (class cfn_constant_float_p): New. Float CFN_BUILT_IN_CONSTANT_P. (class cfn_constant_p): New. Integral CFN_BUILT_IN_CONSTANT_P. (gimple_range_op_handler::maybe_builtin_call): Set arguments and handler for supported built-in calls. * gimple-range-op.h (maybe_builtin_call): New prototype. --- gcc/gimple-range-fold.cc | 17 ------- gcc/gimple-range-op.cc | 104 ++++++++++++++++++++++++++++++++++++--- gcc/gimple-range-op.h | 1 + 3 files changed, 97 insertions(+), 25 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 42408254c35..63a1f517d28 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -944,23 +944,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, switch (func) { - case CFN_BUILT_IN_CONSTANT_P: - { - arg = gimple_call_arg (call, 0); - Value_Range tmp (TREE_TYPE (arg)); - if (src.get_operand (tmp, arg) && tmp.singleton_p ()) - { - r.set (build_one_cst (type), build_one_cst (type)); - return true; - } - if (cfun->after_inlining) - { - r.set_zero (type); - return true; - } - break; - } - case CFN_BUILT_IN_SIGNBIT: { arg = gimple_call_arg (call, 0); diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index ab5b389449d..bcc4c3d778c 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -123,7 +123,11 @@ gimple_range_op_handler::supported_p (gimple *s) { enum tree_code code; tree type = get_code_and_type (s, code); - return (type && range_op_handler (code, type)); + if (type && range_op_handler (code, type)) + return true; + if (is_a (s) && gimple_range_op_handler (s)) + return true; + return false; } // Construct a handler object for statement S. @@ -133,6 +137,8 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) enum tree_code code; tree type = get_code_and_type (s, code); m_stmt = s; + m_op1 = NULL_TREE; + m_op2 = NULL_TREE; if (type) set_op_handler (code, type); @@ -142,7 +148,7 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) case GIMPLE_COND: m_op1 = gimple_cond_lhs (m_stmt); m_op2 = gimple_cond_rhs (m_stmt); - break; + return; case GIMPLE_ASSIGN: m_op1 = gimple_range_base_of_assignment (m_stmt); if (m_op1 && TREE_CODE (m_op1) == MEM_REF) @@ -158,14 +164,15 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) } if (gimple_num_ops (m_stmt) >= 3) m_op2 = gimple_assign_rhs2 (m_stmt); - else - m_op2 = NULL_TREE; - break; + return; default: - m_op1 = NULL_TREE; - m_op2 = NULL_TREE; - break; + gcc_unreachable (); + return; } + // If no range-op table entry handled this stmt, check for other supported + // statements. + if (is_a (m_stmt)) + maybe_builtin_call (); } // Calculate what we can determine of the range of this unary @@ -247,3 +254,84 @@ gimple_range_op_handler::calc_op2 (vrange &r, const vrange &lhs_range, } return op2_range (r, type, lhs_range, op1_range); } + +// -------------------------------------------------------------------- + +// Implement range operator for float CFN_BUILT_IN_CONSTANT_P. +class cfn_constant_float_p : public range_operator_float +{ +public: + using range_operator_float::fold_range; + virtual bool fold_range (irange &r, tree type, const frange &lh, + const irange &, relation_kind) const + { + if (lh.singleton_p ()) + { + r.set (build_one_cst (type), build_one_cst (type)); + return true; + } + if (cfun->after_inlining) + { + r.set_zero (type); + return true; + } + return false; + } +} op_cfn_constant_float_p; + +// Implement range operator for integral CFN_BUILT_IN_CONSTANT_P. +class cfn_constant_p : public range_operator +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const + { + if (lh.singleton_p ()) + { + r.set (build_one_cst (type), build_one_cst (type)); + return true; + } + if (cfun->after_inlining) + { + r.set_zero (type); + return true; + } + return false; + } +} op_cfn_constant_p; + +// Set up a gimple_range_op_handler for any built in function which can be +// supported via range-ops. + +void +gimple_range_op_handler::maybe_builtin_call () +{ + gcc_checking_assert (is_a (m_stmt)); + + gcall *call = as_a (m_stmt); + combined_fn func = gimple_call_combined_fn (call); + if (func == CFN_LAST) + return; + tree type = gimple_range_type (call); + gcc_checking_assert (type); + if (!Value_Range::supports_type_p (type)) + return; + + switch (func) + { + case CFN_BUILT_IN_CONSTANT_P: + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + if (irange::supports_p (TREE_TYPE (m_op1))) + m_int = &op_cfn_constant_p; + else if (frange::supports_p (TREE_TYPE (m_op1))) + m_float = &op_cfn_constant_float_p; + else + m_valid = false; + break; + + default: + break; + } +} diff --git a/gcc/gimple-range-op.h b/gcc/gimple-range-op.h index 8bc0a8fbe11..68764198bc0 100644 --- a/gcc/gimple-range-op.h +++ b/gcc/gimple-range-op.h @@ -38,6 +38,7 @@ public: bool calc_op1 (vrange &r, const vrange &lhs_range, const vrange &op2_range); bool calc_op2 (vrange &r, const vrange &lhs_range, const vrange &op1_range); private: + void maybe_builtin_call (); gimple *m_stmt; tree m_op1, m_op2; }; -- 2.37.3 From patchwork Thu Sep 22 19:02:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681292 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=bBtyGB1s; dkim-atps=neutral Received: from sourceware.org (server2.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 4MYPms6VG7z1yqL for ; Fri, 23 Sep 2022 05:02:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5613A3857B92 for ; Thu, 22 Sep 2022 19:02:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5613A3857B92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873370; bh=Qo2qJoUAE13yQ8d8RmgiiYZr5+d9hJzr9DE3ndGWU3I=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bBtyGB1sIl2yz+iZptGtFqsWYwO6p5gaFYZpIspyjB50t5jODqxSLQL2qgmcX0ICj E7tXRm+0o6frdHdY1GyCo6JLUV6QeeKedWw3+8WAoIZfuxYxYxXS8LzO/J4LnIwU7p Lfw9yXs/RC4BNnRI7a8DOtLcE69NbPscJZuoZW+U= 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 C931A385740D for ; Thu, 22 Sep 2022 19:02:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C931A385740D Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-10-LUtvPp1OPPmwA8Oc3klXGQ-1; Thu, 22 Sep 2022 15:02:29 -0400 X-MC-Unique: LUtvPp1OPPmwA8Oc3klXGQ-1 Received: by mail-il1-f197.google.com with SMTP id c7-20020a056e020bc700b002e59be6ce85so6207444ilu.12 for ; Thu, 22 Sep 2022 12:02:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=gOTKVw/7qrhGV3e6oQ72kHHXix+crqUhcS8b4smtwGE=; b=AZnGFZmit/uW1DsboPi5pFk2jtFhxj3f2GRIbqM+27MWQJyovNS6Ln/OsRnkGsBsIn JLYtHuugmZho9PR2D+WL3a0uMHJdbWbb5V3E4pfgIgwfOGRNSrD5j3CFtQduQGf4eTc8 8Ec3m4gcZmY3dV2NIOmO/FAHSQFU5l0STo6IxT3JbQ5OEPC5cZvw0gaJBsVM04m+Letg X8a7NPr9Fc1RJbYo+gB8cb6Jt4J74/k0QRpZkMPcr7gCZpOApgwnfpKeW8fqC3nfpnAM +xxwAZ5urc2Emb7cjsNfTHC/TNemZhewje9zK/BG1xFSpvhKpgt8ABXp2h4iCb/Hw1i5 0jLA== X-Gm-Message-State: ACrzQf095dv0lnerns6pQoxp5GudELvHQ6XNH46KjdiMxIeD6Xynnse+ WZzytDQ6aAMoRjFPWdees0mEoxA/04GOR7UURz9TzxO7Cr0DrRZRFvh8Fq8cq5799Xcppe0lXPB 1CgUTLYMNdqPD9qeeC8l/6+g0omiwu7DqcYMA96jIVvEpsMY9LKl0tQbNVK9UwUl8OYr56g== X-Received: by 2002:a05:6638:140a:b0:35a:79fd:d4d9 with SMTP id k10-20020a056638140a00b0035a79fdd4d9mr2864336jad.135.1663873346932; Thu, 22 Sep 2022 12:02:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5hjdvUZrSMeAez1s8VIr+VFh9XsNnBpsTkRGe69fbzY2pML6rHjo6rPbmlCfO+MrXcPb6W9w== X-Received: by 2002:a05:6638:140a:b0:35a:79fd:d4d9 with SMTP id k10-20020a056638140a00b0035a79fdd4d9mr2864317jad.135.1663873346680; Thu, 22 Sep 2022 12:02:26 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id w14-20020a022a0e000000b0034c0e8829c0sm2543310jaw.0.2022.09.22.12.02.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:02:25 -0700 (PDT) Message-ID: <37539494-f250-1f45-1dbd-e3f82c296136@redhat.com> Date: Thu, 22 Sep 2022 15:02:23 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 08/17] Convert CFN_BUILT_IN_SIGNBIT to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.6 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From eb82b9f68eb8d0cc65a1a022154c8e729860ea59 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 21 Sep 2022 09:29:40 -0400 Subject: [PATCH 08/17] Convert CFN_BUILT_IN_SIGNBIT to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_BUILT_IN_SIGNBIT. * gimple-range-op.cc (class cfn_signbit): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 20 -------------------- gcc/gimple-range-op.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 63a1f517d28..417a925ac9f 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -944,26 +944,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, switch (func) { - case CFN_BUILT_IN_SIGNBIT: - { - arg = gimple_call_arg (call, 0); - frange tmp; - if (src.get_operand (tmp, arg)) - { - bool signbit; - if (tmp.signbit_p (signbit)) - { - if (signbit) - r.set_nonzero (type); - else - r.set_zero (type); - return true; - } - return false; - } - break; - } - case CFN_BUILT_IN_TOUPPER: { arg = gimple_call_arg (call, 0); diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index bcc4c3d778c..d62dff5f92e 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -301,6 +301,27 @@ public: } } op_cfn_constant_p; +// Implement range operator for CFN_BUILT_IN_SIGNBIT. +class cfn_signbit : public range_operator_float +{ +public: + using range_operator_float::fold_range; + virtual bool fold_range (irange &r, tree type, const frange &lh, + const irange &, relation_kind) const + { + bool signbit; + if (lh.signbit_p (signbit)) + { + if (signbit) + r.set_nonzero (type); + else + r.set_zero (type); + return true; + } + return false; + } +} op_cfn_signbit; + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -331,6 +352,12 @@ gimple_range_op_handler::maybe_builtin_call () m_valid = false; break; + case CFN_BUILT_IN_SIGNBIT: + m_op1 = gimple_call_arg (call, 0); + m_float = &op_cfn_signbit; + m_valid = true; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:05:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681294 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=2620:52:3:1:0:246e:9693:128c; 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=Q7Ibj6ff; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPr14ndpz1yqH for ; Fri, 23 Sep 2022 05:05:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A25A23857427 for ; Thu, 22 Sep 2022 19:05:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A25A23857427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873532; bh=rOU9oQ28uz5Lj5xeL1DV8G/MK5weGXp3Rz66r99dohA=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Q7Ibj6ffWNHwe8l4cpwTIjYHCbG5+udgOXNsUUfJpxw/YroHfc8r2j+2P72myb7IE NfDUA6UqmH0xd3SEFIhVGAqnUUq4yCOt8cIR46QT8i/AHadayucQ0MkFfVIHBPq68/ 9wNYWc46hvh74wFVoywAwDB6xJQwyG4ZsuJBKeCI= 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 136523858D38 for ; Thu, 22 Sep 2022 19:05:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 136523858D38 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-280-VghFO8FcN4u8Bo0DMNH0fg-1; Thu, 22 Sep 2022 15:05:11 -0400 X-MC-Unique: VghFO8FcN4u8Bo0DMNH0fg-1 Received: by mail-io1-f70.google.com with SMTP id e14-20020a6b500e000000b006a13488a320so5255282iob.12 for ; Thu, 22 Sep 2022 12:05:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=5A6g9okRxuw7nwmv3WZG55WH3BZM30HH8oaRwpCg/os=; b=gNG9XC5H5To6Bw2rB/R80WiVLEcOaoV1AQoKHawN+v2DYHAAvWa9Gb6PrphdoDFSj+ 3UrT3LLeTktizMpSbPTc6+EGy4HXYdszjGWHKDQyHlr7QtSSsp+Bo2MnwqlSnOvHEeX3 KA5ebir4CZz7EEgbs0hqR0qI653CdMbiUbyKbq4GyvSwHZ26JTHwIHe3bK7IZlS8CjQq Fg8aaoMC9zCV7vQ374vXRv11fDdXoM/X5cFpelq2gQqqV5HaoWGutDvboi0Qhat5j40i KqZ0Dr+zWWUjw1hFTiJoxDJeT5R6dfScfrMtbzpsWqGZUQFO8r7StEOCqOs0WyDio1vs KuZA== X-Gm-Message-State: ACrzQf2j796J/FyQ3Ji1i0bwDyn+J6IVGdCOgErMhk5QXaldVbCbHr39 LcvBWwEhsQupcdGTn9cosgte9iyW00Z7KxuR6/cy9jqlWOupnjUIKcLkGAGz0a2fugDEs9qfFwQ aD77MGTvxmGNjnzU7+KQIGixBFkQ106QzANLv8Bdn0xBe5kbTYnGov54y4yqtVDpZorxi1g== X-Received: by 2002:a05:6638:4192:b0:34a:4959:edf5 with SMTP id az18-20020a056638419200b0034a4959edf5mr2750284jab.193.1663873510369; Thu, 22 Sep 2022 12:05:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM672Mm37y8iXyNfZdUYC1hK9yB9ZZCpuCNqNFt0wzm28/lQEphqaiMcD52AIR+nCKG8ILh2RA== X-Received: by 2002:a05:6638:4192:b0:34a:4959:edf5 with SMTP id az18-20020a056638419200b0034a4959edf5mr2750270jab.193.1663873510090; Thu, 22 Sep 2022 12:05:10 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id i124-20020a6bb882000000b006a0cd2ab8dfsm2619469iof.8.2022.09.22.12.05.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:05:09 -0700 (PDT) Message-ID: <99671c98-c81e-1fa3-b851-263492a54669@redhat.com> Date: Thu, 22 Sep 2022 15:05:08 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 09/17] Convert CFN_BUILT_IN_TOUPPER and TOLOWER to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 2f5da730f159de238500c82b0c6ef6c9ab91b1c2 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 17:14:30 -0400 Subject: [PATCH 09/17] Convert CFN_BUILT_IN_TOUPPER and TOLOWER to range-ops. * gimple-range-fold.cc (get_letter_range): Move to new class. (range_of_builtin_int_call): Remove case for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. * gimple-range-op.cc (class cfn_toupper_tolower): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 66 ---------------------------------- gcc/gimple-range-op.cc | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 66 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 417a925ac9f..af1f83f7409 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -887,28 +887,6 @@ fold_using_range::range_of_builtin_ubsan_call (irange &r, gcall *call, r.set_varying (type); } -// Return TRUE if we recognize the target character set and return the -// range for lower case and upper case letters. - -static bool -get_letter_range (tree type, irange &lowers, irange &uppers) -{ - // ASCII - int a = lang_hooks.to_target_charset ('a'); - int z = lang_hooks.to_target_charset ('z'); - int A = lang_hooks.to_target_charset ('A'); - int Z = lang_hooks.to_target_charset ('Z'); - - if ((z - a == 25) && (Z - A == 25)) - { - lowers = int_range<2> (build_int_cst (type, a), build_int_cst (type, z)); - uppers = int_range<2> (build_int_cst (type, A), build_int_cst (type, Z)); - return true; - } - // Unknown character set. - return false; -} - // For a builtin in CALL, return a range in R if known and return // TRUE. Otherwise return FALSE. @@ -944,50 +922,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, switch (func) { - case CFN_BUILT_IN_TOUPPER: - { - arg = gimple_call_arg (call, 0); - // If the argument isn't compatible with the LHS, do nothing. - if (!range_compatible_p (type, TREE_TYPE (arg))) - return false; - if (!src.get_operand (r, arg)) - return false; - - int_range<3> lowers; - int_range<3> uppers; - if (!get_letter_range (type, lowers, uppers)) - return false; - - // Return the range passed in without any lower case characters, - // but including all the upper case ones. - lowers.invert (); - r.intersect (lowers); - r.union_ (uppers); - return true; - } - - case CFN_BUILT_IN_TOLOWER: - { - arg = gimple_call_arg (call, 0); - // If the argument isn't compatible with the LHS, do nothing. - if (!range_compatible_p (type, TREE_TYPE (arg))) - return false; - if (!src.get_operand (r, arg)) - return false; - - int_range<3> lowers; - int_range<3> uppers; - if (!get_letter_range (type, lowers, uppers)) - return false; - - // Return the range passed in without any upper case characters, - // but including all the lower case ones. - uppers.invert (); - r.intersect (uppers); - r.union_ (lowers); - return true; - } - CASE_CFN_FFS: CASE_CFN_POPCOUNT: // __builtin_ffs* and __builtin_popcount* return [0, prec]. diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index d62dff5f92e..45384d990ae 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -322,6 +322,71 @@ public: } } op_cfn_signbit; +// Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. +class cfn_toupper_tolower : public range_operator +{ +public: + using range_operator::fold_range; + cfn_toupper_tolower (bool toupper) { m_toupper = toupper; } + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const; +private: + bool get_letter_range (tree type, irange &lowers, irange &uppers) const; + bool m_toupper; +} op_cfn_toupper (true), op_cfn_tolower (false); + +// Return TRUE if we recognize the target character set and return the +// range for lower case and upper case letters. + +bool +cfn_toupper_tolower::get_letter_range (tree type, irange &lowers, + irange &uppers) const +{ + // ASCII + int a = lang_hooks.to_target_charset ('a'); + int z = lang_hooks.to_target_charset ('z'); + int A = lang_hooks.to_target_charset ('A'); + int Z = lang_hooks.to_target_charset ('Z'); + + if ((z - a == 25) && (Z - A == 25)) + { + lowers = int_range<2> (build_int_cst (type, a), build_int_cst (type, z)); + uppers = int_range<2> (build_int_cst (type, A), build_int_cst (type, Z)); + return true; + } + // Unknown character set. + return false; +} + +bool +cfn_toupper_tolower::fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const +{ + int_range<3> lowers; + int_range<3> uppers; + if (!get_letter_range (type, lowers, uppers)) + return false; + + r = lh; + if (m_toupper) + { + // Return the range passed in without any lower case characters, + // but including all the upper case ones. + lowers.invert (); + r.intersect (lowers); + r.union_ (uppers); + } + else + { + // Return the range passed in without any lower case characters, + // but including all the upper case ones. + uppers.invert (); + r.intersect (uppers); + r.union_ (lowers); + } + return true; +} + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -358,6 +423,18 @@ gimple_range_op_handler::maybe_builtin_call () m_valid = true; break; + case CFN_BUILT_IN_TOUPPER: + case CFN_BUILT_IN_TOLOWER: + // Only proceed If the argument is compatible with the LHS. + m_op1 = gimple_call_arg (call, 0); + if (range_compatible_p (type, TREE_TYPE (m_op1))) + { + m_valid = true; + m_int = (func == CFN_BUILT_IN_TOLOWER) ? &op_cfn_tolower + : &op_cfn_toupper; + } + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:05:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681295 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=2620:52:3:1:0:246e:9693:128c; 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=L2+K7c0J; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPr372Kwz1yqH for ; Fri, 23 Sep 2022 05:05:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 076263857433 for ; Thu, 22 Sep 2022 19:05:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 076263857433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873538; bh=LsOZp2JtsO6VBUMkx8tPJpe4IHJUHdVy3gCb02yPxWc=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=L2+K7c0J1HpcKESf9ccSwPuSROdTfivyPfoCXNKl08XWciFiGGWYFcsftwuQ3X4io M/c3jVuln3mAZBHTM828kR5Me07W+p1wHKR/2oUNYgg9EsyPc875FZvg/KFykYMOLQ Yu++3Nss+NYmu/rkOEOZUuMzUbiHx4dM2DBsRbd8= 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 4B32F3858400 for ; Thu, 22 Sep 2022 19:05:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4B32F3858400 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-156-oJUbHKoJP7mHptMBUcKa1Q-1; Thu, 22 Sep 2022 15:05:17 -0400 X-MC-Unique: oJUbHKoJP7mHptMBUcKa1Q-1 Received: by mail-io1-f69.google.com with SMTP id y1-20020a056602200100b006893cd97da9so5261457iod.1 for ; Thu, 22 Sep 2022 12:05:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=lQfDA1FuIxrlziwO84HaRm6i3hzLIXRRS5CP07BQ+fs=; b=KFhPAKY+MQvc+ay5LkLkRpPNR76YXRaX+WdQW5mT46PGkAUtZZLxlJIvgqClRq3nHu UCfK78MvjxOUsIt6VpuIpeaFewquGYzRKIZ4zswIMuIpogSKVxusIi936nVvP5gzkSIy YgP4LrEGZHrbVqyi+BmmCzo3hPD6t/8YkXCl2SUJcJ+Vy/DjrV+TpbZxk+fUynTj46x1 bVT/U4ld7kENmu8kuiLL79kAD6WlGeoqgavu7pxmpFVaTTPMrBLEDxauJuWcpaen4gQW BPWPA87TvkJEdVyqSd9LW2R6Msc1y94djO5sBKXDdRFfTMjRajHf5i9l3mPNzo82mXU9 srcg== X-Gm-Message-State: ACrzQf0Kws4RI8r1VRnMbspAr+YTHVnDF9oQQ5+3ubI8j5yoWsmuhU4X jmmH+r9/s7OWQdS5dpIUTfRgtV1AlFMyBOs1goJcxhqrNsCsBIRwf6JgsdayGWSkTeQ+lvBcuvs ozLFD2a7ImNoQNJrKka3O95XcJBwTblVF3Q69+veBE4iazThwih2xBLe24GQnTEQhu6Xtrw== X-Received: by 2002:a6b:c349:0:b0:689:d9f6:adf0 with SMTP id t70-20020a6bc349000000b00689d9f6adf0mr2230899iof.21.1663873515952; Thu, 22 Sep 2022 12:05:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4rPf02vskaJitPdudKyeRDFjYTkxSkbwcMBvXNfkuFQI4q9/iYJg9mhgkRrPaS1hhR8z/b0Q== X-Received: by 2002:a6b:c349:0:b0:689:d9f6:adf0 with SMTP id t70-20020a6bc349000000b00689d9f6adf0mr2230884iof.21.1663873515621; Thu, 22 Sep 2022 12:05:15 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id g17-20020a05663810f100b00349fb9b1abesm2532044jae.106.2022.09.22.12.05.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:05:14 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:05:13 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 10/17] Convert CFN_BUILT_FFS and CFN_POPCOUNT to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 5f730c650184d4c8bfad513a9e0e593f87a5bf0c Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 18:07:14 -0400 Subject: [PATCH 10/17] Convert CFN_BUILT_FFS and CFN_POPCOUNT to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_FFS and CFN_POPCOUNT. * gimple-range-op.cc (class cfn_pocount): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 22 ---------------------- gcc/gimple-range-op.cc | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index af1f83f7409..ca531037e13 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -922,28 +922,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, switch (func) { - CASE_CFN_FFS: - CASE_CFN_POPCOUNT: - // __builtin_ffs* and __builtin_popcount* return [0, prec]. - arg = gimple_call_arg (call, 0); - prec = TYPE_PRECISION (TREE_TYPE (arg)); - mini = 0; - maxi = prec; - src.get_operand (r, arg); - // If arg is non-zero, then ffs or popcount are non-zero. - if (!range_includes_zero_p (&r)) - mini = 1; - // If some high bits are known to be zero, decrease the maximum. - if (!r.undefined_p ()) - { - if (TYPE_SIGN (r.type ()) == SIGNED) - range_cast (r, unsigned_type_for (r.type ())); - wide_int max = r.upper_bound (); - maxi = wi::floor_log2 (max) + 1; - } - r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); - return true; - CASE_CFN_PARITY: r.set (build_zero_cst (type), build_one_cst (type)); return true; diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 45384d990ae..84837f8ee43 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -387,6 +387,33 @@ cfn_toupper_tolower::fold_range (irange &r, tree type, const irange &lh, return true; } +// Implement range operator for CFN_BUILT_IN_FFS and CFN_BUILT_IN_POPCOUNT. +class cfn_popcount : public range_operator +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const + { + if (lh.undefined_p ()) + return false; + // __builtin_ffs* and __builtin_popcount* return [0, prec]. + int prec = TYPE_PRECISION (lh.type ()); + // If arg is non-zero, then ffs or popcount are non-zero. + int mini = range_includes_zero_p (&lh) ? 0 : 1; + int maxi = prec; + + // If some high bits are known to be zero, decrease the maximum. + int_range_max tmp = lh; + if (TYPE_SIGN (tmp.type ()) == SIGNED) + range_cast (tmp, unsigned_type_for (tmp.type ())); + wide_int max = tmp.upper_bound (); + maxi = wi::floor_log2 (max) + 1; + r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); + return true; + } +} op_cfn_popcount; + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -435,6 +462,13 @@ gimple_range_op_handler::maybe_builtin_call () } break; + CASE_CFN_FFS: + CASE_CFN_POPCOUNT: + m_op1 = gimple_call_arg (call, 0); + m_int = &op_cfn_popcount; + m_valid = true; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:05:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681296 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=2620:52:3:1:0:246e:9693:128c; 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=B1m4m9OS; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPrC3ddrz1yqH for ; Fri, 23 Sep 2022 05:05:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F7683857363 for ; Thu, 22 Sep 2022 19:05:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F7683857363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873545; bh=Fr82gZ7Ayxx+pjyLoPlRoiCZJGRKeEn55dtAep4DGzc=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=B1m4m9OSmLrG1ZS34iwoShtEzoc2bstgviy0YibWoqDtpKJXXmcl69ks/SoIkubxv +h/0TQDwkpAYOHBXVdF3Nhjdj145WZnzLisrBYdNOcpDOMV5oZRnDYUNbxnyLDXc8r AsGQ3LcMr7NCNpIOrNEi1iZ721ZkmeUm3yZZnhz8= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id E59E13857BA2 for ; Thu, 22 Sep 2022 19:05:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E59E13857BA2 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-649-XWwJetiSMV23fOGeas0iDg-1; Thu, 22 Sep 2022 15:05:22 -0400 X-MC-Unique: XWwJetiSMV23fOGeas0iDg-1 Received: by mail-io1-f69.google.com with SMTP id n16-20020a6b5910000000b006a3570db9a5so5303637iob.23 for ; Thu, 22 Sep 2022 12:05:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=TwWGnmr01OJs6tPHGIjyk+CEI85LhO8bRskaSrMugd4=; b=BD2emNms+Efh3WgFINEcsMLWd7mYC5ynn9BeTij4OA1StcddR5MlJpo+WcArQXQU7b daavPzcpSJ1gkZSmruCj3u79ed5KefR+bMYbLxq/ib2DunEBJyhJVwPoZfXY8gGn30Cy PoZVgNQ2ylah0SRdbPEtl1Od9oLDKNulKIfTzFA+lPcsm6h3Dur0UXZD2cfo+Q/dHvQr RK233/6rPEoeLUk6yYEFfaLKzdKxhvgmWCopTek5PmfA6DP7Shl1lx46Gr4lGCmRjc/Q ftdZw7eEswc2NKzbhh+owd4QlINv1IgP4p6+UboDY9eWndgtA6NdWNtyinXxWdREAPkf PIlQ== X-Gm-Message-State: ACrzQf0gaYFIo6sZ4QIqZcb2bCB0XN9CZoqB+UihFpBFHHPurBXIrBEx tgTJNmiJ9XsrvVA1tmI3K3RNC/mcBADZ6ur/1GZdnpl6UV7wAbIbJ9rU6IFPqHtp4qlCyVBhNzu KSFgwxPhzakGeranrTbCzFHKhocXf6zb6EBx3XRko6AJdodvTuGjHOkxwZxdU82q4/CqEQw== X-Received: by 2002:a05:6e02:1886:b0:2eb:438a:c64c with SMTP id o6-20020a056e02188600b002eb438ac64cmr2424344ilu.282.1663873521469; Thu, 22 Sep 2022 12:05:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6A6WUaORQ80Ye5daju0un/bYQj7P/VbyMn8YfYG8s4ahKAQaqptDrxRVI1vzd0kXTImXxBzQ== X-Received: by 2002:a05:6e02:1886:b0:2eb:438a:c64c with SMTP id o6-20020a056e02188600b002eb438ac64cmr2424336ilu.282.1663873521184; Thu, 22 Sep 2022 12:05:21 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id n25-20020a02a199000000b0035ad8408d40sm2528487jah.108.2022.09.22.12.05.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:05:20 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:05:19 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 11/17] Convert CFN_CLZ builtins to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From ae1669a98656cca594fcd2fef6bd2cd7308a361f Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 18:12:25 -0400 Subject: [PATCH 11/17] Convert CFN_CLZ builtins to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_CLZ. * gimple-range-op.cc (class cfn_clz): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 61 ----------------------------- gcc/gimple-range-op.cc | 84 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index ca531037e13..63eaa90be96 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -926,67 +926,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, r.set (build_zero_cst (type), build_one_cst (type)); return true; - CASE_CFN_CLZ: - // __builtin_c[lt]z* return [0, prec-1], except when the - // argument is 0, but that is undefined behavior. - // - // For __builtin_c[lt]z* consider argument of 0 always undefined - // behavior, for internal fns depending on C?Z_DEFINED_VALUE_AT_ZERO. - arg = gimple_call_arg (call, 0); - prec = TYPE_PRECISION (TREE_TYPE (arg)); - mini = 0; - maxi = prec - 1; - mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (arg)); - if (gimple_call_internal_p (call)) - { - if (optab_handler (clz_optab, mode) != CODE_FOR_nothing - && CLZ_DEFINED_VALUE_AT_ZERO (mode, zerov) == 2) - { - // Only handle the single common value. - if (zerov == prec) - maxi = prec; - else - // Magic value to give up, unless we can prove arg is non-zero. - mini = -2; - } - } - - src.get_operand (r, arg); - // From clz of minimum we can compute result maximum. - if (!r.undefined_p ()) - { - // From clz of minimum we can compute result maximum. - if (wi::gt_p (r.lower_bound (), 0, TYPE_SIGN (r.type ()))) - { - maxi = prec - 1 - wi::floor_log2 (r.lower_bound ()); - if (mini == -2) - mini = 0; - } - else if (!range_includes_zero_p (&r)) - { - mini = 0; - maxi = prec - 1; - } - if (mini == -2) - break; - // From clz of maximum we can compute result minimum. - wide_int max = r.upper_bound (); - int newmini = prec - 1 - wi::floor_log2 (max); - if (max == 0) - { - // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec, - // return [prec, prec], otherwise ignore the range. - if (maxi == prec) - mini = prec; - } - else - mini = newmini; - } - if (mini == -2) - break; - r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); - return true; - CASE_CFN_CTZ: // __builtin_ctz* return [0, prec-1], except for when the // argument is 0, but that is undefined behavior. diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 84837f8ee43..caba49309f9 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -414,6 +414,81 @@ public: } } op_cfn_popcount; +// Implement range operator for CFN_BUILT_IN_CLZ +class cfn_clz : public range_operator +{ +public: + cfn_clz (bool internal) { m_gimple_call_internal_p = internal; } + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const; +private: + bool m_gimple_call_internal_p; +} op_cfn_clz (false), op_cfn_clz_internal (true); + +bool +cfn_clz::fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const +{ + // __builtin_c[lt]z* return [0, prec-1], except when the + // argument is 0, but that is undefined behavior. + // + // For __builtin_c[lt]z* consider argument of 0 always undefined + // behavior, for internal fns depending on C?Z_DEFINED_ALUE_AT_ZERO. + if (lh.undefined_p ()) + return false; + int prec = TYPE_PRECISION (lh.type ()); + int mini = 0; + int maxi = prec - 1; + int zerov = 0; + scalar_int_mode mode = SCALAR_INT_TYPE_MODE (lh.type ()); + if (m_gimple_call_internal_p) + { + if (optab_handler (clz_optab, mode) != CODE_FOR_nothing + && CLZ_DEFINED_VALUE_AT_ZERO (mode, zerov) == 2) + { + // Only handle the single common value. + if (zerov == prec) + maxi = prec; + else + // Magic value to give up, unless we can prove arg is non-zero. + mini = -2; + } + } + + // From clz of minimum we can compute result maximum. + if (wi::gt_p (lh.lower_bound (), 0, TYPE_SIGN (lh.type ()))) + { + maxi = prec - 1 - wi::floor_log2 (lh.lower_bound ()); + if (mini == -2) + mini = 0; + } + else if (!range_includes_zero_p (&lh)) + { + mini = 0; + maxi = prec - 1; + } + if (mini == -2) + return false; + // From clz of maximum we can compute result minimum. + wide_int max = lh.upper_bound (); + int newmini = prec - 1 - wi::floor_log2 (max); + if (max == 0) + { + // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec, + // return [prec, prec], otherwise ignore the range. + if (maxi == prec) + mini = prec; + } + else + mini = newmini; + + if (mini == -2) + return false; + r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); + return true; +} + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -469,6 +544,15 @@ gimple_range_op_handler::maybe_builtin_call () m_valid = true; break; + CASE_CFN_CLZ: + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + if (gimple_call_internal_p (call)) + m_int = &op_cfn_clz_internal; + else + m_int = &op_cfn_clz; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:05:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681297 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=Koj9Ma/R; dkim-atps=neutral Received: from sourceware.org (server2.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 4MYPsd6FWwz1yqH for ; Fri, 23 Sep 2022 05:07:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2EFE3856DC2 for ; Thu, 22 Sep 2022 19:06:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2EFE3856DC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873619; bh=qImNkXHpd61aFKiZ9zVfuX5dNognbcw3t825oM7utwA=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Koj9Ma/RvdaPjC/UbVr39zPTJWIoOTgPxU5PnteY6zzJrEW0mhaW37693jDF593/B jgBGGiiGE++q0IR4IiMKVUzs3n1BQVR4RUx7JE+w0AyHQmml3RoqDPgWMTgUENcG2x 1EhZ5u2HEERCmk0xqDOLh7Yv5RK5vATnJGq5EG50= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id A1582385702F for ; Thu, 22 Sep 2022 19:05:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1582385702F Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-635-xKf5N_B3N3Ca19tZpWqmZA-1; Thu, 22 Sep 2022 15:05:41 -0400 X-MC-Unique: xKf5N_B3N3Ca19tZpWqmZA-1 Received: by mail-il1-f198.google.com with SMTP id a8-20020a92c548000000b002f6440ff96bso5546242ilj.22 for ; Thu, 22 Sep 2022 12:05:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=fvPMfN3o24v+rP/BXLY4oDtwFUmZ0q4shuyhcSPIm3o=; b=KRqZaA+ktXJ6J5bCrxMmJfmhZaiXxqHIzHgPGEgHhvppSBy1mnxH0lTfPUVLfmy+6U 7y1YdxgmRWvExj7jh+xxQLuPPzHjTFMGshXx6ZAAl7wzCucEOje1Zx2kZDCFqciCZves W9MCFUaXAAThnx1jdh1ngvUlgawHT5Aa8/L/d0eAa/j8bz33sLn2oyw264Dk3RzFJ7I3 faIzx+H9l/HlB1bXMfiRAxQHDT0XqyQW9rOPNiUDJ0naQk4gPEC/lKcr670rQxcYj7a8 AJL3P7EZ977MXuuq/ZSi+0V5+aL8PGsrMOSWEz67PioJSRQK+/PL6uwmRSGcfzOrdG0z jQXA== X-Gm-Message-State: ACrzQf0H5brCNUderuuKdNogJJjNYSWppXfDN/+dPIZdy/UMSvYflVq1 ysGSdyM8kMXT3/55b9Rv8CQT1GBbAkE3AD60EK4EefSNTAbhWttFPxJGc/Cxe0aS3mWAeWs6SpD k/DdxDsakRZ0/s6lvs3yhl36sZ51/8vEejvXhgPclUVQhxxksV5yRXOEYCFPpJMZh2eHkfw== X-Received: by 2002:a05:6638:16d6:b0:358:31d8:65d8 with SMTP id g22-20020a05663816d600b0035831d865d8mr3000617jat.137.1663873538285; Thu, 22 Sep 2022 12:05:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ivFoFd06ZcLZFbOHlx0kcOvlUlJW5/GpxxCDR8u7nM3NtQ9EUP/CD6JiPtG71N80W6wFwpQ== X-Received: by 2002:a05:6638:16d6:b0:358:31d8:65d8 with SMTP id g22-20020a05663816d600b0035831d865d8mr3000607jat.137.1663873538070; Thu, 22 Sep 2022 12:05:38 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id b88-20020a0295e1000000b00349c8fe9109sm2507720jai.174.2022.09.22.12.05.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:05:37 -0700 (PDT) Message-ID: <622e4a48-eae4-600f-db3c-c478f537caa7@redhat.com> Date: Thu, 22 Sep 2022 15:05:36 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 12/17] Convert CFN_CTZ builtins to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 55738d8d96bb4f39a72cf5e3739d35b39fc2146a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 18:19:30 -0400 Subject: [PATCH 12/17] Convert CFN_CTZ builtins to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_CTZ. * gimple-range-op.cc (class cfn_ctz): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 61 +------------------------------ gcc/gimple-range-op.cc | 79 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 60 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 63eaa90be96..96a138a7a02 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -917,7 +917,7 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, tree type = gimple_range_type (call); tree arg; - int mini, maxi, zerov = 0, prec; + int prec; scalar_int_mode mode; switch (func) @@ -926,65 +926,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, r.set (build_zero_cst (type), build_one_cst (type)); return true; - CASE_CFN_CTZ: - // __builtin_ctz* return [0, prec-1], except for when the - // argument is 0, but that is undefined behavior. - // - // For __builtin_ctz* consider argument of 0 always undefined - // behavior, for internal fns depending on CTZ_DEFINED_VALUE_AT_ZERO. - arg = gimple_call_arg (call, 0); - prec = TYPE_PRECISION (TREE_TYPE (arg)); - mini = 0; - maxi = prec - 1; - mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (arg)); - if (gimple_call_internal_p (call)) - { - if (optab_handler (ctz_optab, mode) != CODE_FOR_nothing - && CTZ_DEFINED_VALUE_AT_ZERO (mode, zerov) == 2) - { - // Handle only the two common values. - if (zerov == -1) - mini = -1; - else if (zerov == prec) - maxi = prec; - else - // Magic value to give up, unless we can prove arg is non-zero. - mini = -2; - } - } - src.get_operand (r, arg); - if (!r.undefined_p ()) - { - // If arg is non-zero, then use [0, prec - 1]. - if (!range_includes_zero_p (&r)) - { - mini = 0; - maxi = prec - 1; - } - // If some high bits are known to be zero, we can decrease - // the maximum. - wide_int max = r.upper_bound (); - if (max == 0) - { - // Argument is [0, 0]. If CTZ_DEFINED_VALUE_AT_ZERO - // is 2 with value -1 or prec, return [-1, -1] or [prec, prec]. - // Otherwise ignore the range. - if (mini == -1) - maxi = -1; - else if (maxi == prec) - mini = prec; - } - // If value at zero is prec and 0 is in the range, we can't lower - // the upper bound. We could create two separate ranges though, - // [0,floor_log2(max)][prec,prec] though. - else if (maxi != prec) - maxi = wi::floor_log2 (max); - } - if (mini == -2) - break; - r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); - return true; - CASE_CFN_CLRSB: arg = gimple_call_arg (call, 0); prec = TYPE_PRECISION (TREE_TYPE (arg)); diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index caba49309f9..801c2bb235e 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -489,6 +489,76 @@ cfn_clz::fold_range (irange &r, tree type, const irange &lh, return true; } +// Implement range operator for CFN_BUILT_IN_CTZ +class cfn_ctz : public range_operator +{ +public: + cfn_ctz (bool internal) { m_gimple_call_internal_p = internal; } + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const; +private: + bool m_gimple_call_internal_p; +} op_cfn_ctz (false), op_cfn_ctz_internal (true); + +bool +cfn_ctz::fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const +{ + if (lh.undefined_p ()) + return false; + int prec = TYPE_PRECISION (lh.type ()); + int mini = 0; + int maxi = prec - 1; + int zerov = 0; + scalar_int_mode mode = SCALAR_INT_TYPE_MODE (lh.type ()); + + if (m_gimple_call_internal_p) + { + if (optab_handler (ctz_optab, mode) != CODE_FOR_nothing + && CTZ_DEFINED_VALUE_AT_ZERO (mode, zerov) == 2) + { + // Handle only the two common values. + if (zerov == -1) + mini = -1; + else if (zerov == prec) + maxi = prec; + else + // Magic value to give up, unless we can prove arg is non-zero. + mini = -2; + } + } + // If arg is non-zero, then use [0, prec - 1]. + if (!range_includes_zero_p (&lh)) + { + mini = 0; + maxi = prec - 1; + } + // If some high bits are known to be zero, we can decrease + // the maximum. + wide_int max = lh.upper_bound (); + if (max == 0) + { + // Argument is [0, 0]. If CTZ_DEFINED_VALUE_AT_ZERO + // is 2 with value -1 or prec, return [-1, -1] or [prec, prec]. + // Otherwise ignore the range. + if (mini == -1) + maxi = -1; + else if (maxi == prec) + mini = prec; + } + // If value at zero is prec and 0 is in the range, we can't lower + // the upper bound. We could create two separate ranges though, + // [0,floor_log2(max)][prec,prec] though. + else if (maxi != prec) + maxi = wi::floor_log2 (max); + + if (mini == -2) + return false; + r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); + return true; +} + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -553,6 +623,15 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_clz; break; + CASE_CFN_CTZ: + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + if (gimple_call_internal_p (call)) + m_int = &op_cfn_ctz_internal; + else + m_int = &op_cfn_ctz; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:06:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681299 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=2620:52:3:1:0:246e:9693:128c; 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=epMeLXZZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPtn4CY3z1yqH for ; Fri, 23 Sep 2022 05:08:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 997403857BA1 for ; Thu, 22 Sep 2022 19:07:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 997403857BA1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873679; bh=VMTc7lQLk7xF5zB5DU5WjEp1qtZEj7fQTQ6NNQEGQKc=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=epMeLXZZ9Qv9kiVliWCC9xxuTlK4E3RCW/N/0oviqfcM8GNrFhpJSlr+z4qnxVj2J PswcSgqYQ21oXVNXEBVmzafVus26/mODc9PsSkuVrSyRKWeZmZd/aD1P56u6JKc/rD hb8JOZi1//jIvCQakHK/EgOPdbgclOWDF6vxmq0Q= 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 9CBA53857C42 for ; Thu, 22 Sep 2022 19:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9CBA53857C42 Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-344-ZhhT2VU1PPmUc1Et3Tv72w-1; Thu, 22 Sep 2022 15:06:17 -0400 X-MC-Unique: ZhhT2VU1PPmUc1Et3Tv72w-1 Received: by mail-il1-f198.google.com with SMTP id a8-20020a92c548000000b002f6440ff96bso5547417ilj.22 for ; Thu, 22 Sep 2022 12:06:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=BnQ647yjmuLZ7hXXb41zEPTxXUGhlC5HfcbpZoBMuHs=; b=iblcgbbxIxlb6a8a+5bSZITU7Ij+GAN6WPuzShDPaykzemMiBe79JcoqZKeTe3t/fL mZ3w5+dq0eW/lcuHjajzzAjjCapOBY6u3t7BW3xzo4C1ik0Qjg1lSqrAhcdyhfn2FFfH nxoKdGmZ4NmIAPFabiE5+9pNjtMxckzpyk5qU/9KeLhYDz1/tQkGYTnYUJQI7u6xaGlL DXUx4FmhE/7A2W8jMU+OMycVN2PRPhKuZEuyEOCD/6/wZwmasrw/mWRxzbHwlDBZTONE P4FG0lFdrloEB1P++d4mTNiOKvOttYn+Z8y9cKKVvWSX7oJ4vs3yV1QEkP2xKObAgLeU 3ePw== X-Gm-Message-State: ACrzQf3V3fOgTtLMv9Czy6nyoTvcZNj8AgZaodR516j6yDwjxD3lAZtQ jUWntXUUQL0eKi30mxYVNJRIVNS15yTJPWKy7UNkurfe8fNjxughHCrC2ZWH3dTtWyhKZ3UfvMO WaTlnPVgizGw+sj56BXAC1UjjgWrlzoBF1+AhquJMQ3v2wwMZ0/RQB6jzQ1ABm5jXqGgNyA== X-Received: by 2002:a05:6e02:1d02:b0:2f1:6fb4:26b6 with SMTP id i2-20020a056e021d0200b002f16fb426b6mr2413530ila.49.1663873576874; Thu, 22 Sep 2022 12:06:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ezBmx5U2+p1hyMjf7yMmbxU6ksegG9Tp5jaAwXFkisZO67vkf9ofAQkrBbjXLnf8odknWgw== X-Received: by 2002:a05:6e02:1d02:b0:2f1:6fb4:26b6 with SMTP id i2-20020a056e021d0200b002f16fb426b6mr2413519ila.49.1663873576645; Thu, 22 Sep 2022 12:06:16 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id x3-20020a056602160300b006a19872663bsm2571766iow.53.2022.09.22.12.06.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:06:15 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:06:14 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 13/17] Convert CFN_BUILT_IN_CLRSB to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From f7e62b09300b6935bceaffb4c42f6edab80f52dc Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 18:21:04 -0400 Subject: [PATCH 13/17] Convert CFN_BUILT_IN_CLRSB to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_BUILT_IN_CLRSB. * gimple-range-op.cc (class cfn_clrsb): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 7 ------- gcc/gimple-range-op.cc | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 96a138a7a02..1d7d1da7bbe 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -916,8 +916,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, return false; tree type = gimple_range_type (call); - tree arg; - int prec; scalar_int_mode mode; switch (func) @@ -926,11 +924,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, r.set (build_zero_cst (type), build_one_cst (type)); return true; - CASE_CFN_CLRSB: - arg = gimple_call_arg (call, 0); - prec = TYPE_PRECISION (TREE_TYPE (arg)); - r.set (build_int_cst (type, 0), build_int_cst (type, prec - 1)); - return true; case CFN_UBSAN_CHECK_ADD: range_of_builtin_ubsan_call (r, call, PLUS_EXPR, src); return true; diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 801c2bb235e..bee225431e8 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -559,6 +559,23 @@ cfn_ctz::fold_range (irange &r, tree type, const irange &lh, return true; } + +// Implement range operator for CFN_BUILT_IN_ +class cfn_clrsb : public range_operator +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const + { + if (lh.undefined_p ()) + return false; + int prec = TYPE_PRECISION (lh.type ()); + r.set (build_int_cst (type, 0), build_int_cst (type, prec - 1)); + return true; + } +} op_cfn_clrsb; + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -632,6 +649,12 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_ctz; break; + CASE_CFN_CLRSB: + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + m_int = &op_cfn_clrsb; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:06:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681298 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=pQpVBKeu; 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 4MYPt00SQYz1yqH for ; Fri, 23 Sep 2022 05:07:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08B9B385741C for ; Thu, 22 Sep 2022 19:07:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08B9B385741C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873637; bh=PBph2QULcN+GdX+bqDcQc7NmFESQMYmy7BYW20b/w+s=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pQpVBKeuLkfOlDYOS1175A7JAANiZV98cTrZURNSldFoV6cslshjHcFh1RfxqyRPo UeSS1lNTZzq4UdY+fPFAHbZwQpLLnKsLVYNJ/5pyDvYDNMZ+hrxQMhrR25sn24tgDX DVQ+mvBvkI7A7izGrNYRg/ur1+uyF5CpCxR4YPbg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 807A83857341 for ; Thu, 22 Sep 2022 19:06:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 807A83857341 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-245-1-0jcMdrMHOuNvLGrPejJg-1; Thu, 22 Sep 2022 15:06:53 -0400 X-MC-Unique: 1-0jcMdrMHOuNvLGrPejJg-1 Received: by mail-io1-f71.google.com with SMTP id y10-20020a5d914a000000b00688fa7b2252so5287495ioq.0 for ; Thu, 22 Sep 2022 12:06:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=3hcilMJ4u7BBEdZca+ypX8wuy27HKOk5JBWTJ9eFVhI=; b=inu45vNWdWrWoiPmKk1f8RSBku+jTDU9E7rR85tCsHFyOuLC/V6XUDiKYpMVar/t44 rIK5j15x2O5Trz4xpRbeT3EE+hCLDJNjvj6I5dJDzUWcsbaGs3p5GBiOJOkyWsoq56yG S7gB9hy9WThgVZXGVa7WPywW1c0jTgZP+5EhHy66XRdX5xVhNRGQHiPmjkA/ea3OQgCp pJCyIhRG9v46Aau85EaQGV93Jw4i8JBfDu+5DPTxxKPGEBcw0o2A61KLwr65/o/TgtpW /OQcMDeUau0azYBvKcYq9pybprVAbvHUTbyci/lhyUJGpN/3xVCSgfeyZ2R1l1KazZ7i dF1A== X-Gm-Message-State: ACrzQf3P+s7WEOE3zYJuCXGdbY31OLpw7VXa6TkqGNs3t9oSxUuh6dOd D0DYRH1wmrXtuMnbEZmM9Qep4ZbhCnwBJGgPEi1d+oSHKIZ9Tl2tEt3fLRsykvtzth43+U2nCUj 1b0+1O7zA9n8h4w95RLpOABlEJdUTBc1NWQK/cqrm1fhb3bbdCFKqqq3IB2qZgi5uHZTQCg== X-Received: by 2002:a92:730c:0:b0:2f5:7dd7:45f7 with SMTP id o12-20020a92730c000000b002f57dd745f7mr2500207ilc.12.1663873612558; Thu, 22 Sep 2022 12:06:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7e5FRo3LWEXRhSfXGOVTEfMROKci64lgRXWuJrjoEyBH/bufnFZZjb5b3oAdGlyUUks20zWg== X-Received: by 2002:a92:730c:0:b0:2f5:7dd7:45f7 with SMTP id o12-20020a92730c000000b002f57dd745f7mr2500197ilc.12.1663873612309; Thu, 22 Sep 2022 12:06:52 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id m12-20020a92d70c000000b002f6028e31cesm2314685iln.61.2022.09.22.12.06.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:06:51 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:06:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 14/17] Convert CFN_BUILT_IN_UBSAN_CHECK_* to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From b6f670ff706e35dc51a62db4206cb241dcac4963 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 18:48:05 -0400 Subject: [PATCH 14/17] Convert CFN_BUILT_IN_UBSAN_CHECK_* to range-ops. * gimple-range-fold.cc (range_of_builtin_ubsan_call): Delete. (range_of_builtin_int_call): Remove cases for CFN_BUILT_IN_UBSAN_CHECK. * gimple-range-op.cc (class cfn_ubsan): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 47 +-------------------------------- gcc/gimple-range-op.cc | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 46 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 1d7d1da7bbe..d445270417a 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -852,41 +852,6 @@ fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &src) return true; } -// Return the range of a __builtin_ubsan* in CALL and set it in R. -// CODE is the type of ubsan call (PLUS_EXPR, MINUS_EXPR or -// MULT_EXPR). - -void -fold_using_range::range_of_builtin_ubsan_call (irange &r, gcall *call, - tree_code code, fur_source &src) -{ - gcc_checking_assert (code == PLUS_EXPR || code == MINUS_EXPR - || code == MULT_EXPR); - tree type = gimple_range_type (call); - range_op_handler op (code, type); - gcc_checking_assert (op); - int_range_max ir0, ir1; - tree arg0 = gimple_call_arg (call, 0); - tree arg1 = gimple_call_arg (call, 1); - src.get_operand (ir0, arg0); - src.get_operand (ir1, arg1); - // Check for any relation between arg0 and arg1. - relation_kind relation = src.query_relation (arg0, arg1); - - 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; - op.fold_range (r, type, ir0, ir1, relation); - flag_wrapv = saved_flag_wrapv; - - // If for both arguments vrp_valueize returned non-NULL, this should - // have been already folded and if not, it wasn't folded because of - // overflow. Avoid removing the UBSAN_CHECK_* calls in that case. - if (r.singleton_p ()) - r.set_varying (type); -} - // For a builtin in CALL, return a range in R if known and return // TRUE. Otherwise return FALSE. @@ -909,7 +874,7 @@ fold_using_range::range_of_builtin_call (vrange &r, gcall *call, bool fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, - fur_source &src) + fur_source &) { combined_fn func = gimple_call_combined_fn (call); if (func == CFN_LAST) @@ -924,16 +889,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, r.set (build_zero_cst (type), build_one_cst (type)); return true; - case CFN_UBSAN_CHECK_ADD: - range_of_builtin_ubsan_call (r, call, PLUS_EXPR, src); - return true; - case CFN_UBSAN_CHECK_SUB: - range_of_builtin_ubsan_call (r, call, MINUS_EXPR, src); - return true; - case CFN_UBSAN_CHECK_MUL: - range_of_builtin_ubsan_call (r, call, MULT_EXPR, src); - return true; - case CFN_GOACC_DIM_SIZE: case CFN_GOACC_DIM_POS: // Optimizing these two internal functions helps the loop diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index bee225431e8..09b7dd2add3 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -576,6 +576,41 @@ public: } } op_cfn_clrsb; + +// Implement range operator for CFN_BUILT_IN_ +class cfn_ubsan : public range_operator +{ +public: + cfn_ubsan (enum tree_code code) { m_code = code; } + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &rh, relation_kind rel) const + { + range_op_handler handler (m_code, type); + 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); + flag_wrapv = saved_flag_wrapv; + + // If for both arguments vrp_valueize returned non-NULL, this should + // have been already folded and if not, it wasn't folded because of + // overflow. Avoid removing the UBSAN_CHECK_* calls in that case. + if (result && r.singleton_p ()) + r.set_varying (type); + return result; + } +private: + enum tree_code m_code; +}; + +cfn_ubsan op_cfn_ubsan_add (PLUS_EXPR); +cfn_ubsan op_cfn_ubsan_sub (MINUS_EXPR); +cfn_ubsan op_cfn_ubsan_mul (MULT_EXPR); + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -655,6 +690,27 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_clrsb; break; + case CFN_UBSAN_CHECK_ADD: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_valid = true; + m_int = &op_cfn_ubsan_add; + break; + + case CFN_UBSAN_CHECK_SUB: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_valid = true; + m_int = &op_cfn_ubsan_sub; + break; + + case CFN_UBSAN_CHECK_MUL: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_valid = true; + m_int = &op_cfn_ubsan_mul; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:08:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681300 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=RrXMieFA; 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 4MYPvZ4xtcz1yqH for ; Fri, 23 Sep 2022 05:08:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76B143857827 for ; Thu, 22 Sep 2022 19:08:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76B143857827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873720; bh=litkq4wwtsmrL4HfCABCHagnbXFQPBQqEbSmCS+JHdg=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RrXMieFAwxkaR3C+zQDsgNfh1CM9LWEK+dKjtU2O66LyWoO9B0UZ/wcrgvcrOb35Q 8RinUCI09rFM3onLx1UYfWEVFreHDpIlc1o6pggx7sUnAkAWx8zUXKwgjPPdxBwfl9 V0P6HXUbDJOpCJ2HqE0VaHbjQv4mjJAyXYRurRPQ= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id D9F483857BBC for ; Thu, 22 Sep 2022 19:08:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9F483857BBC Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-589-4pbwxBgJN4itRumFjyVsTw-1; Thu, 22 Sep 2022 15:08:19 -0400 X-MC-Unique: 4pbwxBgJN4itRumFjyVsTw-1 Received: by mail-io1-f72.google.com with SMTP id e15-20020a5d8acf000000b006a3ed059e49so1644084iot.14 for ; Thu, 22 Sep 2022 12:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=hXuRE6j25LreGnEdkEwz1nVf8lScH46W15cf80Lmt+M=; b=upbmPTTvVsaRfoK2Z3THCH2MuulFQQnRxCfTE8vd3HDSxAjruZ1MS0vJGIv/moDjaz OYOV6XGOCyUpIYEtcLKpwPdGjIp3LJHJQ/bO5tT2UGDaLL95cRNqQPjvz30nXJ/C2BH+ PNJ33On5V84Xud18NT7H/ACYbTNe0ztINEh8ZqE0pp5bJFjVZM7CbECBw0H7BT3FHeRE MtF9Pv5vauAYsV5+iYK9tBrPU0eTCqXva4xXHLWwBBQ1gS72Q3Y62iUkoQhjqpkXzNZE ze0UBMqLAHpmANDPINH3jWlO0SpAN/gIdyni4i8xEq5Op9PyuhYl/Xu9BiCuAs0T4/vb 5igw== X-Gm-Message-State: ACrzQf3zaO7JWMuCHuFQiYb70FUr6UrcM4rCYXNlPcbhVnevRPubEM7E OgmQylwuALg/SleriHDtn1aOiiDUFXSQqvvuAZTQWy3wW8yWlUFWBYg1C7X9Fu/Ge0udLbIDZID j2t3v2dvbz0pZXL7+ukUbd+ke/xVbWylsiR/xTKTltXdY4LYP/BD39n7YmhqqAjcLJf1OIw== X-Received: by 2002:a05:6602:2d89:b0:6a3:8489:fef4 with SMTP id k9-20020a0566022d8900b006a38489fef4mr2432722iow.105.1663873698662; Thu, 22 Sep 2022 12:08:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Tz2aWgdM8NAIcnXNypt5CgxDW3q4sBrPMI5BpuduKW4AZ9BqXv+um+0q8OKCy/con2aIvIA== X-Received: by 2002:a05:6602:2d89:b0:6a3:8489:fef4 with SMTP id k9-20020a0566022d8900b006a38489fef4mr2432711iow.105.1663873698303; Thu, 22 Sep 2022 12:08:18 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id y30-20020a02731e000000b0035b0af5783dsm2472785jab.32.2022.09.22.12.08.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:08:17 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:08:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 15/17] Convert CFN_BUILT_IN_STRLEN to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From c750e675cb77f283ff991682db7740bc5f6d4cf4 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 19:05:03 -0400 Subject: [PATCH 15/17] Convert CFN_BUILT_IN_STRLEN to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_BUILT_IN_STRLEN. * gimple-range-op.cc (class cfn_strlen): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 21 --------------------- gcc/gimple-range-op.cc | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index d445270417a..d22fb0e9352 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -908,27 +908,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, return true; } - case CFN_BUILT_IN_STRLEN: - if (tree lhs = gimple_call_lhs (call)) - if (ptrdiff_type_node - && (TYPE_PRECISION (ptrdiff_type_node) - == TYPE_PRECISION (TREE_TYPE (lhs)))) - { - tree type = TREE_TYPE (lhs); - tree max = vrp_val_max (ptrdiff_type_node); - wide_int wmax - = wi::to_wide (max, TYPE_PRECISION (TREE_TYPE (max))); - tree range_min = build_zero_cst (type); - // To account for the terminating NULL, the maximum length - // is one less than the maximum array size, which in turn - // is one less than PTRDIFF_MAX (or SIZE_MAX where it's - // smaller than the former type). - // FIXME: Use max_object_size() - 1 here. - tree range_max = wide_int_to_tree (type, wmax - 2); - r.set (range_min, range_max); - return true; - } - break; default: break; } diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 09b7dd2add3..f9161b5820f 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -611,6 +611,30 @@ cfn_ubsan op_cfn_ubsan_add (PLUS_EXPR); cfn_ubsan op_cfn_ubsan_sub (MINUS_EXPR); cfn_ubsan op_cfn_ubsan_mul (MULT_EXPR); + +// Implement range operator for CFN_BUILT_IN_STRLEN +class cfn_strlen : public range_operator +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &, + const irange &, relation_kind) const + { + tree max = vrp_val_max (ptrdiff_type_node); + wide_int wmax + = wi::to_wide (max, TYPE_PRECISION (TREE_TYPE (max))); + tree range_min = build_zero_cst (type); + // To account for the terminating NULL, the maximum length + // is one less than the maximum array size, which in turn + // is one less than PTRDIFF_MAX (or SIZE_MAX where it's + // smaller than the former type). + // FIXME: Use max_object_size() - 1 here. + tree range_max = wide_int_to_tree (type, wmax - 2); + r.set (range_min, range_max); + return true; + } +} op_cfn_strlen; + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -711,6 +735,19 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_ubsan_mul; break; + case CFN_BUILT_IN_STRLEN: + { + tree lhs = gimple_call_lhs (call); + if (lhs && ptrdiff_type_node && (TYPE_PRECISION (ptrdiff_type_node) + == TYPE_PRECISION (TREE_TYPE (lhs)))) + { + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + m_int = &op_cfn_strlen; + } + break; + } + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:10:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681301 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=2620:52:3:1:0:246e:9693:128c; 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=rksq85Jl; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MYPxm0xyzz1ypf for ; Fri, 23 Sep 2022 05:10:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8A7C3858005 for ; Thu, 22 Sep 2022 19:10:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8A7C3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873832; bh=JFqxHQw7h4km9I2ttqhkzVVM3DFXEWW7ofuRIUa6Izg=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=rksq85Jl8CB/3bUpE81HdIP70ehOVGyjlnVvUL0wP5I92UyhJ4vOcy5NP76dCa8fE /MOP3I0F5lQrpevU4tCsKA50+9wJ/8ylz31clg3xrQnpaJLNAB1ILjt4AN3+8EfOiS Q2m+LyUYmoBjKnuPCr3nRCNv+6yqjZyXr87BDlwc= 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 B7AD23858D38 for ; Thu, 22 Sep 2022 19:10:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B7AD23858D38 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-562-655F-dfBNgCmDiIrtGrz_A-1; Thu, 22 Sep 2022 15:10:11 -0400 X-MC-Unique: 655F-dfBNgCmDiIrtGrz_A-1 Received: by mail-io1-f69.google.com with SMTP id i14-20020a5d934e000000b006892db5bcd4so5343147ioo.22 for ; Thu, 22 Sep 2022 12:10:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=28MRBqqCpjYtuKrtA4Z6pf0IFJz+KXKxvHAIIBRyS5I=; b=6KRq0N1tH521kfOvSC3uB7OFrAO9fgt+7cMUZh/zo1GYKZHQaLSfH6dDuShIoQgEzn F8E8o98vLDOWlXzt9tpVlkEEhLfT94WBE50w84YbbLYsgHo7s51oBM++saGFyBhawS3E jpUZREaZgOfx+AR3SqhUI5U4REqkH3Xyix0K6brmz+RC6FW2HPRj72gZo8jMLrP2GUct tU9DN9Sd1qTvJ26FQtO3XDdT7vIH8Vp0f+AcDlomYUqIaz6V8xsn6V6op+j5ycIF0lCJ 569Hl+XdYGMH84J3yrRYiiAZXhN6FeVSjBKJQ0a0Quo1lv5K5Gl2kJqIA0kfy2u+AoUr 8z3g== X-Gm-Message-State: ACrzQf3ndLtwwRSLRJqxCZnF8HlGxjIOzqEXiFbQ+F950/p2bJfWtLsa vLdIM5a/lNwfat+esAQfOqGjonYUuB8DWQ7rwbwn5swGonoIJH0XTY1xol0aK9PkNodfGHbd0qy g27C0UYz0oGShKCrmlUXh+WhWgKJn4xFmHUpCmM9+Q8I8nG0SO1+8nusNfQ4zxTXJdMJx1g== X-Received: by 2002:a05:6638:13cb:b0:33f:336c:34ae with SMTP id i11-20020a05663813cb00b0033f336c34aemr2719666jaj.317.1663873810093; Thu, 22 Sep 2022 12:10:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WgIgCNKFwjw/GJhGXMDIVGL1MaVrV6X3zXNu9ojTzs/5cn1FKM0sOeco78eQx07ywvG0Y7g== X-Received: by 2002:a05:6638:13cb:b0:33f:336c:34ae with SMTP id i11-20020a05663813cb00b0033f336c34aemr2719648jaj.317.1663873809795; Thu, 22 Sep 2022 12:10:09 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id f24-20020a5d8798000000b0068a82e9b780sm2595818ion.28.2022.09.22.12.10.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:10:08 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:10:07 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 16/17] Convert CFN_BUILT_IN_GOACC_DIM_* to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.8 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From e7f035f66aa25e0537a0e3a76d43c71fe9531724 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 19:19:30 -0400 Subject: [PATCH 16/17] Convert CFN_BUILT_IN_GOACC_DIM_* to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_GOACC_DIM_*. * gimple-range-op.cc (class cfn_goacc_dim): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 19 ---------------- gcc/gimple-range-op.cc | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index d22fb0e9352..5e8a13e7337 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -889,25 +889,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, r.set (build_zero_cst (type), build_one_cst (type)); return true; - case CFN_GOACC_DIM_SIZE: - case CFN_GOACC_DIM_POS: - // Optimizing these two internal functions helps the loop - // optimizer eliminate outer comparisons. Size is [1,N] - // and pos is [0,N-1]. - { - bool is_pos = func == CFN_GOACC_DIM_POS; - int axis = oacc_get_ifn_dim_arg (call); - int size = oacc_get_fn_dim_size (current_function_decl, axis); - if (!size) - // If it's dynamic, the backend might know a hardware limitation. - size = targetm.goacc.dim_limit (axis); - - r.set (build_int_cst (type, is_pos ? 0 : 1), - size - ? build_int_cst (type, size - is_pos) : vrp_val_max (type)); - return true; - } - default: break; } diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index f9161b5820f..76295466e65 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -635,6 +635,34 @@ public: } } op_cfn_strlen; + +// Implement range operator for CFN_BUILT_IN_GOACC_DIM +class cfn_goacc_dim : public range_operator +{ +public: + cfn_goacc_dim (bool is_pos) { m_is_pos = is_pos; } + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &, relation_kind) const + { + tree axis_tree; + if (!lh.singleton_p (&axis_tree)) + return false; + HOST_WIDE_INT axis = TREE_INT_CST_LOW (axis_tree); + int size = oacc_get_fn_dim_size (current_function_decl, axis); + if (!size) + // If it's dynamic, the backend might know a hardware limitation. + size = targetm.goacc.dim_limit (axis); + + r.set (build_int_cst (type, m_is_pos ? 0 : 1), + size + ? build_int_cst (type, size - m_is_pos) : vrp_val_max (type)); + return true; + } +private: + bool m_is_pos; +} op_cfn_goacc_dim_size (false), op_cfn_goacc_dim_pos (true); + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -748,6 +776,25 @@ gimple_range_op_handler::maybe_builtin_call () break; } + // Optimizing these two internal functions helps the loop + // optimizer eliminate outer comparisons. Size is [1,N] + // and pos is [0,N-1]. + case CFN_GOACC_DIM_SIZE: + // This call will ensure all the asserts are triggered. + oacc_get_ifn_dim_arg (call); + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + m_int = &op_cfn_goacc_dim_size; + break; + + case CFN_GOACC_DIM_POS: + // This call will ensure all the asserts are triggered. + oacc_get_ifn_dim_arg (call); + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + m_int = &op_cfn_goacc_dim_pos; + break; + default: break; } -- 2.37.3 From patchwork Thu Sep 22 19:10:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681303 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=ZmtsBQIm; dkim-atps=neutral Received: from sourceware.org (server2.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 4MYPzM4fLhz1ypf for ; Fri, 23 Sep 2022 05:11:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BF1E3858029 for ; Thu, 22 Sep 2022 19:11:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BF1E3858029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873917; bh=zw/WHEHESSwBeKyMIvQHe/nsjVMk/TGPlX842/cXWtI=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZmtsBQImG1PlDDWjouh+i+dd60cd3F2CDCNL/je9jT5lmCmrF2NjuLlv4BDCJ58PR xFQtN2rGtJik7ceDMd3YYCqBsioSA70pdxqgAAN6JTFgHB59MxWUQdbVMsvfqiZoIu nNww3c5f5/XwVCUCAKniYwa2fTZOZRQJ8Xs8DYms= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 1E2E538582B5 for ; Thu, 22 Sep 2022 19:10:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E2E538582B5 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-631-zy807MKLNX6tHDRsnU3cnQ-1; Thu, 22 Sep 2022 15:10:49 -0400 X-MC-Unique: zy807MKLNX6tHDRsnU3cnQ-1 Received: by mail-io1-f72.google.com with SMTP id y1-20020a056602200100b006893cd97da9so5270218iod.1 for ; Thu, 22 Sep 2022 12:10:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=PWeT8UYyVU/ZgmDlFAMFXDIRY134GwWBIlz90JNqg1I=; b=3grLIb0Gw+wB4Nrjzh1GSqGMK3vOcoFj6SwzCwM+bPSfWhIWX3QTwhIBAwJg9sW3Jw IYQUQvBX6KTcauxNJQ3ICdFfUHF1pqfGDrFI9xKrZDzfzf+Ji/hhHtnDunAB8E98intc b+6Ov0L1VxSGdCxpRXmR9P2KMui6QSoTlgkA2xtSincRmIs5FUXv1J7irRjHei0MKJLK ep/xETO/qrPwAte1Uv84/qUP50P//syfEZIlSqNCruDAfqj/f0f7J46JeZRtgDKp4VVd /0QC/g0d/tmlAdNNVrSp/G+UvIVtxknnxjMoq5H19tOynT2LN9Oa31We/eXdlFph61Sr h/ag== X-Gm-Message-State: ACrzQf1VUnuBnj+1mgEcW1onU6s+x65CEUtHJ5YvpNnq382oGLpLC18i J2ZgjjvH5fngYKbT7YmwF2M5MYfX5B1qP4mrDLzJz2RAdV4CFScJMY11XAKc7055PM8KMJtl/IK tX9BfIuKgSlfE555PGKroc1p+XeLtLF1KZZztwWpJW4DKbRa8swdaUndvV12k/WuYg6c4ZA== X-Received: by 2002:a05:6e02:168f:b0:2f2:467:5f39 with SMTP id f15-20020a056e02168f00b002f204675f39mr2600987ila.174.1663873848041; Thu, 22 Sep 2022 12:10:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Eh6jjJOWuYTDPXxPI5Brz+EC+LLCSb1Ijuy6/c0Ub2A5pEW3vU3jk6hKnrri7fqX9CZwxeQ== X-Received: by 2002:a05:6e02:168f:b0:2f2:467:5f39 with SMTP id f15-20020a056e02168f00b002f204675f39mr2600980ila.174.1663873847717; Thu, 22 Sep 2022 12:10:47 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id p23-20020a02b017000000b0034e75d95c13sm2469510jah.151.2022.09.22.12.10.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:10:47 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:10:45 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 17/17] Convert CFN_BUILT_IN_PARITY to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.8 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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" Also, as the last builtin remaining, also remove the builtin infrastructure routines from fold_using_range. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 5608e410914ebb7c8cc9fa50afc8ada3b22cbf2c Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 19:30:46 -0400 Subject: [PATCH 17/17] Convert CFN_BUILT_IN_PARITY to range-ops. Also, as the last builtin remaining, also remove the builtin infrastrucure routines from fold_using_range. * gimple-range-fold.cc (range_of_range_op): Handle no operands. (range_of_call): Do not check for builtins. (fold_using_range::range_of_builtin_call): Delete. (fold_using_range::range_of_builtin_int_call): Delete. * gimple-range-fold.h: Adjust prototypes. * gimple-range-op.cc (class cfn_parity): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 60 ++++++++-------------------------------- gcc/gimple-range-fold.h | 4 --- gcc/gimple-range-op.cc | 19 +++++++++++++ 3 files changed, 31 insertions(+), 52 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 5e8a13e7337..c381ef94087 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -534,6 +534,16 @@ fold_using_range::range_of_range_op (vrange &r, tree lhs = handler.lhs (); tree op1 = handler.operand1 (); tree op2 = handler.operand2 (); + + // Certain types of builtin functions may have no arguments. + if (!op1) + { + Value_Range r1 (type); + if (!handler.fold_range (r, type, r1, r1)) + r.set_varying (type); + return true; + } + Value_Range range1 (TREE_TYPE (op1)); Value_Range range2 (op2 ? TREE_TYPE (op2) : TREE_TYPE (op1)); @@ -823,7 +833,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) // If a range cannot be calculated, return false. bool -fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &src) +fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &) { tree type = gimple_range_type (call); if (!type) @@ -832,9 +842,7 @@ fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &src) tree lhs = gimple_call_lhs (call); bool strict_overflow_p; - if (range_of_builtin_call (r, call, src)) - ; - else if (gimple_stmt_nonnegative_warnv_p (call, &strict_overflow_p)) + if (gimple_stmt_nonnegative_warnv_p (call, &strict_overflow_p)) r.set_nonnegative (type); else if (gimple_call_nonnull_result_p (call) || gimple_call_nonnull_arg (call)) @@ -852,50 +860,6 @@ fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &src) return true; } -// For a builtin in CALL, return a range in R if known and return -// TRUE. Otherwise return FALSE. - -bool -fold_using_range::range_of_builtin_call (vrange &r, gcall *call, - fur_source &src) -{ - combined_fn func = gimple_call_combined_fn (call); - if (func == CFN_LAST) - return false; - - tree type = gimple_range_type (call); - gcc_checking_assert (type); - - if (irange::supports_p (type)) - return range_of_builtin_int_call (as_a (r), call, src); - - return false; -} - -bool -fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, - fur_source &) -{ - combined_fn func = gimple_call_combined_fn (call); - if (func == CFN_LAST) - return false; - - tree type = gimple_range_type (call); - scalar_int_mode mode; - - switch (func) - { - CASE_CFN_PARITY: - r.set (build_zero_cst (type), build_one_cst (type)); - return true; - - default: - break; - } - return false; -} - - // Calculate a range for COND_EXPR statement S and return it in R. // If a range cannot be calculated, return false. diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index ce18c66b8e7..d1ed2bca80f 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -165,10 +165,6 @@ protected: bool range_of_call (vrange &r, gcall *call, fur_source &src); bool range_of_cond_expr (vrange &r, gassign* cond, fur_source &src); bool range_of_address (irange &r, gimple *s, fur_source &src); - bool range_of_builtin_call (vrange &r, gcall *call, fur_source &src); - bool range_of_builtin_int_call (irange &r, gcall *call, fur_source &src); - void range_of_builtin_ubsan_call (irange &r, gcall *call, tree_code code, - fur_source &src); bool range_of_phi (vrange &r, gphi *phi, fur_source &src); void range_of_ssa_name_with_loop_info (vrange &, tree, class loop *, gphi *, fur_source &src); diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 76295466e65..d7c6dfa933d 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -663,6 +663,20 @@ private: bool m_is_pos; } op_cfn_goacc_dim_size (false), op_cfn_goacc_dim_pos (true); + +// Implement range operator for CFN_BUILT_IN_ +class cfn_parity : public range_operator +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &, + const irange &, relation_kind) const + { + r.set (build_zero_cst (type), build_one_cst (type)); + return true; + } +} op_cfn_parity; + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -795,6 +809,11 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_goacc_dim_pos; break; + CASE_CFN_PARITY: + m_valid = true; + m_int = &op_cfn_parity; + break; + default: break; } -- 2.37.3