From patchwork Fri Nov 8 23:18:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 289938 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E384B2C00C2 for ; Sat, 9 Nov 2013 10:18:54 +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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=jyNT4eUU3udMDePF l1W/mEp3BD/GtKA2RorswSbeJbkc39A8g0BJi2v1UfR23hnzc3JpeaAxUSNqGmuy z4tgeXcjW58esKUH+2djNtTdqh3drPBPe3YvfeFU9xzoZnqlE3sZNLdjyGlLVpO0 DfbtnloHivYHYG8MZraMJhopLZ4= 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:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=KS0GKXV/McwEMioa9eRWrN aFcJk=; b=ZTl9IA3UHmX2dmbxHtP86gTRs8b7xAMyz73dw0jRA78dcoKAowTpiE PjG/172vUP3YiLM9+XhZhTnVTBJNXwfQbp5xG9MVM4gdRUZ+xK8LI/9kDxKzsRF8 BuDttfIun3XnTGvYl2RBuAhazVDSP0ARGiDBngQ2joOysyumvag4Y= Received: (qmail 23840 invoked by alias); 8 Nov 2013 23:18:44 -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 23831 invoked by uid 89); 8 Nov 2013 23:18:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail2-relais-roc.national.inria.fr Received: from Unknown (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Fri, 08 Nov 2013 23:18:42 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 09 Nov 2013 00:18:33 +0100 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1VevJx-0001s3-Au; Sat, 09 Nov 2013 00:18:33 +0100 Date: Sat, 9 Nov 2013 00:18:33 +0100 (CET) From: Marc Glisse To: Richard Biener cc: Jeff Law , gcc-patches Subject: Re: [RFA][PATCH] Minor fix to aliasing machinery In-Reply-To: Message-ID: References: <52702A5D.6030101@redhat.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 On Wed, 6 Nov 2013, Richard Biener wrote: > So the only thing that remains is the mem_ref_offset thing and yes, I guess > I'd prefer to use double-ints because we deal with bit offsets in the end. Here it is (bootstrap+testsuite on x86_64-unknown-linux-gnu). It feels rather artificial to do this small bit of computation with double_int when so much else assumes HWI is enough, but why not... 2013-11-09 Marc Glisse Jeff Law gcc/ * tree-ssa-alias.c (stmt_kills_ref_p_1): Use ao_ref_init_from_ptr_and_size for builtins. gcc/testsuite/ * gcc.dg/tree-ssa/alias-27.c: New testcase. Index: gcc/testsuite/gcc.dg/tree-ssa/alias-27.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/alias-27.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/alias-27.c (working copy) @@ -0,0 +1,11 @@ +/* { 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" } } */ Property changes on: gcc/testsuite/gcc.dg/tree-ssa/alias-27.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: gcc/tree-ssa-alias.c =================================================================== --- gcc/tree-ssa-alias.c (revision 204608) +++ gcc/tree-ssa-alias.c (working copy) @@ -2001,23 +2001,24 @@ stmt_may_clobber_ref_p (gimple stmt, tre return stmt_may_clobber_ref_p_1 (stmt, &r); } /* If STMT kills the memory reference REF return true, otherwise return false. */ static bool stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref) { /* For a must-alias check we need to be able to constrain - the access properly. */ - ao_ref_base (ref); - if (ref->max_size == -1) + the access properly. + FIXME: except for BUILTIN_FREE. */ + if (!ao_ref_base (ref) + || ref->max_size == -1) return false; if (gimple_has_lhs (stmt) && TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME /* The assignment is not necessarily carried out if it can throw and we can catch it in the current function where we could inspect the previous value. ??? We only need to care about the RHS throwing. For aggregate assignments or similar calls and non-call exceptions the LHS might throw as well. */ @@ -2090,37 +2091,47 @@ stmt_kills_ref_p_1 (gimple stmt, ao_ref case BUILT_IN_MEMPCPY: case BUILT_IN_MEMMOVE: case BUILT_IN_MEMSET: case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMPCPY_CHK: case BUILT_IN_MEMMOVE_CHK: case BUILT_IN_MEMSET_CHK: { tree dest = gimple_call_arg (stmt, 0); tree len = gimple_call_arg (stmt, 2); - tree base = NULL_TREE; - HOST_WIDE_INT offset = 0; if (!host_integerp (len, 0)) return false; - if (TREE_CODE (dest) == ADDR_EXPR) - base = get_addr_base_and_unit_offset (TREE_OPERAND (dest, 0), - &offset); - else if (TREE_CODE (dest) == SSA_NAME) - base = dest; - if (base - && base == ao_ref_base (ref)) + tree rbase = ref->base; + double_int roffset = double_int::from_shwi (ref->offset); + ao_ref dref; + ao_ref_init_from_ptr_and_size (&dref, dest, len); + tree base = ao_ref_base (&dref); + double_int offset = double_int::from_shwi (dref.offset); + double_int bpu = double_int::from_uhwi (BITS_PER_UNIT); + if (!base || dref.size == -1) + return false; + if (TREE_CODE (base) == MEM_REF) + { + if (TREE_CODE (rbase) != MEM_REF) + return false; + // Compare pointers. + offset += bpu * mem_ref_offset (base); + roffset += bpu * mem_ref_offset (rbase); + base = TREE_OPERAND (base, 0); + rbase = TREE_OPERAND (rbase, 0); + } + if (base == rbase) { - HOST_WIDE_INT size = TREE_INT_CST_LOW (len); - if (offset <= ref->offset / BITS_PER_UNIT - && (offset + size - >= ((ref->offset + ref->max_size + BITS_PER_UNIT - 1) - / BITS_PER_UNIT))) + double_int size = bpu * tree_to_double_int (len); + double_int rsize = double_int::from_uhwi (ref->max_size); + if (offset.sle (roffset) + && (roffset + rsize).sle (offset + size)) return true; } break; } case BUILT_IN_VA_END: { tree ptr = gimple_call_arg (stmt, 0); if (TREE_CODE (ptr) == ADDR_EXPR) {