From patchwork Thu Oct 31 17:11:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 287568 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 409E62C038E for ; Fri, 1 Nov 2013 04:11:43 +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=TSVtKvUxz0K/rJI2 pgUh+QKt4HdHqCRsARorbxpebsjt5uIhztJuwvyaYOFOq9CBM5JGzeLglQHehps5 TfaWyT3LuW1ev3MspVgimFoU6yyKNEkBYJj3Ygj4+7ZWNosESPGJu2zZ/unSxqnk uO/q4dkqDikEmhaF223CKJE41Sg= 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=0pWb9801KKjMjwC+MtqL4E /wocU=; b=e9p488gdurxTfRBSb4x3RuBX05H1/L5wUCRJGeYTWdyCABcbOouMAr 823O5AIt6oN4Y7IJT3PwkDpwDX5G+1zn3jq3NI3VpEntwfQTh0aj9/vdMCCjxhuC RqAP+nbVz8IAEKMC4ZIcExMCmtlEWB6E4xSWPyxk3nktTGigKd+Tk= Received: (qmail 24097 invoked by alias); 31 Oct 2013 17:11:36 -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 24081 invoked by uid 89); 31 Oct 2013 17:11:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (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; Thu, 31 Oct 2013 17:11:34 +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; 31 Oct 2013 18:11:12 +0100 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1VbvmM-0001Z6-8U; Thu, 31 Oct 2013 18:11:30 +0100 Date: Thu, 31 Oct 2013 18:11:30 +0100 (CET) From: Marc Glisse To: Richard Biener cc: Jeff Law , GCC Patches Subject: Re: Aliasing: look through pointer's def stmt In-Reply-To: Message-ID: References: <526A0269.8030407@redhat.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 On Wed, 30 Oct 2013, Richard Biener wrote: >> --- gcc/tree-ssa-alias.c (revision 204188) >> +++ gcc/tree-ssa-alias.c (working copy) >> @@ -567,20 +567,29 @@ void >> ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size) >> { >> HOST_WIDE_INT t1, t2; >> ref->ref = NULL_TREE; >> if (TREE_CODE (ptr) == SSA_NAME) >> { >> gimple stmt = SSA_NAME_DEF_STMT (ptr); >> if (gimple_assign_single_p (stmt) >> && gimple_assign_rhs_code (stmt) == ADDR_EXPR) >> ptr = gimple_assign_rhs1 (stmt); >> + else if (is_gimple_assign (stmt) >> + && gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR >> + && host_integerp (gimple_assign_rhs2 (stmt), 0) >> + && (t1 = int_cst_value (gimple_assign_rhs2 (stmt))) >= 0) > > No need to restrict this to positive offsets I think. Here is the follow-up patch to remove this restriction (bootstrap+testsuite on x86_64-unknown-linux-gnu). I don't really know how safe it is. I couldn't use host_integerp(,1) since it returns false for (size_t)(-1) on x86_64, and host_integerp(,0) seemed strange, but I could use it if you want. 2013-11-01 Marc Glisse gcc/ * tree-ssa-alias.h (ranges_overlap_p): Handle negative offsets. * tree-ssa-alias.c (ao_ref_init_from_ptr_and_size): Likewise. gcc/testsuite/ * gcc.dg/tree-ssa/alias-26.c: New file. Index: gcc/testsuite/gcc.dg/tree-ssa/alias-26.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/alias-26.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/alias-26.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +void f (const char *c, int *i) +{ + *i = 42; + __builtin_memcpy (i - 1, c, sizeof (int)); + if (*i != 42) __builtin_abort(); +} + +/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ + Property changes on: gcc/testsuite/gcc.dg/tree-ssa/alias-26.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 204267) +++ gcc/tree-ssa-alias.c (working copy) @@ -552,42 +552,42 @@ ao_ref_base_alias_set (ao_ref *ref) alias_set_type ao_ref_alias_set (ao_ref *ref) { if (ref->ref_alias_set != -1) return ref->ref_alias_set; ref->ref_alias_set = get_alias_set (ref->ref); return ref->ref_alias_set; } /* Init an alias-oracle reference representation from a gimple pointer - PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE the the + PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE then the size is assumed to be unknown. The access is assumed to be only to or after of the pointer target, not before it. */ void ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size) { HOST_WIDE_INT t1, t2, extra_offset = 0; ref->ref = NULL_TREE; if (TREE_CODE (ptr) == SSA_NAME) { gimple stmt = SSA_NAME_DEF_STMT (ptr); if (gimple_assign_single_p (stmt) && gimple_assign_rhs_code (stmt) == ADDR_EXPR) ptr = gimple_assign_rhs1 (stmt); else if (is_gimple_assign (stmt) && gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR - && host_integerp (gimple_assign_rhs2 (stmt), 0) - && (t1 = int_cst_value (gimple_assign_rhs2 (stmt))) >= 0) + && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST) { ptr = gimple_assign_rhs1 (stmt); - extra_offset = BITS_PER_UNIT * t1; + extra_offset = BITS_PER_UNIT + * int_cst_value (gimple_assign_rhs2 (stmt)); } } if (TREE_CODE (ptr) == ADDR_EXPR) ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0), &ref->offset, &t1, &t2); else { ref->base = build2 (MEM_REF, char_type_node, ptr, null_pointer_node); Index: gcc/tree-ssa-alias.h =================================================================== --- gcc/tree-ssa-alias.h (revision 204267) +++ gcc/tree-ssa-alias.h (working copy) @@ -139,30 +139,30 @@ extern void pt_solution_set_var (struct extern void dump_pta_stats (FILE *); extern GTY(()) struct pt_solution ipa_escaped_pt; /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2] overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the range is open-ended. Otherwise return false. */ static inline bool -ranges_overlap_p (unsigned HOST_WIDE_INT pos1, - unsigned HOST_WIDE_INT size1, - unsigned HOST_WIDE_INT pos2, - unsigned HOST_WIDE_INT size2) +ranges_overlap_p (HOST_WIDE_INT pos1, + HOST_WIDE_INT size1, + HOST_WIDE_INT pos2, + HOST_WIDE_INT size2) { if (pos1 >= pos2 - && (size2 == (unsigned HOST_WIDE_INT)-1 + && (size2 == -1 || pos1 < (pos2 + size2))) return true; if (pos2 >= pos1 - && (size1 == (unsigned HOST_WIDE_INT)-1 + && (size1 == -1 || pos2 < (pos1 + size1))) return true; return false; } #endif /* TREE_SSA_ALIAS_H */