From patchwork Sat Nov 6 15:35:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 47163 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 C29333857C7B for ; Sat, 6 Nov 2021 15:37:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C29333857C7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636213075; bh=zfoNufmZvbK50syO0q03X0D0E8ToLvyja7r+N7WCCUQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Yh+tutawRKA/HJnDwGr2bLEvWH6ef5rlAmY77g5SUOWQu8FqDNIPUrL/Z0qih/Y6z meKGQBgOmCl6ZtMxh6a5i/0JMTgrEAuCtshXc1aOODvCzeaBly8F6+IOdkgz+AGu5g Mq+LTAmswBBWbzuTBuI/e7jr087M0I47jncsqlDg= 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 B9D19385800F for ; Sat, 6 Nov 2021 15:36:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9D19385800F 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-355-xawySnk6OPmRgpQovHOG3A-1; Sat, 06 Nov 2021 11:36:16 -0400 X-MC-Unique: xawySnk6OPmRgpQovHOG3A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FD491808308 for ; Sat, 6 Nov 2021 15:36:06 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1FFCD60C9F; Sat, 6 Nov 2021 15:36:05 +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 1A6Fa2f5098298 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 6 Nov 2021 16:36:03 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1A6Fa27s098295; Sat, 6 Nov 2021 16:36:02 +0100 To: GCC patches Subject: [COMMITTED] path oracle: Do not look at root oracle for killed defs. Date: Sat, 6 Nov 2021 16:35:57 +0100 Message-Id: <20211106153557.98170-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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, 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" [This is more Andrew's domain, but this is a P1 PR and I'd like to unbreak the SPEC run, since this is a straigthforward fix. When he returns he can double check my work and give additional suggestions.] The problem here is that we are incorrectly threading 41->20->21 here: [local count: 56063504182]: _134 = M.10_120 + 1; if (_71 <= _134) goto ; [11.00%] else goto ; [89.00%] ... ... ... [local count: 49896518755]: [local count: 56063503181]: # lb_75 = PHI <_134(41), 1(18)> _117 = mstep_49 + lb_75; _118 = _117 + -1; _119 = mstep_49 + _118; M.10_120 = MIN_EXPR <_119, _71>; if (lb_75 > M.10_120) goto ; [11.00%] else goto ; [89.00%] First, lb_17 == _134 because of the PHI. Second, _134 > M.10_120 because of _134 = M.10_120 + 1. We then assume that lb_75 > M.10_120, but this is incorrect because M.10_120 was killed along the path. This incorrect thread causes the miscompilation in 527.cam4_r. Tested on x86-64 and ppc64le Linux. Committed. gcc/ChangeLog: PR tree-optimization/103061 * value-relation.cc (path_oracle::path_oracle): Initialize m_killed_defs. (path_oracle::killing_def): Set m_killed_defs. (path_oracle::query_relation): Do not look at the root oracle for killed defs. * value-relation.h (class path_oracle): Add m_killed_defs. --- gcc/value-relation.cc | 9 +++++++++ gcc/value-relation.h | 1 + 2 files changed, 10 insertions(+) diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index f1e46d38de1..a0105481466 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -1235,6 +1235,7 @@ path_oracle::path_oracle (relation_oracle *oracle) m_equiv.m_next = NULL; m_relations.m_names = BITMAP_ALLOC (&m_bitmaps); m_relations.m_head = NULL; + m_killed_defs = BITMAP_ALLOC (&m_bitmaps); } path_oracle::~path_oracle () @@ -1305,6 +1306,8 @@ path_oracle::killing_def (tree ssa) unsigned v = SSA_NAME_VERSION (ssa); + bitmap_set_bit (m_killed_defs, v); + // Walk the equivalency list and remove SSA from any equivalencies. if (bitmap_bit_p (m_equiv.m_names, v)) { @@ -1389,6 +1392,12 @@ path_oracle::query_relation (basic_block bb, const_bitmap b1, const_bitmap b2) relation_kind k = m_relations.find_relation (b1, b2); + // Do not look at the root oracle for names that have been killed + // along the path. + if (bitmap_intersect_p (m_killed_defs, b1) + || bitmap_intersect_p (m_killed_defs, b2)) + return k; + if (k == VREL_NONE && m_root) k = m_root->query_relation (bb, b1, b2); diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 97be3251144..8086f5552b5 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -233,6 +233,7 @@ private: equiv_chain m_equiv; relation_chain_head m_relations; relation_oracle *m_root; + bitmap m_killed_defs; bitmap_obstack m_bitmaps; struct obstack m_chain_obstack;