aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <andrew_pinski@playstation.sony.com>2009-01-20 17:10:40 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2009-01-20 17:10:40 +0000
commit37348bf1059789a055e87113553bdda141db5cd0 (patch)
tree724475a560b4dd068a277f34c223a8bf205b5837 /gcc
parentd0a589040b272bdc1adafd3a268d0903d418e1aa (diff)
downloadgcc-37348bf1059789a055e87113553bdda141db5cd0.zip
gcc-37348bf1059789a055e87113553bdda141db5cd0.tar.gz
gcc-37348bf1059789a055e87113553bdda141db5cd0.tar.bz2
re PR tree-optimization/38747 (Wrong code due to VIEW_CONVERT_EXPR)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/struct-aliasing-1.c17
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-1.c15
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-2.c18
-rw-r--r--gcc/tree-ssa-forwprop.c15
6 files changed, 79 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7b43b970..e4bb5c7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 55fc1c8..4754d1a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..9786b44
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/struct-aliasing-1.c
@@ -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
index 0000000..78e92d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-1.c
@@ -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
index 0000000..aa9e142
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/struct-aliasing-2.c
@@ -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" } } */
+
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index bfd7146..3826f1a 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -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