From patchwork Mon Sep 27 13:07:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1533312 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=QLDzB7lJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4HJ2y11T7rz9tkJ for ; Mon, 27 Sep 2021 23:08:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3BB2385840F for ; Mon, 27 Sep 2021 13:08:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3BB2385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632748102; bh=xvVlpyCCVZwvM7TnMRgEBzPCyh/vOxYC1n41OWfnqdY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QLDzB7lJZbAQHtzthEUpRS4OtKIMaIdHoi81p1pdwj7PXKTS/HM6SsftlH5G3q+Oj 76T/ELEGFKAHpAkAPSRYK4XEC6Ss4FBN6C/pU47LEJYNGAoM3e5mVAlxyJ85xNhGJJ epbgdxPF1jXEkOSCz5ab1i51yXw3NLfVGSthIapM= 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 8236D3858405 for ; Mon, 27 Sep 2021 13:07:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8236D3858405 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 BCAEE22185 for ; Mon, 27 Sep 2021 13:07:55 +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 A902713A7F for ; Mon, 27 Sep 2021 13:07:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HJzIJyvCUWFIfwAAMHmgww (envelope-from ) for ; Mon, 27 Sep 2021 13:07:55 +0000 Date: Mon, 27 Sep 2021 15:07:55 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100112 - VN last_vuse and redundant store elimination Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 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" This avoids the last_vuse optimization hindering redundant store elimination by always also recording the original VUSE that was in effect on the load. Bootstrapped and tested on x86_64-unknown-linux-gnu. I'm still pondering on how to avoid the wastage of adding the ref twice and will at least record some statistics for this. 2021-09-27 Richard Biener PR tree-optimization/100112 * tree-ssa-sccvn.c (visit_reference_op_load): Record the referece into the hashtable twice in case last_vuse is different from the original vuse on the stmt. * gcc.dg/tree-ssa/ssa-fre-95.c: New testcase. --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-95.c | 25 ++++++++++++++++++++++ gcc/tree-ssa-sccvn.c | 17 +++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-95.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-95.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-95.c new file mode 100644 index 00000000000..b0936be5e77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-95.c @@ -0,0 +1,25 @@ +/* PR100112 and dups. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-fre1-details -fdump-tree-optimized" } */ + +int *c, *b; +void foo() +{ + int *tem = b; + *tem = 0; + int *footem = c; + c = footem; +} + +void bar() +{ + int *tem = b; + int *bartem = c; + *tem = 0; + c = bartem; +} + +/* We should elide the redundant store in foo, in bar it is not redundant since + the *tem = 0 store might alias. */ +/* { dg-final { scan-tree-dump "Deleted redundant store c = footem" "fre1" } } */ +/* { dg-final { scan-tree-dump "c = bartem" "optimized" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index e8b1c39184d..416a5252144 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -5125,13 +5125,12 @@ static bool visit_reference_op_load (tree lhs, tree op, gimple *stmt) { bool changed = false; - tree last_vuse; tree result; vn_reference_t res; - last_vuse = gimple_vuse (stmt); - result = vn_reference_lookup (op, gimple_vuse (stmt), - default_vn_walk_kind, &res, true, &last_vuse); + tree vuse = gimple_vuse (stmt); + tree last_vuse = vuse; + result = vn_reference_lookup (op, vuse, default_vn_walk_kind, &res, true, &last_vuse); /* We handle type-punning through unions by value-numbering based on offset and size of the access. Be prepared to handle a @@ -5174,6 +5173,16 @@ visit_reference_op_load (tree lhs, tree op, gimple *stmt) { changed = set_ssa_val_to (lhs, lhs); vn_reference_insert (op, lhs, last_vuse, NULL_TREE); + if (vuse && SSA_VAL (last_vuse) != SSA_VAL (vuse)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Using extra use virtual operand "); + print_generic_expr (dump_file, last_vuse); + fprintf (dump_file, "\n"); + } + vn_reference_insert (op, lhs, vuse, NULL_TREE); + } } return changed;