summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2011-10-04 12:34:06 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2011-10-04 12:34:06 +0000
commit5a41d783acbed929d6fe7da7dfe989e4953bc454 (patch)
treee03429ddfdb28c26c0b8a6b943ec84b3196db8b1 /gcc
parentda8e87834082d6cd5c2f82c38285f702bb280de1 (diff)
downloadgcc-5a41d783acbed929d6fe7da7dfe989e4953bc454.tar.gz
* fold-const.c (fold_unary_loc): Don't optimize
POINTER_PLUS_EXPR casted to TYPE_RESTRICT pointer by casting the inner pointer if it isn't TYPE_RESTRICT. * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Don't through casts from non-TYPE_RESTRICT pointer to TYPE_RESTRICT pointer. * gcc.dg/tree-ssa/restrict-4.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179500 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/fold-const.c1
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c26
-rw-r--r--gcc/tree-ssa-forwprop.c5
5 files changed, 44 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9ee1a187242..3b973a05e3f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2011-10-04 Jakub Jelinek <jakub@redhat.com>
+
+ * fold-const.c (fold_unary_loc): Don't optimize
+ POINTER_PLUS_EXPR casted to TYPE_RESTRICT pointer by
+ casting the inner pointer if it isn't TYPE_RESTRICT.
+ * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Don't through
+ casts from non-TYPE_RESTRICT pointer to TYPE_RESTRICT pointer.
+
2011-10-04 Joseph Myers <joseph@codesourcery.com>
* config.gcc (i[34567]86-*-elf*, x86_64-*-elf*): Use
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 79ebd8b5701..c3871f1075a 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7946,6 +7946,7 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
that this happens when X or Y is NOP_EXPR or Y is INTEGER_CST. */
if (POINTER_TYPE_P (type)
&& TREE_CODE (arg0) == POINTER_PLUS_EXPR
+ && (!TYPE_RESTRICT (type) || TYPE_RESTRICT (TREE_TYPE (arg0)))
&& (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
|| TREE_CODE (TREE_OPERAND (arg0, 0)) == NOP_EXPR
|| TREE_CODE (TREE_OPERAND (arg0, 1)) == NOP_EXPR))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5e2965b88d0..b0d2d2cec40 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2011-10-04 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.dg/tree-ssa/restrict-4.c: New test.
+
2011-10-04 Artem Shinkarov <artyom.shinkaroff@gmail.com>
* gcc.c-torture/execute/vector-compare-1.c: Fix trailing white
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c b/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c
new file mode 100644
index 00000000000..a307c89f487
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+foo (int *x, int y)
+{
+ int *__restrict p1 = x;
+ int *__restrict p2 = x + 32;
+ p1[y] = 1;
+ p2[4] = 2;
+ return p1[y];
+}
+
+int
+bar (int *x, int y)
+{
+ int *__restrict p1 = x;
+ int *p3 = x + 32;
+ int *__restrict p2 = p3;
+ p1[y] = 1;
+ p2[4] = 2;
+ return p1[y];
+}
+
+/* { dg-final { scan-tree-dump-times "return 1;" 2 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index a8737dac933..c6b92cfe77f 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -804,6 +804,11 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
&& ((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