From b799033017f0b33846490fc4612b4eb29b9ed0c6 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 6 Oct 2011 18:38:29 +0200 Subject: [PATCH] re PR tree-optimization/49279 (Optimization incorrectly presuming constant variable inside loop in g++ 4.5 and 4.6 with -O2 and -O3 for x86_64 targets) 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. From-SVN: r179620 --- gcc/ChangeLog | 10 ++++++ gcc/testsuite/ChangeLog | 6 ++++ gcc/testsuite/gcc.c-torture/execute/pr49279.c | 35 +++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c | 2 +- gcc/tree-ssa-forwprop.c | 5 --- gcc/tree-ssa-structalias.c | 9 ----- gcc/tree-ssa.c | 6 ---- 7 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr49279.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ae8c6c94e6e..aec77e967de 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2011-10-06 Jakub Jelinek + + 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. + 2011-10-06 Bernd Schmidt * function.c (thread_prologue_and_epilogue_insns): Build a vector diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b5ad3a4aa60..cac88e925a4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-10-06 Jakub Jelinek + + PR tree-optimization/49279 + * gcc.dg/tree-ssa/restrict-4.c: XFAIL. + * gcc.c-torture/execute/pr49279.c: New test. + 2011-10-06 Bernd Schmidt PR target/49049 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr49279.c b/gcc/testsuite/gcc.c-torture/execute/pr49279.c new file mode 100644 index 00000000000..7f2c0d22129 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr49279.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c b/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c index a307c89f487..7bcdcdd053a 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/restrict-4.c @@ -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" } } */ diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index c6b92cfe77f..a8737dac933 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -804,11 +804,6 @@ 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 diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 821fc7d92b2..7de22aabcb3 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -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 diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index a0115938077..258a7444b08 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1270,12 +1270,6 @@ useless_type_conversion_p (tree outer_type, tree inner_type) != 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;