public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Richard Biener <rguenther@suse.de>
Cc: Jakub Jelinek <jakub@redhat.com>, Jan Hubicka <hubicka@ucw.cz>,
	gcc-patches@gcc.gnu.org
Subject: Re: -fstrict-aliasing fixes 4/6: do not fiddle with flag_strict_aliasing when expanding debug locations
Date: Wed, 02 Dec 2015 20:16:00 -0000	[thread overview]
Message-ID: <20151202201610.GC90183@kam.mff.cuni.cz> (raw)
In-Reply-To: <alpine.LSU.2.11.1512021019190.4884@t29.fhfr.qr>

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;
 }
 \f
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

  parent reply	other threads:[~2015-12-02 20:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-02  8:07 Jan Hubicka
2015-12-02  9:05 ` Richard Biener
2015-12-02  9:15   ` Jakub Jelinek
2015-12-02  9:21     ` Richard Biener
2015-12-02 17:17       ` Jan Hubicka
2015-12-02 20:16       ` Jan Hubicka [this message]
2015-12-02 20:25         ` Jakub Jelinek
2015-12-04 11:04           ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151202201610.GC90183@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).