public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Guenther <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Don't handle CAST_RESTRICT (PR tree-optimization/49279)
Date: Thu, 06 Oct 2011 14:45:00 -0000	[thread overview]
Message-ID: <20111006143132.GC19412@tyan-ft48-01.lab.bos.redhat.com> (raw)

Hi!

CAST_RESTRICT based disambiguation unfortunately isn't reliable,
e.g. to store a non-restrict pointer into a restricted field,
we add a non-useless cast to restricted pointer in the gimplifier,
and while we don't consider that field to have a special restrict tag
because it is unsafe to do so, we unfortunately create it for the
CAST_RESTRICT before that and end up with different restrict tags
for the same thing.  See the PR for more details.

This patch turns off CAST_RESTRICT handling for now, in the future
we might try to replace it by explicit CAST_RESTRICT stmts in some form,
but need to solve problems with multiple inlined copies of the same function
with restrict arguments or restrict variables in it and intermixed code from
them (or similarly code from different non-overlapping source blocks).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
4.6 too?

2011-10-06  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/49279
	* tree-ssa-structalias.c (find_func_aliases): Don't handle
	CAST_RESTRICT.
	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Allow
	restrict propagation.
	* tree-ssa.c (useless_type_conversion_p): Don't return false
	if TYPE_RESTRICT differs.

	* gcc.dg/tree-ssa/restrict-4.c: XFAIL.
	* gcc.c-torture/execute/pr49279.c: New test.

--- gcc/tree-ssa-structalias.c.jj	2011-10-04 10:18:29.000000000 +0200
+++ gcc/tree-ssa-structalias.c	2011-10-05 12:43:42.000000000 +0200
@@ -4494,15 +4494,6 @@ find_func_aliases (gimple origt)
 	  && (!in_ipa_mode
 	      || DECL_EXTERNAL (lhsop) || TREE_PUBLIC (lhsop)))
 	make_escape_constraint (rhsop);
-      /* If this is a conversion of a non-restrict pointer to a
-	 restrict pointer track it with a new heapvar.  */
-      else if (gimple_assign_cast_p (t)
-	       && POINTER_TYPE_P (TREE_TYPE (rhsop))
-	       && POINTER_TYPE_P (TREE_TYPE (lhsop))
-	       && !TYPE_RESTRICT (TREE_TYPE (rhsop))
-	       && TYPE_RESTRICT (TREE_TYPE (lhsop)))
-	make_constraint_from_restrict (get_vi_for_tree (lhsop),
-				       "CAST_RESTRICT");
     }
   /* Handle escapes through return.  */
   else if (gimple_code (t) == GIMPLE_RETURN
--- gcc/tree-ssa-forwprop.c.jj	2011-10-04 14:36:00.000000000 +0200
+++ gcc/tree-ssa-forwprop.c	2011-10-05 12:46:32.000000000 +0200
@@ -804,11 +804,6 @@ forward_propagate_addr_expr_1 (tree name
       && ((rhs_code == SSA_NAME && rhs == name)
 	  || CONVERT_EXPR_CODE_P (rhs_code)))
     {
-      /* Don't propagate restrict pointer's RHS.  */
-      if (TYPE_RESTRICT (TREE_TYPE (lhs))
-	  && !TYPE_RESTRICT (TREE_TYPE (name))
-	  && !is_gimple_min_invariant (def_rhs))
-	return false;
       /* Only recurse if we don't deal with a single use or we cannot
 	 do the propagation to the current statement.  In particular
 	 we can end up with a conversion needed for a non-invariant
--- gcc/tree-ssa.c.jj	2011-09-15 12:18:54.000000000 +0200
+++ gcc/tree-ssa.c	2011-10-05 12:44:52.000000000 +0200
@@ -1270,12 +1270,6 @@ useless_type_conversion_p (tree outer_ty
 	  != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
 	return false;
 
-      /* Do not lose casts to restrict qualified pointers.  */
-      if ((TYPE_RESTRICT (outer_type)
-	   != TYPE_RESTRICT (inner_type))
-	  && TYPE_RESTRICT (outer_type))
-	return false;
-
       /* If the outer type is (void *), the conversion is not necessary.  */
       if (VOID_TYPE_P (TREE_TYPE (outer_type)))
 	return true;
--- gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c.jj	2011-10-04 14:33:08.000000000 +0200
+++ gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c	2011-10-05 16:22:33.232433231 +0200
@@ -22,5 +22,5 @@ bar (int *x, int y)
   return p1[y];
 }
 
-/* { dg-final { scan-tree-dump-times "return 1;" 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "return 1;" 2 "optimized" { xfail *-*-* } } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
--- gcc/testsuite/gcc.c-torture/execute/pr49279.c.jj	2011-10-05 13:32:43.087670846 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr49279.c	2011-10-05 13:32:43.087670846 +0200
@@ -0,0 +1,35 @@
+/* PR tree-optimization/49279 */
+extern void abort (void);
+
+struct S { int a; int *__restrict p; };
+
+__attribute__((noinline, noclone))
+struct S *bar (struct S *p)
+{
+  struct S *r;
+  asm volatile ("" : "=r" (r) : "0" (p) : "memory");
+  return r;
+}
+
+__attribute__((noinline, noclone))
+int
+foo (int *p, int *q)
+{
+  struct S s, *t;
+  s.a = 1;
+  s.p = p;
+  t = bar (&s);
+  t->p = q;
+  s.p[0] = 0;
+  t->p[0] = 1;
+  return s.p[0];
+}
+
+int
+main ()
+{
+  int a, b;
+  if (foo (&a, &b) != 1)
+    abort ();
+  return 0;
+}

	Jakub

             reply	other threads:[~2011-10-06 14:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-06 14:45 Jakub Jelinek [this message]
2011-10-06 15:02 ` Richard Guenther
2015-10-29 11:00 Tom de Vries
2015-10-29 12:05 ` 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=20111006143132.GC19412@tyan-ft48-01.lab.bos.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).