From patchwork Tue Oct 29 21:36:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 287053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A87572C036E for ; Wed, 30 Oct 2013 08:36:38 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=FwrdzeMzeV3SeCgHBqqcbVoXoy58Rbw41jQPUmHTKDehAY K8dqrpJd1ksMYcc+pD/2TkL6UtYYeBaRXcwa8iF8YtMOHtXOpwrn647UO2w7dccD ujVAjrfjPMCh/MlJO4vBpqo9YlROJ71jGF6DD2lQDjyQUmuqupecp/gBMHIzc= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=Lb3vadrGKAT5MYifbvg+VSFsd3Q=; b=u0D0+ygpxh2RWbOEnlh7 j/KqrM/3NpxjQ0CG7Gx/UHM7ttWZTagsvsXBukx2ijDX8xcioyzzckwWifnnrXGd WmL1pAcGhaYVlrFNDjKkDM+clGMPBt2F1b8YV4/aGo4y2TlmUmBLPS5VyKNEa3j/ xp39dh/gEptnL6D0j79HLRQ= Received: (qmail 20033 invoked by alias); 29 Oct 2013 21:36:32 -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 20019 invoked by uid 89); 29 Oct 2013 21:36:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Oct 2013 21:36:31 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9TLaTDh026508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 29 Oct 2013 17:36:30 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-93.phx2.redhat.com [10.3.113.93]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r9TLaTnI023443 for ; Tue, 29 Oct 2013 17:36:29 -0400 Message-ID: <52702A5D.6030101@redhat.com> Date: Tue, 29 Oct 2013 15:36:29 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: gcc-patches Subject: [RFA][PATCH] Minor fix to aliasing machinery X-IsSubscribed: yes Marc pointed out that the handling of various BUILT_IN_MEM* and BUILT_IN_STR* functions in tree-ssa-alias.c probably wasn't working as intended because the code wasn't prepared for a common return value from ao_ref_base, particularly returns of MEM_REFs. This patch fixes the code to handle the trivial case of returning a MEM_REF and adds a simple testcase. There's probably a lot more that could be done here. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. Ok for the trunk? Thanks, Jeff * tree-ssa-alias.c (stmt_kills_ref_p_1): Handle case where ao_ref_base returns a MEM_REF. * gcc.dg/tree-ssa/alias-26.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-26.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-26.c new file mode 100644 index 0000000..b5625b8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-26.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +void f (long *p) { + *p = 42; + p[4] = 42; + __builtin_memset (p, 0, 100); +} + +/* { dg-final { scan-tree-dump-not "= 42" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ + diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 4db83bd..5120e72 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -2079,6 +2079,7 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref) tree dest = gimple_call_arg (stmt, 0); tree len = gimple_call_arg (stmt, 2); tree base = NULL_TREE; + tree ref_base; HOST_WIDE_INT offset = 0; if (!host_integerp (len, 0)) return false; @@ -2087,8 +2088,11 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref) &offset); else if (TREE_CODE (dest) == SSA_NAME) base = dest; + ref_base = ao_ref_base (ref); if (base - && base == ao_ref_base (ref)) + && ((TREE_CODE (ref_base) == MEM_REF + && base == TREE_OPERAND (ref_base, 0)) + || ref_base == base)) { HOST_WIDE_INT size = TREE_INT_CST_LOW (len); if (offset <= ref->offset / BITS_PER_UNIT