From patchwork Tue Aug 2 12:24:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2943021pxt; Tue, 2 Aug 2022 05:26:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s0onxsP90jWAL123tZm9QwsDk77OUW8t9vNtDALo1qjpFBxolAxt/ap9Fk02X4/RLea9da X-Received: by 2002:a17:906:5a6c:b0:72b:561a:3458 with SMTP id my44-20020a1709065a6c00b0072b561a3458mr15980137ejc.114.1659443186605; Tue, 02 Aug 2022 05:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659443186; cv=none; d=google.com; s=arc-20160816; b=FdLkvwqmAAZgBbkcw4ZOMjTOUeX0ZNexpUqBeFL09FwVyxd2Ys3Fo8y/sgwhdJKy69 oFW82BMW7yJP+q5Z2Rcm269iwqPdDvaw5SR90aZdYIHBG7ZDnWDgJhD8VxD0m0erzPmO pNiMYkRI+Z+1IAst7G9yldw5hJnjizr8Pzua8CTf3oH0nT3h5xMsW27UUXDCY7ZMckoK ceY7vHudFblloeV1wil3VlqHKoJuJ0hb2hcmiuM44X45BKDUErhYBuhc9FAW1SWnGmzd BhIWD+eq/OI3Hv6DlGthpKK95nmXmoL9BT+EqtExnGuaiPxM+ZN1kUxBsUAs18IXLshv 9TUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Nu7P5VDMXvEDo4oMz19BlLlDcvI0dVhp93FH9SQsOjQ=; b=ANRnvPtdI8emSp3MPx/tu7fkeKF7QWazjVobLi8mA6FIY9cNQZzdV/zvy2m3wjKchA 0BLHkKh8KDXhiSVn0lkS9HzEDI1nbKCa3P1pXmFPp2dT63Pqg8ufRjoHwgOQVJwY6nIm cAaFt1+DwPsTzThNrwq/01YkX05olsR+ApbwJQX+kaLQKlUy58DU/viGH7b78F/sNQxc eJRdLqbDgfsWi+pUlBqBauhoux6VmjBtf8MUUMpf/KWPHB6oLffQAw1ZTesSrmkDbE21 l3yF9zrDz8T/P/9QN6Hwmvqm3MjGG2/YxGN/l8hdk4iQqEKrYAyAZWpBNOyVVqsVzokR TPlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uZDwT6sk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id go6-20020a1709070d8600b006dfc3945326si635021ejc.152.2022.08.02.05.26.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 05:26:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uZDwT6sk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D293838485A2 for ; Tue, 2 Aug 2022 12:25:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D293838485A2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659443156; bh=Nu7P5VDMXvEDo4oMz19BlLlDcvI0dVhp93FH9SQsOjQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uZDwT6skwCjhbnveurZxXTlI/tAkEypRnK0AtzNozl0Joc9pTSlasFA+2FaH1M41n xr2Q3d8sJ5ebsarlkKMNif/zNdj1xv/fN0VMhV6LAFMHErWU2pU3sCOuk1IqK8olfz HHSNgHsOJEamgp0FWLD+pQRTvHIcZ+/yTgGjf0m0= 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 01F2238515EA for ; Tue, 2 Aug 2022 12:24:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01F2238515EA Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-TTAFN0LuN7GDaKKV8WPe7w-1; Tue, 02 Aug 2022 08:24:15 -0400 X-MC-Unique: TTAFN0LuN7GDaKKV8WPe7w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A2B28041BE; Tue, 2 Aug 2022 12:24:14 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 317AA18EA8; Tue, 2 Aug 2022 12:24:13 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 272COBRo336138 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 2 Aug 2022 14:24:11 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 272COBko336137; Tue, 2 Aug 2022 14:24:11 +0200 To: GCC patches Subject: [PATCH] Implement streamer for frange. Date: Tue, 2 Aug 2022 14:24:07 +0200 Message-Id: <20220802122407.336092-3-aldyh@redhat.com> In-Reply-To: <20220802122407.336092-1-aldyh@redhat.com> References: <20220802122407.336092-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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_NONE, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740052298546310342?= X-GMAIL-MSGID: =?utf-8?q?1740052298546310342?= This patch Allows us to export floating point ranges into the SSA name (SSA_NAME_RANGE_INFO). [Richi, in PR24021 you suggested that match.pd could use global float ranges, because it would generally not invoke ranger. This patch implements the boiler plate to save the frange globally.] [Jeff, we've also been talking in parallel of using NAN knowledge during expansion to RTL. This patch will provide the NAN bits in the SSA name.] Since frange's currently implementation is just a shell, with no actual endpoints, frange_storage_slot only contains frange_props which fits inside a byte. When we have endpoints, y'all can decide if it's worth saving them, or if the NAN/etc bits are good enough. I've tested this on my branch which has FP-ranger enabled. I will commit once I do a final round of testing on vanilla trunk. gcc/ChangeLog: * tree-core.h (struct tree_ssa_name): Add frange_info and reshuffle the rest. * value-range-storage.cc (vrange_storage::alloc_slot): Add case for frange. (vrange_storage::set_vrange): Same. (vrange_storage::get_vrange): Same. (vrange_storage::fits_p): Same. (frange_storage_slot::alloc_slot): New. (frange_storage_slot::set_frange): New. (frange_storage_slot::get_frange): New. (frange_storage_slot::fits_p): New. * value-range-storage.h (class frange_storage_slot): New. --- gcc/tree-core.h | 12 ++++---- gcc/value-range-storage.cc | 61 +++++++++++++++++++++++++++++++++++++- gcc/value-range-storage.h | 19 ++++++++++++ 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/gcc/tree-core.h b/gcc/tree-core.h index ea9f281f1cc..86a07c282af 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1589,17 +1589,17 @@ struct GTY(()) tree_ssa_name { /* Value range information. */ union ssa_name_info_type { + /* Ranges for integers. */ + struct GTY ((tag ("0"))) irange_storage_slot *irange_info; + /* Ranges for floating point numbers. */ + struct GTY ((tag ("1"))) frange_storage_slot *frange_info; /* Pointer attributes used for alias analysis. */ - struct GTY ((tag ("0"))) ptr_info_def *ptr_info; + struct GTY ((tag ("2"))) ptr_info_def *ptr_info; /* This holds any range info supported by ranger (except ptr_info above) and is managed by vrange_storage. */ void * GTY ((skip)) range_info; - /* GTY tag when the range in the range_info slot above satisfies - irange::supports_type_p. */ - struct GTY ((tag ("1"))) irange_storage_slot *irange_info; } GTY ((desc ("%1.typed.type ?" \ - "!POINTER_TYPE_P (TREE_TYPE ((tree)&%1)) : 2"))) info; - + "(POINTER_TYPE_P (TREE_TYPE ((tree)&%1)) ? 2 : SCALAR_FLOAT_TYPE_P (TREE_TYPE ((tree)&%1))) : 3"))) info; /* Immediate uses list for this SSA_NAME. */ struct ssa_use_operand_t imm_uses; }; diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index 8b5ab544ce3..ea3b83ca641 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -40,7 +40,8 @@ vrange_storage::alloc_slot (const vrange &r) if (is_a (r)) return irange_storage_slot::alloc_slot (*m_alloc, as_a (r)); - + if (is_a (r)) + return frange_storage_slot::alloc_slot (*m_alloc, as_a (r)); return NULL; } @@ -55,6 +56,12 @@ vrange_storage::set_vrange (void *slot, const vrange &r) gcc_checking_assert (s->fits_p (as_a (r))); s->set_irange (as_a (r)); } + else if (is_a (r)) + { + frange_storage_slot *s = static_cast (slot); + gcc_checking_assert (s->fits_p (as_a (r))); + s->set_frange (as_a (r)); + } else gcc_unreachable (); } @@ -70,6 +77,12 @@ vrange_storage::get_vrange (const void *slot, vrange &r, tree type) = static_cast (slot); s->get_irange (as_a (r), type); } + else if (is_a (r)) + { + const frange_storage_slot *s + = static_cast (slot); + s->get_frange (as_a (r), type); + } else gcc_unreachable (); } @@ -85,6 +98,12 @@ vrange_storage::fits_p (const void *slot, const vrange &r) = static_cast (slot); return s->fits_p (as_a (r)); } + if (is_a (r)) + { + const frange_storage_slot *s + = static_cast (slot); + return s->fits_p (as_a (r)); + } gcc_unreachable (); return false; } @@ -215,3 +234,43 @@ debug (const irange_storage_slot &storage) storage.dump (); fprintf (stderr, "\n"); } + +// Implementation of frange_storage_slot. + +frange_storage_slot * +frange_storage_slot::alloc_slot (vrange_allocator &allocator, const frange &r) +{ + size_t size = sizeof (frange_storage_slot); + frange_storage_slot *p + = static_cast (allocator.alloc (size)); + new (p) frange_storage_slot (r); + return p; +} + +void +frange_storage_slot::set_frange (const frange &r) +{ + gcc_checking_assert (fits_p (r)); + gcc_checking_assert (!r.undefined_p ()); + + m_props = r.m_props; +} + +void +frange_storage_slot::get_frange (frange &r, tree type) const +{ + gcc_checking_assert (r.supports_type_p (type)); + + r.set_varying (type); + r.m_props = m_props; + r.normalize_kind (); + + if (flag_checking) + r.verify_range (); +} + +bool +frange_storage_slot::fits_p (const frange &) const +{ + return true; +} diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h index 5a3336b673b..3fac5ea2f86 100644 --- a/gcc/value-range-storage.h +++ b/gcc/value-range-storage.h @@ -100,6 +100,25 @@ private: trailing_wide_ints m_ints; }; +// A chunk of memory to store an frange to long term memory. + +class GTY (()) frange_storage_slot +{ + public: + static frange_storage_slot *alloc_slot (vrange_allocator &, const frange &r); + void set_frange (const frange &r); + void get_frange (frange &r, tree type) const; + bool fits_p (const frange &) const; + private: + frange_storage_slot (const frange &r) { set_frange (r); } + DISABLE_COPY_AND_ASSIGN (frange_storage_slot); + + // We can get away with just storing the properties because the type + // can be gotten from the SSA, and UNDEFINED is unsupported, so it + // can only be a range. + frange_props m_props; +}; + class obstack_vrange_allocator : public vrange_allocator { public: