[PATCH] Amend fixes for PR26134 and PR48037
Richard Guenther
rguenther@suse.de
Wed Mar 16 13:50:00 GMT 2011
This makes sure we also rewrite complex variables into SSA form if
we extract components via pointer-to-elements.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2011-03-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/26134
* tree-ssa.c (maybe_rewrite_mem_ref_base): Handle rewriting
complex part accesses to REALPART_EXPR and IMAGPART_EXPR.
(non_rewritable_mem_ref_base): Handle complex type component
accesses, constrain offsets for vector and complex extracts
more properly.
* gcc.dg/tree-ssa/complex-6.c: New testcase.
Index: gcc/tree-ssa.c
===================================================================
*** gcc/tree-ssa.c (revision 171042)
--- gcc/tree-ssa.c (working copy)
*************** maybe_rewrite_mem_ref_base (tree *tp)
*** 1855,1860 ****
--- 1855,1868 ----
bitsize_int (BITS_PER_UNIT),
TREE_OPERAND (*tp, 1), 0));
}
+ else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
+ && useless_type_conversion_p (TREE_TYPE (*tp),
+ TREE_TYPE (TREE_TYPE (sym))))
+ {
+ *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
+ ? REALPART_EXPR : IMAGPART_EXPR,
+ TREE_TYPE (*tp), sym);
+ }
else if (integer_zerop (TREE_OPERAND (*tp, 1)))
{
if (!useless_type_conversion_p (TREE_TYPE (*tp),
*************** non_rewritable_mem_ref_base (tree ref)
*** 1888,1897 ****
&& TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
{
tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
! if (TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
&& useless_type_conversion_p (TREE_TYPE (base),
TREE_TYPE (TREE_TYPE (decl)))
&& double_int_fits_in_uhwi_p (mem_ref_offset (base))
&& multiple_of_p (sizetype, TREE_OPERAND (base, 1),
TYPE_SIZE_UNIT (TREE_TYPE (base))))
return NULL_TREE;
--- 1896,1909 ----
&& TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
{
tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
! if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
! || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
&& useless_type_conversion_p (TREE_TYPE (base),
TREE_TYPE (TREE_TYPE (decl)))
&& double_int_fits_in_uhwi_p (mem_ref_offset (base))
+ && double_int_ucmp
+ (tree_to_double_int (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
+ mem_ref_offset (base)) == 1
&& multiple_of_p (sizetype, TREE_OPERAND (base, 1),
TYPE_SIZE_UNIT (TREE_TYPE (base))))
return NULL_TREE;
Index: gcc/testsuite/gcc.dg/tree-ssa/complex-6.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/complex-6.c (revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/complex-6.c (revision 0)
***************
*** 0 ****
--- 1,25 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-optimized" } */
+
+ float
+ quantum_real(float _Complex a)
+ {
+ float *p = (float *) &a;
+ return p[0];
+ }
+ float
+ quantum_imag(float _Complex a)
+ {
+ float *p = (float *) &a;
+ return p[1];
+ }
+ float
+ quantum_foo(float _Complex a)
+ {
+ float *p = (float *) &a;
+ return p[2];
+ }
+
+ /* { dg-final { scan-tree-dump-times "REALPART_EXPR" 1 "optimized" } } */
+ /* { dg-final { scan-tree-dump-times "IMAGPART_EXPR" 1 "optimized" } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */
More information about the Gcc-patches
mailing list