From patchwork Mon May 22 18:56:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 97566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1654206vqo; Mon, 22 May 2023 11:58:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7O9bOEwTYWDYwKXFumW44pnpjhMORFgVIWE9gCYvTQPLw7ewDowaLbFBbUXPMoq+ARJg1G X-Received: by 2002:a17:907:c21:b0:958:801b:9945 with SMTP id ga33-20020a1709070c2100b00958801b9945mr11229590ejc.31.1684781884920; Mon, 22 May 2023 11:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684781884; cv=none; d=google.com; s=arc-20160816; b=vKmqnOoe4Gnnqt1/cg5PZ6tOtAjbunot+JISAhyiHUC9M33j0oUXdSsdTxeH3kncF+ uc/+oV2rDVWsIHFLbgx4O9gJ+VOmECLYnXMVRPmKV+vwTn7O5Hly8XovhGpE3pOHqqVG WVOFXDQOgr623orGdxIcWkeMiNBIuU8K512PnMOyRv9ATdcBS2i+COjqJLXp8RoJelEq teZgzukAi50Km7Y3INW6tp/gOHpmWWji8dsLIsTFXD/C6aOm1lhEJGv37jOAJhmhM3au 0CdfpBzZuy/Kj+b6iD/DcbVf9l0E4JBDUpp62J4mTwzetAhGVsrs0blx1gdzji9Z0opC oNRA== 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:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=bf5gAyXb2aub8t8+Kvn+5bJxXlWUb4smQBMn8V9q9pQ=; b=pjSSvF1jAyj60tKEe5et58PNvB+/ibtkOOlNlUAnVZlM3UY4a8GCws+Eli9Wqe7R+b WDsHrocaeu2RNtSkg1RE7abpYorsU9Xlwa1NfZPNxOpx+MrPNDYREARr4kuufoct5YBI KFBd3JSJq2qavjkSlJDOsnL81T6+XHj6yS2GrAEmj984bID4U97+6+dhEOkQjWiFBB1h Ym6tO0nHSszWD9aqLoLUxf3rYihX4yrIVb1CS/EFgxGVNnv0pre/EESjr7wHAW6MZduA MKmgECmMufglHQ1j144EV/n2O1czyAmeDLgdHd1G3+ZZwfyMPA+sAGo5MLdEmCz3E1PA n7+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vrHOJiDN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a22-20020a17090682d600b0096f86264088si310387ejy.624.2023.05.22.11.58.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 11:58:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vrHOJiDN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD83A385700D for ; Mon, 22 May 2023 18:57:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD83A385700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684781848; bh=bf5gAyXb2aub8t8+Kvn+5bJxXlWUb4smQBMn8V9q9pQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vrHOJiDNSE43E3qFq1N9tZASM8aNAeyMcDWsHtAVn0QCHVqHfvgPGXjc6UtRLiHDA kyZmCv7vxmaKGMI5qhDtAVwvt1QF5WVB//CsKD6JuHTnlzI1ACEIJLs/zwZ+w7X6Dk OtSZBXmv9XrVr/KMwUUgvYj+1cEP54QzonsQbOzc= 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 D61BF385841D for ; Mon, 22 May 2023 18:56:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D61BF385841D Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-nbw134WROfuDT2LQIl_GBQ-1; Mon, 22 May 2023 14:56:40 -0400 X-MC-Unique: nbw134WROfuDT2LQIl_GBQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 795F33C01DE8 for ; Mon, 22 May 2023 18:56:40 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1189B1121314; Mon, 22 May 2023 18:56:39 +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 34MIubJG537485 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 22 May 2023 20:56:37 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 34MIub1f537484; Mon, 22 May 2023 20:56:37 +0200 To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [PATCH] Implement ipa_vr hashing. Date: Mon, 22 May 2023 20:56:21 +0200 Message-Id: <20230522185622.537454-2-aldyh@redhat.com> In-Reply-To: <20230522185622.537454-1-aldyh@redhat.com> References: <20230522185622.537454-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: 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?1766621849400401012?= X-GMAIL-MSGID: =?utf-8?q?1766621849400401012?= Implement hashing for ipa_vr. When all is said and done, all these patches incurr a 7.64% slowdown for ipa-cp, with is entirely covered by the similar 7% increase in this area last week. So we get type agnostic ranges with "infinite" range precision close to free. There is no change in overall compilation. OK? gcc/ChangeLog: * ipa-prop.cc (struct ipa_vr_ggc_hash_traits): Adjust for use with ipa_vr instead of value_range. (gt_pch_nx): Same. (gt_ggc_mx): Same. (ipa_get_value_range): Same. * value-range.cc (gt_pch_nx): Move to ipa-prop.cc and adjust for ipa_vr. (gt_ggc_mx): Same. --- gcc/ipa-prop.cc | 76 +++++++++++++++++++++++++++------------------- gcc/value-range.cc | 15 --------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index c46a89f1b49..6383bc11e0a 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -109,53 +109,53 @@ struct ipa_bit_ggc_hash_traits : public ggc_cache_remove /* Hash table for avoid repeated allocations of equal ipa_bits. */ static GTY ((cache)) hash_table *ipa_bits_hash_table; -/* Traits for a hash table for reusing value_ranges used for IPA. Note that - the equiv bitmap is not hashed and is expected to be NULL. */ +/* Traits for a hash table for reusing ranges. */ -struct ipa_vr_ggc_hash_traits : public ggc_cache_remove +struct ipa_vr_ggc_hash_traits : public ggc_cache_remove { - typedef value_range *value_type; - typedef value_range *compare_type; + typedef ipa_vr *value_type; + typedef const vrange *compare_type; static hashval_t - hash (const value_range *p) + hash (const ipa_vr *p) { - tree min, max; - value_range_kind kind = get_legacy_range (*p, min, max); - inchash::hash hstate (kind); - inchash::add_expr (min, hstate); - inchash::add_expr (max, hstate); + // This never get called, except in the verification code, as + // ipa_get_value_range() calculates the hash itself. This + // function is mostly here for completness' sake. + Value_Range vr; + p->get_vrange (vr); + inchash::hash hstate; + add_vrange (vr, hstate); return hstate.end (); } static bool - equal (const value_range *a, const value_range *b) + equal (const ipa_vr *a, const vrange *b) { - return (types_compatible_p (a->type (), b->type ()) - && *a == *b); + return a->equal_p (*b); } static const bool empty_zero_p = true; static void - mark_empty (value_range *&p) + mark_empty (ipa_vr *&p) { p = NULL; } static bool - is_empty (const value_range *p) + is_empty (const ipa_vr *p) { return p == NULL; } static bool - is_deleted (const value_range *p) + is_deleted (const ipa_vr *p) { - return p == reinterpret_cast (1); + return p == reinterpret_cast (1); } static void - mark_deleted (value_range *&p) + mark_deleted (ipa_vr *&p) { - p = reinterpret_cast (1); + p = reinterpret_cast (1); } }; -/* Hash table for avoid repeated allocations of equal value_ranges. */ +/* Hash table for avoid repeated allocations of equal ranges. */ static GTY ((cache)) hash_table *ipa_vr_hash_table; /* Holders of ipa cgraph hooks: */ @@ -265,6 +265,22 @@ ipa_vr::dump (FILE *out) const fprintf (out, "NO RANGE"); } +// ?? These stubs are because we use an ipa_vr in a hash_traits and +// hash-traits.h defines an extern of gt_ggc_mx (T &) instead of +// picking up the gt_ggc_mx (T *) version. +void +gt_pch_nx (ipa_vr *&x) +{ + return gt_pch_nx ((ipa_vr *) x); +} + +void +gt_ggc_mx (ipa_vr *&x) +{ + return gt_ggc_mx ((ipa_vr *) x); +} + + /* Return true if DECL_FUNCTION_SPECIFIC_OPTIMIZATION of the decl associated with NODE should prevent us from analyzing it for the purposes of IPA-CP. */ @@ -2284,27 +2300,25 @@ ipa_set_jfunc_bits (ipa_jump_func *jf, const widest_int &value, jf->bits = ipa_get_ipa_bits_for_value (value, mask); } -/* Return a pointer to a value_range just like *TMP, but either find it in - ipa_vr_hash_table or allocate it in GC memory. TMP->equiv must be NULL. */ +/* Return a pointer to an ipa_vr just like TMP, but either find it in + ipa_vr_hash_table or allocate it in GC memory. */ static ipa_vr * ipa_get_value_range (const vrange &tmp) { - /* FIXME: Add hashing support. - value_range **slot = ipa_vr_hash_table->find_slot (tmp, INSERT); + inchash::hash hstate; + inchash::add_vrange (tmp, hstate); + hashval_t hash = hstate.end (); + ipa_vr **slot = ipa_vr_hash_table->find_slot_with_hash (&tmp, hash, INSERT); if (*slot) return *slot; - value_range *vr = new (ggc_alloc ()) value_range; - *vr = *tmp; - *slot = vr; - */ ipa_vr *vr = new (ggc_alloc ()) ipa_vr (tmp); - + *slot = vr; return vr; } -/* Assign to JF a pointer to a value_range just like TMP but either fetch a +/* Assign to JF a pointer to a range just like TMP but either fetch a copy from ipa_vr_hash_table or allocate a new on in GC memory. */ static void diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 45b1e655967..7b81025357b 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -2008,21 +2008,6 @@ gt_pch_nx (vrange *x, gt_pointer_operator op, void *cookie) gcc_unreachable (); } -// ?? These stubs are for ipa-prop.cc which use a value_range in a -// hash_traits. hash-traits.h defines an extern of gt_ggc_mx (T &) -// instead of picking up the gt_ggc_mx (T *) version. -void -gt_pch_nx (int_range<2> *&x) -{ - return gt_pch_nx ((irange *) x); -} - -void -gt_ggc_mx (int_range<2> *&x) -{ - return gt_ggc_mx ((irange *) x); -} - #define DEFINE_INT_RANGE_INSTANCE(N) \ template int_range::int_range(tree_node *, \ const wide_int &, \