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