OSDN Git Service

2010-07-02 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 2 Jul 2010 09:14:03 +0000 (09:14 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 2 Jul 2010 09:14:03 +0000 (09:14 +0000)
PR tree-optimization/44748
* tree-ssa-ccp.c (fold_const_aggregate_ref): Properly handle
the embedded conversion in MEM_REFs.

* gcc.dg/tree-ssa/ssa-ccp-29.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161689 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-29.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index 4052269..365a719 100644 (file)
@@ -1,3 +1,9 @@
+2010-07-02  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/44748
+       * tree-ssa-ccp.c (fold_const_aggregate_ref): Properly handle
+       the embedded conversion in MEM_REFs.
+
 2010-07-01  López-Ibáñez  <manu@gcc.gnu.org>
 
        * reload.c: Include toplev.h.
index 8d84acd..d9c0a99 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-02  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/44748
+       * gcc.dg/tree-ssa/ssa-ccp-29.c: New testcase.
+
 2010-07-02  Iain Sandoe  <iains@gcc.gnu.org>
 
        * objc-obj-c++-shared/next-abi.h: Remove dependency on system
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-29.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-29.c
new file mode 100644 (file)
index 0000000..44d2945
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-ccp2" } */
+
+static double num;
+int foo (void)
+{
+  return *(unsigned *)&num;
+}
+
+/* { dg-final { scan-tree-dump "return 0;" "ccp2" } } */
+/* { dg-final { cleanup-tree-dump "ccp2" } } */
index 912c505..1e2309a 100644 (file)
@@ -1317,7 +1317,14 @@ fold_const_aggregate_ref (tree t)
          if (DECL_P (base)
              && !AGGREGATE_TYPE_P (TREE_TYPE (base))
              && integer_zerop (TREE_OPERAND (t, 1)))
-           return get_symbol_constant_value (base);
+           {
+             tree res = get_symbol_constant_value (base);
+             if (res
+                 && !useless_type_conversion_p
+                       (TREE_TYPE (t), TREE_TYPE (res)))
+               res = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (t), res);
+             return res;
+           }
 
          if (!TREE_READONLY (base)
              || TREE_CODE (TREE_TYPE (base)) != ARRAY_TYPE