re PR other/52754 (indirect indexing broken with -fpredictive-commoning)

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.

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

From-SVN: r186012
This commit is contained in:
Richard Guenther 2012-03-30 13:41:24 +00:00 committed by Richard Biener
parent 0b7fccfaf2
commit fef205d534
4 changed files with 50 additions and 6 deletions

View 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> 2012-03-30 Richard Guenther <rguenther@suse.de>
PR middle-end/52772 PR middle-end/52772

View 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> 2012-03-30 Richard Guenther <rguenther@suse.de>
PR middle-end/52772 PR middle-end/52772

View file

@ -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;
}

View 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 that of the pointed-to type of the address we can put the
dereferenced address on the LHS preserving the original alias-type. */ dereferenced address on the LHS preserving the original alias-type. */
else if (gimple_assign_lhs (use_stmt) == lhs else if (gimple_assign_lhs (use_stmt) == lhs
&& integer_zerop (TREE_OPERAND (lhs, 1))
&& useless_type_conversion_p && useless_type_conversion_p
(TREE_TYPE (TREE_OPERAND (def_rhs, 0)), (TREE_TYPE (TREE_OPERAND (def_rhs, 0)),
TREE_TYPE (gimple_assign_rhs1 (use_stmt)))) 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) if (TREE_CODE (*def_rhs_basep) == MEM_REF)
{ {
new_base = TREE_OPERAND (*def_rhs_basep, 0); new_base = TREE_OPERAND (*def_rhs_basep, 0);
new_offset new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (lhs, 1)),
= int_const_binop (PLUS_EXPR, TREE_OPERAND (lhs, 1), TREE_OPERAND (*def_rhs_basep, 1));
TREE_OPERAND (*def_rhs_basep, 1));
} }
else 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 that of the pointed-to type of the address we can put the
dereferenced address on the RHS preserving the original alias-type. */ dereferenced address on the RHS preserving the original alias-type. */
else if (gimple_assign_rhs1 (use_stmt) == rhs else if (gimple_assign_rhs1 (use_stmt) == rhs
&& integer_zerop (TREE_OPERAND (rhs, 1))
&& useless_type_conversion_p && useless_type_conversion_p
(TREE_TYPE (gimple_assign_lhs (use_stmt)), (TREE_TYPE (gimple_assign_lhs (use_stmt)),
TREE_TYPE (TREE_OPERAND (def_rhs, 0)))) 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) if (TREE_CODE (*def_rhs_basep) == MEM_REF)
{ {
new_base = TREE_OPERAND (*def_rhs_basep, 0); new_base = TREE_OPERAND (*def_rhs_basep, 0);
new_offset new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (rhs, 1)),
= int_const_binop (PLUS_EXPR, TREE_OPERAND (rhs, 1), TREE_OPERAND (*def_rhs_basep, 1));
TREE_OPERAND (*def_rhs_basep, 1));
} }
else else
{ {