Message ID | 20211106153557.98170-1-aldyh@redhat.com |
---|---|
State | Committed |
Commit | 4856699eeb2809c50930bafe341a96470877195d |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 <patchwork@sourceware.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Aldy Hernandez via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Aldy Hernandez <aldyh@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[COMMITTED] path oracle: Do not look at root oracle for killed defs.
|
|
Commit Message
Aldy Hernandez
Nov. 6, 2021, 3:35 p.m. UTC
[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: <bb 35> [local count: 56063504182]: _134 = M.10_120 + 1; if (_71 <= _134) goto <bb 19>; [11.00%] else goto <bb 41>; [89.00%] ... ... ... <bb 41> [local count: 49896518755]: <bb 20> [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 <bb 21>; [11.00%] else goto <bb 22>; [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(+)
Comments
On Sat, Nov 6, 2021 at 4:38 PM Aldy Hernandez via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > [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: > > <bb 35> [local count: 56063504182]: > _134 = M.10_120 + 1; > if (_71 <= _134) > goto <bb 19>; [11.00%] > else > goto <bb 41>; [89.00%] > ... > ... > ... > <bb 41> [local count: 49896518755]: > > <bb 20> [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 <bb 21>; [11.00%] > else > goto <bb 22>; [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. Huh, since SSA has only a single definition it cannot be "killed". What can happen is that if you look across backedges that the same reg can have two different values. Basically when you look across backedges you have to discard all knowledge you derived from stuff that's dominated by the backedge destination. > > 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; > -- > 2.31.1 >
On 11/8/21 3:44 AM, Richard Biener via Gcc-patches wrote: > On Sat, Nov 6, 2021 at 4:38 PM Aldy Hernandez via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> [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: >> >> <bb 35> [local count: 56063504182]: >> _134 = M.10_120 + 1; >> if (_71 <= _134) >> goto <bb 19>; [11.00%] >> else >> goto <bb 41>; [89.00%] >> ... >> ... >> ... >> <bb 41> [local count: 49896518755]: >> >> <bb 20> [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 <bb 21>; [11.00%] >> else >> goto <bb 22>; [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. > Huh, since SSA has only a single definition it cannot be "killed". > What can happen is that if you look across backedges that the same > reg can have two different values. Basically when you look across > backedges you have to discard all knowledge you derived from > stuff that's dominated by the backedge destination. > Yeah, its just terminology... the path oracle follows a linear set of edges, so when we see the DEF of an ssa-name, any existing relations that have been seen have, by definition, come from a back edge at some point. If the root oracle has that relation, as in this case, it came from a back edge. "Killing" is referring to killing any relations in the path up to this point when we see the definition of the SSA_NAME. This includes anything in, or preceding, the path to this point.. We were removing any relations found in the path, but were missing the "preceding" part. Andrew
On 11/6/21 11:35 AM, Aldy Hernandez wrote: > [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: > > <bb 35> [local count: 56063504182]: > _134 = M.10_120 + 1; > if (_71 <= _134) > goto <bb 19>; [11.00%] > else > goto <bb 41>; [89.00%] > ... > ... > ... > <bb 41> [local count: 49896518755]: > > <bb 20> [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 <bb 21>; [11.00%] > else > goto <bb 22>; [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; Yeah, that is fine I think. Rangers oracle doesn't suffer from this issue since it is dominance based.. we wont find any relation from a back edge because it won't dominate the definition. The path oracle may start after a block containing a back edge, as so may inherit relations from that back edge. The path oracle operates as an add-onto the normal oracle. it simply maintains a list of relations that have been seen along the path, in the order it has seen them. these are combined with any relations rangers oracle has active at the first block in the path. That is why when we see an SSA_NAME defined while walking the path we may see relations already existing... And we need to NOT find any relation that existed before the definition. Anderw
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;