From patchwork Fri Oct 22 10:48:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 46527 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92B913857C52 for ; Fri, 22 Oct 2021 10:49:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92B913857C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634899768; bh=a8zlFtC323CxoG/YSDQFd3Etq/98QJuukstkxJ0O+2g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=w0s8xZU1IfNASyJYzK14V3x4AhjngF3g//sNAW4TKAbjFR1ol2T79+nMHZ8Rdl70S xlrQYqsbPqLOsOIpYf+vK2WSXLjpUDl/gEBf49MsgzpGGodRpE3SiK+TA9k2xsWYFt zmmhV/XesFe/wQOhO7AUX6Clbr328idxM6s42J0o= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 753B1385840A for ; Fri, 22 Oct 2021 10:48:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 753B1385840A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-WYfO--XpMamEPDdquPlODQ-1; Fri, 22 Oct 2021 06:48:57 -0400 X-MC-Unique: WYfO--XpMamEPDdquPlODQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C63710A8E00; Fri, 22 Oct 2021 10:48:56 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A152E16A42; Fri, 22 Oct 2021 10:48:37 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 19MAmYZD079662 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Oct 2021 12:48:35 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 19MAmYvN079661; Fri, 22 Oct 2021 12:48:34 +0200 To: GCC patches Subject: [COMMITTED] Disregard incoming equivalences to a path when defining a new one. Date: Fri, 22 Oct 2021 12:48:31 +0200 Message-Id: <20211022104831.79592-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The equivalence oracle creates a new equiv set at each def point, killing any incoming equivalences, however in the path sensitive oracle we create brand new equivalences at each PHI: BB4: BB8: x_5 = PHI Here we note that x_5 == y_8 at the end of the path. The current code is intersecting this new equivalence with previously known equivalences coming into the path. This is incorrect, as this is a new definition. This patch kills any known equivalence before we register a new one. This hasn't caused problems so far, but upcoming changes to the pipeline has us threading more aggressively and triggering corner cases where this causes incorrect code. I have tested this patch with the usual regstrap cycle. I have also hacked a compiler comparing the old and new behavior to see if we were previously threading paths where the decision was made due to invalid equivalences. Luckily, there were no such paths, but there were 22 paths in a set of .ii files where disregarding incoming relations allowed us to thread the path. This is a miniscule improvement, but we moved a handful of thredable paths earlier in the pipeline, which is always good. Tested on x86-64 Linux. Co-authored-by: Andrew MacLeod gcc/ChangeLog: * gimple-range-path.cc (path_range_query::compute_phi_relations): Kill any global relations we may know before registering a new one. * value-relation.cc (path_oracle::killing_def): New. * value-relation.h (path_oracle::killing_def): New. --- gcc/gimple-range-path.cc | 10 +++++++++- gcc/value-relation.cc | 23 +++++++++++++++++++++++ gcc/value-relation.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 694271306a7..557338993ae 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -698,7 +698,15 @@ path_range_query::compute_phi_relations (basic_block bb, basic_block prev) tree arg = gimple_phi_arg_def (phi, i); if (gimple_range_ssa_p (arg)) - m_oracle->register_relation (entry, EQ_EXPR, arg, result); + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " from bb%d:", bb->index); + + // Throw away any previous relation. + get_path_oracle ()->killing_def (result); + + m_oracle->register_relation (entry, EQ_EXPR, arg, result); + } break; } diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index ac5f3f9afc0..2acf375ca9a 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -1285,6 +1285,29 @@ path_oracle::register_equiv (basic_block bb, tree ssa1, tree ssa2) bitmap_ior_into (m_equiv.m_names, b); } +// Register killing definition of an SSA_NAME. + +void +path_oracle::killing_def (tree ssa) +{ + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, " Registering killing_def (path_oracle) "); + print_generic_expr (dump_file, ssa, TDF_SLIM); + fprintf (dump_file, "\n"); + } + + bitmap b = BITMAP_ALLOC (&m_bitmaps); + bitmap_set_bit (b, SSA_NAME_VERSION (ssa)); + equiv_chain *ptr = (equiv_chain *) obstack_alloc (&m_chain_obstack, + sizeof (equiv_chain)); + ptr->m_names = b; + ptr->m_bb = NULL; + ptr->m_next = m_equiv.m_next; + m_equiv.m_next = ptr; + bitmap_ior_into (m_equiv.m_names, b); +} + // Register relation K between SSA1 and SSA2, resolving unknowns by // querying from BB. diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 53cefbfa7dc..97be3251144 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -222,6 +222,7 @@ public: ~path_oracle (); const_bitmap equiv_set (tree, basic_block); void register_relation (basic_block, relation_kind, tree, tree); + void killing_def (tree); relation_kind query_relation (basic_block, tree, tree); relation_kind query_relation (basic_block, const_bitmap, const_bitmap); void reset_path ();