From patchwork Fri Oct 22 09:40:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1544859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DN8HbOXj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbKB02w2Kz9ssP for ; Fri, 22 Oct 2021 20:41:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DB08385782A for ; Fri, 22 Oct 2021 09:41:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DB08385782A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634895700; bh=gJSNKlhV6NgTsstzk3O9IxjxaeZTXDzK6TC8/xyLhLg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DN8HbOXja3zMxqfzxKVvWyJmP1+l7hB4D0qrS1Jy8vDEf4GhNyYWdH0fck90IqioZ MLtHFrD1kL2KyBYSNr7KBdVg51JvZSDcVxQBvRlADR+4r8IpORM6zPA6+fC5ak9EDS BIJDPW7uk2MvPC5gupgtwds6kktIjEqgcBAqxkKk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 89F5D3857820 for ; Fri, 22 Oct 2021 09:40:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89F5D3857820 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 61DB8212C8 for ; Fri, 22 Oct 2021 09:40:44 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4ECB913CA7 for ; Fri, 22 Oct 2021 09:40:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gJ4XEhyHcmGbaQAAMHmgww (envelope-from ) for ; Fri, 22 Oct 2021 09:40:44 +0000 Date: Fri, 22 Oct 2021 11:40:43 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] bootstrap/102681 - properly CSE PHIs with default def args Message-ID: <35163823-351n-r193-2nr7-9oq541n1130@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The PR shows that we fail to CSE PHIs containing (different) default definitions due to the fact on how we now handle on-demand build of VN_INFO. The following fixes this in the same way the PHI visitation code does. On gcc.dg/ubsan/pr81981.c this causes one expected warning to be elided since the uninit pass sees the change [local count: 1073741824]: # u$0_2 = PHI - # cstore_11 = PHI v = u$0_2; - return cstore_11; + return u$0_2; and thus only one of the conditionally uninitialized uses (the other became dead). I have XFAILed the missing diagnostic, I don't see a way to preserve that. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-10-22 Richard Biener PR bootstrap/102681 * tree-ssa-sccvn.c (vn_phi_insert): For undefined SSA args record VN_TOP. (vn_phi_lookup): Likewise. * gcc.dg/tree-ssa/ssa-fre-97.c: New testcase. * gcc.dg/ubsan/pr81981.c: XFAIL one case. --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/ubsan/pr81981.c | 2 +- gcc/tree-ssa-sccvn.c | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c new file mode 100644 index 00000000000..2f09c8baeb8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* ethread threading does not yet catch this but it might at some point. */ +/* { dg-options "-O -fdump-tree-fre1-details -fno-thread-jumps" } */ + +int foo (int b, int x) +{ + int i, j; + if (b) + i = x; + if (b) + j = x; + return j == i; +} + +/* Even with different undefs we should CSE a PHI node with the + same controlling condition. */ + +/* { dg-final { scan-tree-dump "Replaced redundant PHI node" "fre1" } } */ +/* { dg-final { scan-tree-dump "return 1;" "fre1" } } */ diff --git a/gcc/testsuite/gcc.dg/ubsan/pr81981.c b/gcc/testsuite/gcc.dg/ubsan/pr81981.c index 8a6597c84c8..d201efb3f65 100644 --- a/gcc/testsuite/gcc.dg/ubsan/pr81981.c +++ b/gcc/testsuite/gcc.dg/ubsan/pr81981.c @@ -16,6 +16,6 @@ foo (int i) u[0] = i; } - v = u[0]; /* { dg-warning "may be used uninitialized" } */ + v = u[0]; /* { dg-warning "may be used uninitialized" "" { xfail *-*-* } } */ return t[0]; /* { dg-warning "may be used uninitialized" } */ } diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index ae0172a143e..893b1d0ddaa 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -4499,7 +4499,12 @@ vn_phi_lookup (gimple *phi, bool backedges_varying_p) tree def = PHI_ARG_DEF_FROM_EDGE (phi, e); if (TREE_CODE (def) == SSA_NAME && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))) - def = SSA_VAL (def); + { + if (ssa_undefined_value_p (def, false)) + def = VN_TOP; + else + def = SSA_VAL (def); + } vp1->phiargs[e->dest_idx] = def; } vp1->type = TREE_TYPE (gimple_phi_result (phi)); @@ -4543,7 +4548,12 @@ vn_phi_insert (gimple *phi, tree result, bool backedges_varying_p) tree def = PHI_ARG_DEF_FROM_EDGE (phi, e); if (TREE_CODE (def) == SSA_NAME && (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))) - def = SSA_VAL (def); + { + if (ssa_undefined_value_p (def, false)) + def = VN_TOP; + else + def = SSA_VAL (def); + } vp1->phiargs[e->dest_idx] = def; } vp1->value_id = VN_INFO (result)->value_id;