]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/38747 (Wrong code due to VIEW_CONVERT_EXPR)
authorAndrew Pinski <andrew_pinski@playstation.sony.com>
Tue, 20 Jan 2009 17:10:40 +0000 (17:10 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 20 Jan 2009 17:10:40 +0000 (17:10 +0000)
2009-01-20  Andrew Pinski  <andrew_pinski@playstation.sony.com>
Richard Guenther  <rguenther@suse.de>

PR tree-optimization/38747
PR tree-optimization/38748
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Disable the VCE
conversion if the base address is an indirect reference and the
aliasing sets could cause issues.

* gcc.dg/tree-ssa/struct-aliasing-1.c: New test.
* gcc.dg/tree-ssa/struct-aliasing-2.c: Likewise.
* gcc.c-torture/execute/struct-aliasing-1.c: Likewise.

Co-Authored-By: Richard Guenther <rguenther@suse.de>
From-SVN: r143523

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/struct-aliasing-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-2.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index 7b43b970454262cdc90850152cb9318421072726..e4bb5c71b3a4c0cc2df75077b34337b38e6a709c 100644 (file)
@@ -1,3 +1,12 @@
+2009-01-20  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+       Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/38747
+       PR tree-optimization/38748
+       * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Disable the VCE
+       conversion if the base address is an indirect reference and the
+       aliasing sets could cause issues.
+
 2009-01-20  Sebastian Pop  <sebastian.pop@amd.com>
 
        * common.opt (fgraphite, fgraphite-identity): Add comment for 
index 55fc1c8c856624a4db7f9559b49b465041f4d20f..4754d1a29983de2eb15e93c6625ad612353445e8 100644 (file)
@@ -1,3 +1,12 @@
+2009-01-20  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+       Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/38747
+       PR tree-optimization/38748
+       * gcc.dg/tree-ssa/struct-aliasing-1.c: New test.
+       * gcc.dg/tree-ssa/struct-aliasing-2.c: Likewise.
+       * gcc.c-torture/execute/struct-aliasing-1.c: Likewise.
+
 2009-01-20  Kees Cook  <kees@ubuntu.com>
            H.J. Lu  <hongjiu.lu@intel.com>
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/struct-aliasing-1.c b/gcc/testsuite/gcc.c-torture/execute/struct-aliasing-1.c
new file mode 100644 (file)
index 0000000..9786b44
--- /dev/null
@@ -0,0 +1,17 @@
+struct S { float f; };
+int __attribute__((noinline))
+foo (int *r, struct S *p)
+{
+  int *q = (int *)&p->f;
+  int i = *q;
+  *r = 0;
+  return i + *q;
+}
+extern void abort (void);
+int main()
+{
+  int i = 1;
+  if (foo (&i, (struct S *)&i) != 1)
+    abort ();
+  return (0);
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-1.c b/gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-1.c
new file mode 100644 (file)
index 0000000..78e92d7
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do "compile" } */
+/* { dg-options "-O2 -fdump-tree-fre" } */
+
+struct S { float f; };
+int __attribute__((noinline))
+foo (float *r, struct S *p)
+{
+  int *q = (int *)&p->f;
+  int i = *q;
+  *r = 0.0;
+  return i + *q;
+}
+
+/* { dg-final { scan-tree-dump-times "\\\*q" 1 "fre" } } */
+/* { dg-final { cleanup-tree-dump "fre" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-2.c b/gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-2.c
new file mode 100644 (file)
index 0000000..aa9e142
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do "compile" } */
+/* { dg-options "-O2 -fdump-tree-fre" } */
+
+struct S { unsigned f; };
+
+int
+foo ( struct S *p)
+{
+  int *q = (int *)&p->f;
+  int i = *q;
+  return i + p->f;
+}
+
+
+/*  There should only be one load of p->f because fwprop can change *(int *)&p->f into just (int)p->f.  */
+/* { dg-final { scan-tree-dump-times "p_.\\\(D\\\)->f" 1 "fre" } } */
+/* { dg-final { cleanup-tree-dump "fre" } } */
+
index bfd7146d4901dc18d53988dbd5283a5be19cb9e8..3826f1af598ce1cfa13d9e5e4b4ace9c3f80c30a 100644 (file)
@@ -777,7 +777,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
       && operand_equal_p (TYPE_SIZE (TREE_TYPE (rhs)),
                          TYPE_SIZE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))), 0)) 
    {
-     tree new_rhs = unshare_expr (TREE_OPERAND (def_rhs, 0));
+     tree def_rhs_base, new_rhs = unshare_expr (TREE_OPERAND (def_rhs, 0));
      new_rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs), new_rhs);
      if (TREE_CODE (new_rhs) != VIEW_CONVERT_EXPR)
        {
@@ -788,16 +788,23 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
         new_rhs = force_gimple_operand_gsi (use_stmt_gsi, new_rhs, true, NULL,
                                             true, GSI_NEW_STMT);
         gimple_assign_set_rhs1 (use_stmt, new_rhs);
+        tidy_after_forward_propagate_addr (use_stmt);
+        return true;
        }
-     else
+     /* If the defining rhs comes from an indirect reference, then do not
+        convert into a VIEW_CONVERT_EXPR.  */
+     def_rhs_base = TREE_OPERAND (def_rhs, 0);
+     while (handled_component_p (def_rhs_base))
+       def_rhs_base = TREE_OPERAND (def_rhs_base, 0);
+     if (!INDIRECT_REF_P (def_rhs_base))
        {
         /* We may have arbitrary VIEW_CONVERT_EXPRs in a nested component
            reference.  Place it there and fold the thing.  */
         *rhsp = new_rhs;
         fold_stmt_inplace (use_stmt);
+        tidy_after_forward_propagate_addr (use_stmt);
+        return true;
        }
-     tidy_after_forward_propagate_addr (use_stmt);
-     return true;
    }
 
   /* If the use of the ADDR_EXPR is not a POINTER_PLUS_EXPR, there