From patchwork Wed Dec 2 20:16:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 551730 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 2D45D1402EC for ; Thu, 3 Dec 2015 07:16:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=PJU3/GUa; 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=ZqfrksQFC+umx9Tgo /uDGGIqTWQwlL2ol62Ov+ymg0SA/vuFdhG/BSX/37uYYMrKfO0Kh+pIke/Ng9UDt SHoumNry4YT8tuPZWpFhOat+UkD0vLpYJB7cJR98VwOYSO6FlpQf5K6QYimj/ZnV l9NRARE5XOCnbtCF//tI+jpIec= 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:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=N7uKUIADgwxdDqNFy5l2J2m eL+w=; b=PJU3/GUamxwErBtVTU9Z+0aECrljUfu/sTkE7xJjaKoz5xEaUBywVMo t00Ttv+YYarXzxH/serctSSovcIyMuh+uTboMDNOqfK0/LLF35KANVjWWUZJSo9R Mgl41/ltfIL8oetJdUwRfgihHt8aSeoaHWttrZtxFJ9oHuMdWUxQ= Received: (qmail 30035 invoked by alias); 2 Dec 2015 20:16:17 -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 29988 invoked by uid 89); 2 Dec 2015 20:16:16 -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, 02 Dec 2015 20:16:14 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 20872543E55; Wed, 2 Dec 2015 21:16:11 +0100 (CET) Date: Wed, 2 Dec 2015 21:16:10 +0100 From: Jan Hubicka To: Richard Biener Cc: Jakub Jelinek , Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: -fstrict-aliasing fixes 4/6: do not fiddle with flag_strict_aliasing when expanding debug locations Message-ID: <20151202201610.GC90183@kam.mff.cuni.cz> References: <20151202080706.GA92803@kam.mff.cuni.cz> <20151202091519.GB5675@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Hi, I discussed the situation with Jakub on IRC today. It seems we still want to have alias sets in the dumps, but Jakub agrees with introduction new global var to control this instead of tampering with flag_strict_aliasing. This patch does that and also fixes expand_call_stmt which forget to set the flag. Additionally I modified get_alias_set to lookup existing alias set whever possible. In majority of cases the alias set is there because the variable was optimized out and the optimizers thus touched it earlier. Bootstrapped/regtested x86_64-linux including ada. OK? Honza * cfgexpand.c: Include alias.h (expand_call_stmt, expand_debug_expr): Set no_new_alias_sets; do not fiddle with flag_strict_aliasing * alias.c (no_new_alias_sets): New global var. (get_alias_set): Do not introduce new alias sets when no_new_alias_sets is set. (new_alias_set): Check that no new alias sets are introduced. * alias.h (no_new_alias_sets): Declare. * varasm.c: Include alias.h (make_decl_rtl_for_debug): Use no_new_alias_sets instead of flag_strict_aliasing. Index: cfgexpand.c =================================================================== --- cfgexpand.c (revision 231122) +++ cfgexpand.c (working copy) @@ -73,6 +73,7 @@ along with GCC; see the file COPYING3. #include "builtins.h" #include "tree-chkp.h" #include "rtl-chkp.h" +#include "alias.h" /* Some systems use __main in a way incompatible with its use in gcc, in these cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to @@ -2622,12 +2623,17 @@ expand_call_stmt (gcall *stmt) unsigned int ix; tree dtemp; + gcc_assert (!no_new_alias_sets); + no_new_alias_sets = true; + if (debug_args) for (ix = 1; (*debug_args)->iterate (ix, &dtemp); ix += 2) { gcc_assert (TREE_CODE (dtemp) == DEBUG_EXPR_DECL); expand_debug_expr (dtemp); } + + no_new_alias_sets = false; } lhs = gimple_call_lhs (stmt); @@ -4080,6 +4086,8 @@ expand_debug_expr (tree exp) int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp)); addr_space_t as; + gcc_assert (no_new_alias_sets); + switch (TREE_CODE_CLASS (TREE_CODE (exp))) { case tcc_expression: @@ -5219,12 +5227,12 @@ expand_debug_locations (void) { rtx_insn *insn; rtx_insn *last = get_last_insn (); - int save_strict_alias = flag_strict_aliasing; /* New alias sets while setting up memory attributes cause -fcompare-debug failures, even though it doesn't bring about any codegen changes. */ - flag_strict_aliasing = 0; + gcc_assert (!no_new_alias_sets); + no_new_alias_sets = true; for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) if (DEBUG_INSN_P (insn)) @@ -5284,7 +5292,7 @@ expand_debug_locations (void) avoid_complex_debug_insns (insn2, &INSN_VAR_LOCATION_LOC (insn2), 0); } - flag_strict_aliasing = save_strict_alias; + no_new_alias_sets = false; } /* Performs swapping operands of commutative operations to expand Index: varasm.c =================================================================== --- varasm.c (revision 231122) +++ varasm.c (working copy) @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3. #include "common/common-target.h" #include "asan.h" #include "rtl-iter.h" +#include "alias.h" #ifdef XCOFF_DEBUGGING_INFO #include "xcoffout.h" /* Needed for external data declarations. */ @@ -1487,7 +1488,6 @@ make_decl_rtl (tree decl) rtx make_decl_rtl_for_debug (tree decl) { - unsigned int save_aliasing_flag; rtx rtl; if (DECL_RTL_SET_P (decl)) @@ -1496,18 +1496,16 @@ make_decl_rtl_for_debug (tree decl) /* Kludge alert! Somewhere down the call chain, make_decl_rtl will call new_alias_set. If running with -fcompare-debug, sometimes we do not want to create alias sets that will throw the alias - numbers off in the comparison dumps. So... clearing - flag_strict_aliasing will keep new_alias_set() from creating a - new set. */ - save_aliasing_flag = flag_strict_aliasing; - flag_strict_aliasing = 0; + numbers off in the comparison dumps. */ + bool save_no_new_alias_sets = no_new_alias_sets; + no_new_alias_sets = true; rtl = DECL_RTL (decl); /* Reset DECL_RTL back, as various parts of the compiler expects DECL_RTL set meaning it is actually going to be output. */ SET_DECL_RTL (decl, NULL); - flag_strict_aliasing = save_aliasing_flag; + no_new_alias_sets = save_no_new_alias_sets; return rtl; } Index: alias.c =================================================================== --- alias.c (revision 231122) +++ alias.c (working copy) @@ -145,6 +145,9 @@ struct GTY(()) alias_set_entry { bool has_pointer; }; +/* When true we will not allocate any new alias sets. */ +bool no_new_alias_sets; + static int rtx_equal_for_memref_p (const_rtx, const_rtx); static int memrefs_conflict_p (int, rtx, int, rtx, HOST_WIDE_INT); static void record_set (rtx, const_rtx, void *); @@ -1034,6 +1037,10 @@ get_alias_set (tree t) gcc_checking_assert (p == TYPE_MAIN_VARIANT (p)); if (TYPE_ALIAS_SET_KNOWN_P (p)) set = TYPE_ALIAS_SET (p); + /* During debug statement expanding we can not allocate new alias sets + or the debug dumps will miscompare. */ + else if (no_new_alias_sets) + return 0; else { set = new_alias_set (); @@ -1041,6 +1048,10 @@ get_alias_set (tree t) } } } + /* During debug statement expanding we can not allocate new alias sets + or the debug dumps will miscompare. */ + else if (no_new_alias_sets) + return 0; /* Alias set of ptr_type_node is special and serve as universal pointer which is TBAA compatible with every other pointer type. Be sure we have the alias set built even for LTO which otherwise keeps all TYPE_CANONICAL @@ -1060,6 +1071,11 @@ get_alias_set (tree t) set = new_alias_set (); } + /* Do not record alias set 0 if we are not creating new aliases. Perhaps + we needed new one during the recursion. */ + if (!set && !no_new_alias_sets) + return 0; + TYPE_ALIAS_SET (t) = set; /* If this is an aggregate type or a complex type, we must record any @@ -1085,6 +1101,7 @@ get_alias_set (tree t) alias_set_type new_alias_set (void) { + gcc_assert (!no_new_alias_sets); if (flag_strict_aliasing) { if (alias_sets == 0) Index: alias.h =================================================================== --- alias.h (revision 231122) +++ alias.h (working copy) @@ -37,6 +37,8 @@ extern void dump_alias_stats_in_alias_c tree reference_alias_ptr_type (tree); bool alias_ptr_types_compatible_p (tree, tree); +extern bool no_new_alias_sets; + /* This alias set can be used to force a memory to conflict with all other memories, creating a barrier across which no memory reference can move. Note that there are other legacy ways to create such