From patchwork Wed Dec 9 05:11:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 554235 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9BDDB140213 for ; Wed, 9 Dec 2015 16:11:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=B9FN1LQW; dkim-atps=neutral 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=l2eL/nJ2F6JNj/vx5+a8EWu2rvVlZ9YOVEBaFHXK4RIL0hZLrU7qL xX8/fbXHQ7BfL8ElUsqZcEpS09DN9ZwfY0EO5trhaLdkM7dThhaI0rTGxCftdPOE GE3INy4gMKA1sI9g3cHDrlXozcorVrV9E7V+NJZuQ0lwb7Fd0YuVJQ= 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=hxfNJ3LI/JqhZYd8jbsul9L3efQ=; b=B9FN1LQWVaLp631saq8u n6JxIDrA3buR5n/qIKr1HoPul4p7q4rb9gkKrIKEmPJMHC6Q6HruZTzTzIbofTWM Qm7Dc4uW0f99AxofvKfNaCQvKWMum6MdAfL6cbPgXwgDoynCMbawe6NY200fN921 UPV2Pk1x8pZJTfwccjxmtuY= Received: (qmail 100614 invoked by alias); 9 Dec 2015 05:11:45 -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 100600 invoked by uid 89); 9 Dec 2015 05:11:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 09 Dec 2015 05:11:42 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 8C0A0540762; Wed, 9 Dec 2015 06:11:37 +0100 (CET) Date: Wed, 9 Dec 2015 06:11:37 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Transparent alias suport part 8 (equal_address_to support) Message-ID: <20151209051137.GA39879@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, this patch makes symtab_node::equal_address_to to understand transparent aliases and always return true for symbol and its transparent alias. In addition I introduced new parameter MEMORY_ACCESSED which makes the function useful for base/ofset alias oracle implementation. We are bit schisofrenic about assumptions when aliases can happen. i.e. &global_var == &globa_var2 will not fold to false, because we think that the variables may be aliases, but global_var = 1; global_var2 = 2; return global_var will return 1 becuase the alias oracle assumes aliases to not exist. I think we could have optimization flag controling this and switch to the assumption that there are no invisible aliases next stage1. For now I am preserving current schisofreny - see the end of the patch so we won't lose too many of alias oracle hits. Bootstrapped/regtested x86_64-linux, comitted. * symtab.c (symtab_node::equal_address_to): New parameter MEMORY_ACCESSED. * cgraph.h (symtab_node::equal_address_to): Update prototype. Index: symtab.c =================================================================== --- symtab.c (revision 231439) +++ symtab.c (working copy) @@ -1878,9 +1878,14 @@ symtab_node::nonzero_address () /* Return 0 if symbol is known to have different address than S2, Return 1 if symbol is known to have same address as S2, - return 2 otherwise. */ + return 2 otherwise. + + If MEMORY_ACCESSED is true, assume that both memory pointer to THIS + and S2 is going to be accessed. This eliminates the situations when + either THIS or S2 is NULL and is seful for comparing bases when deciding + about memory aliasing. */ int -symtab_node::equal_address_to (symtab_node *s2) +symtab_node::equal_address_to (symtab_node *s2, bool memory_accessed) { enum availability avail1, avail2; @@ -1888,6 +1893,16 @@ symtab_node::equal_address_to (symtab_no if (this == s2) return 1; + /* Unwind transparent aliases first; those are always equal to their + target. */ + if (this->transparent_alias && this->analyzed) + return this->get_alias_target ()->equal_address_to (s2); + while (s2->transparent_alias && s2->analyzed) + s2 = s2->get_alias_target(); + + if (this == s2) + return 1; + /* For non-interposable aliases, lookup and compare their actual definitions. Also check if the symbol needs to bind to given definition. */ symtab_node *rs1 = ultimate_alias_target (&avail1); @@ -1924,8 +1939,9 @@ symtab_node::equal_address_to (symtab_no return 1; } - /* If both symbols may resolve to NULL, we can not really prove them different. */ - if (!nonzero_address () && !s2->nonzero_address ()) + /* If both symbols may resolve to NULL, we can not really prove them + different. */ + if (!memory_accessed && !nonzero_address () && !s2->nonzero_address ()) return 2; /* Except for NULL, functions and variables never overlap. */ @@ -1956,11 +1972,12 @@ symtab_node::equal_address_to (symtab_no } /* TODO: Alias oracle basically assume that addresses of global variables - are different unless they are declared as alias of one to another. - We probably should be consistent and use this fact here, too, and update - alias oracle to use this predicate. */ + are different unless they are declared as alias of one to another while + the code folding comparsions doesn't. + We probably should be consistent and use this fact here, too, but for + the moment return false only when we are called from the alias oracle. */ - return 2; + return memory_accessed && rs1 != rs2 ? 0 : 2; } /* Worker for call_for_symbol_and_aliases. */ Index: cgraph.h =================================================================== --- cgraph.h (revision 231439) +++ cgraph.h (working copy) @@ -355,8 +355,13 @@ public: /* Return 0 if symbol is known to have different address than S2, Return 1 if symbol is known to have same address as S2, - return 2 otherwise. */ - int equal_address_to (symtab_node *s2); + return 2 otherwise. + + If MEMORY_ACCESSED is true, assume that both memory pointer to THIS + and S2 is going to be accessed. This eliminates the situations when + either THIS or S2 is NULL and is seful for comparing bases when deciding + about memory aliasing. */ + int equal_address_to (symtab_node *s2, bool memory_accessed = false); /* Return true if symbol's address may possibly be compared to other symbol's address. */