From patchwork Thu Nov 23 09:03:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 840705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-467766-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Xz5aSwSN"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yjD023vg5z9s3w for ; Thu, 23 Nov 2017 20:04:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=CU/EgTrcmz86xupYAP187auDJ5I7Ak0eEJGS2B2fp2dbZCWFkskqJ PrH+0BzuvI1GWwvOec+AdcptbN2COcCIxZH6hT0/W4Le/5afjqAx4FN0ogrVayxF oaquUiqqb7E94Ir8GFYKfGWbV0Kbi9RoS24Sm1iLGCOQgUDPELSpVM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=YqZO1n5WkubWui4bvpsrR2I+Kqk=; b=Xz5aSwSNBDj7h0TxArRr tGoSCo8CGpVo19py9KRg4F3TuUk5Yl2LeoJ7HbZ8+EzNw0Al34dwPjpZ4N+xCUUH O/k0V0V7WqDhjev46LwoQjGFnwF7Jx70H5IfLjXqVQJzp93FIMX/UhY4512ckgxk 9EHoU1VTaBNbmIONw4bVDcM= Received: (qmail 78310 invoked by alias); 23 Nov 2017 09:03:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 78296 invoked by uid 89); 23 Nov 2017 09:03:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, KB_WAM_FROM_NAME_SINGLEWORD, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Nov 2017 09:03:52 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9AC16AAC1 for ; Thu, 23 Nov 2017 09:03:48 +0000 (UTC) Date: Thu, 23 Nov 2017 10:03:48 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR23094 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This fixes an old missed optimization in alias disambiguation during SCCVN. We can skip a clobbering stmt if that is a store with exactly the same value as a preceeding redundancy. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2017-11-23 Richard Biener PR tree-optimization/23094 * tree-ssa-sccvn.c (vuse_ssa_val): Handle VN_TOP when we come here from walking over backedges in the first iteration. (vn_reference_lookup_3): Skip clobbers that store the same value. * gcc.dg/tree-ssa/ssa-fre-61.c: New testcase. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 255054) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -345,7 +345,12 @@ vuse_ssa_val (tree x) do { - x = SSA_VAL (x); + tree tem = SSA_VAL (x); + /* stmt walking can walk over a backedge and reach code we didn't + value-number yet. */ + if (tem == VN_TOP) + return x; + x = tem; } while (SSA_NAME_IN_FREE_LIST (x)); @@ -1868,6 +1873,39 @@ vn_reference_lookup_3 (ao_ref *ref, tree ao_ref_init (&lhs_ref, lhs); lhs_ref_ok = true; } + + /* If we reach a clobbering statement try to skip it and see if + we find a VN result with exactly the same value as the + possible clobber. In this case we can ignore the clobber + and return the found value. + Note that we don't need to worry about partial overlapping + accesses as we then can use TBAA to disambiguate against the + clobbering statement when looking up a load (thus the + VN_WALKREWRITE guard). */ + if (vn_walk_kind == VN_WALKREWRITE + && is_gimple_reg_type (TREE_TYPE (lhs)) + && types_compatible_p (TREE_TYPE (lhs), vr->type)) + { + tree *saved_last_vuse_ptr = last_vuse_ptr; + /* Do not update last_vuse_ptr in vn_reference_lookup_2. */ + last_vuse_ptr = NULL; + tree saved_vuse = vr->vuse; + hashval_t saved_hashcode = vr->hashcode; + void *res = vn_reference_lookup_2 (ref, + gimple_vuse (def_stmt), 0, vr); + /* Need to restore vr->vuse and vr->hashcode. */ + vr->vuse = saved_vuse; + vr->hashcode = saved_hashcode; + last_vuse_ptr = saved_last_vuse_ptr; + if (res && res != (void *)-1) + { + vn_reference_t vnresult = (vn_reference_t) res; + if (vnresult->result + && operand_equal_p (vnresult->result, + gimple_assign_rhs1 (def_stmt), 0)) + return res; + } + } } else if (gimple_call_builtin_p (def_stmt, BUILT_IN_NORMAL) && gimple_call_num_args (def_stmt) <= 4) Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-61.c (working copy) @@ -0,0 +1,43 @@ +/* { dg-do link } */ +/* { dg-options "-O -fdump-tree-fre1-details" } */ + +void link_error (void); + +void test1 (int *p, int *q) +{ + *p = 1; + *q = 1; + if (*p != 1) + link_error (); +} + +void test2 (int *p, int *q, int t) +{ + *p = t; + *q = t; + if (*p != t) + link_error (); +} + +void test3 (int *q, int *p) +{ + int tem = *p; + *q = tem; + if (*p != tem) + link_error (); +} + +char a[4]; +struct A { char a[4]; }; +void test4 (struct A *p) +{ + a[0] = p->a[0]; + a[0] = p->a[0]; + a[0] = p->a[0]; +} + +int main() { return 0; } + +/* { dg-final { scan-tree-dump-times "Replaced \\\*p" 3 "fre1" } } */ +/* { dg-final { scan-tree-dump-times "Replaced p_.\\(D\\)->" 2 "fre1" } } */ +/* { dg-final { scan-tree-dump-times "Deleted redundant store a\\\[0\\\]" 2 "fre1" } } */