2012-03-30 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 30 Mar 2012 13:41:24 +0000 (13:41 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 30 Mar 2012 13:41:24 +0000 (13:41 +0000)
PR tree-optimization/52754
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Only
propagate arbitrary addresses into really plain dereferences.

* gcc.target/i386/pr52754.c: New testcase.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr52754.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index 151e5a7..84538f8 100644 (file)
@@ -1,3 +1,9 @@
+2012-03-30  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/52754
+       * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Only
+       propagate arbitrary addresses into really plain dereferences.
+
 2012-03-30  Richard Guenther <rguenther@suse.de>
 
        PR middle-end/52772
index fb232b3..549789d 100644 (file)
@@ -1,3 +1,8 @@
+2012-03-30  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/52754
+       * gcc.target/i386/pr52754.c: New testcase.
+
 2012-03-30  Richard Guenther <rguenther@suse.de>
 
        PR middle-end/52772
diff --git a/gcc/testsuite/gcc.target/i386/pr52754.c b/gcc/testsuite/gcc.target/i386/pr52754.c
new file mode 100644 (file)
index 0000000..0f2dbff
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fpredictive-commoning -msse2 -std=c99" } */
+/* { dg-require-effective-target sse2 } */
+
+#include <x86intrin.h>
+
+#include "isa-check.h"
+#include "sse-os-support.h"
+
+int main()
+{
+    const float mem[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
+
+    unsigned int indexes[8];
+    for (unsigned int i = 0; i < 8; ++i) indexes[i] = i;
+
+    check_isa ();
+
+    if (!sse_os_support ())
+      exit (0);
+
+    __m128 x = _mm_setr_ps(0, 1, 2, 3);
+    for (unsigned int i = 0; i + 4 < 6; ++i) {
+        const unsigned int *ii = &indexes[i];
+        const __m128 tmp = _mm_setr_ps(mem[ii[0]], mem[ii[1]], mem[ii[2]], mem[ii[3]]);
+        if (0xf != _mm_movemask_ps(_mm_cmpeq_ps(tmp, x))) {
+            __builtin_abort();
+        }
+        x = _mm_add_ps(x, _mm_set1_ps(1));
+    }
+
+    return 0;
+}
index 9197795..2b16222 100644 (file)
@@ -905,6 +905,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
          that of the pointed-to type of the address we can put the
         dereferenced address on the LHS preserving the original alias-type.  */
       else if (gimple_assign_lhs (use_stmt) == lhs
+              && integer_zerop (TREE_OPERAND (lhs, 1))
               && useless_type_conversion_p
                    (TREE_TYPE (TREE_OPERAND (def_rhs, 0)),
                     TREE_TYPE (gimple_assign_rhs1 (use_stmt))))
@@ -917,9 +918,8 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
          if (TREE_CODE (*def_rhs_basep) == MEM_REF)
            {
              new_base = TREE_OPERAND (*def_rhs_basep, 0);
-             new_offset
-               = int_const_binop (PLUS_EXPR, TREE_OPERAND (lhs, 1),
-                                  TREE_OPERAND (*def_rhs_basep, 1));
+             new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (lhs, 1)),
+                                        TREE_OPERAND (*def_rhs_basep, 1));
            }
          else
            {
@@ -989,6 +989,7 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
          that of the pointed-to type of the address we can put the
         dereferenced address on the RHS preserving the original alias-type.  */
       else if (gimple_assign_rhs1 (use_stmt) == rhs
+              && integer_zerop (TREE_OPERAND (rhs, 1))
               && useless_type_conversion_p
                    (TREE_TYPE (gimple_assign_lhs (use_stmt)),
                     TREE_TYPE (TREE_OPERAND (def_rhs, 0))))
@@ -1001,9 +1002,8 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
          if (TREE_CODE (*def_rhs_basep) == MEM_REF)
            {
              new_base = TREE_OPERAND (*def_rhs_basep, 0);
-             new_offset
-               = int_const_binop (PLUS_EXPR, TREE_OPERAND (rhs, 1),
-                                  TREE_OPERAND (*def_rhs_basep, 1));
+             new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (rhs, 1)),
+                                        TREE_OPERAND (*def_rhs_basep, 1));
            }
          else
            {