Move some complex simplifications to match.pd
2015-08-31 Marc Glisse <marc.glisse@inria.fr> gcc/ * match.pd (SIN, COS, TAN, COSH): Reorder for consistency. (CEXPI): New operator list. (real (conj (x)), imag (conj (x)), real (x +- y), real (cexpi (x)), imag (cexpi (x)), conj (conj (x)), conj (complex (x, y))): Converted from ... * fold-const.c (fold_unary_loc, fold_binary_loc): ... here. Remove. gcc/testsuite/ * gcc.dg/tree-ssa/complex-7.c: New file. From-SVN: r227343
This commit is contained in:
parent
eaef98f3af
commit
77c028c522
@ -1,3 +1,12 @@
|
||||
2015-08-31 Marc Glisse <marc.glisse@inria.fr>
|
||||
|
||||
* match.pd (SIN, COS, TAN, COSH): Reorder for consistency.
|
||||
(CEXPI): New operator list.
|
||||
(real (conj (x)), imag (conj (x)), real (x +- y), real (cexpi (x)),
|
||||
imag (cexpi (x)), conj (conj (x)), conj (complex (x, y))):
|
||||
Converted from ...
|
||||
* fold-const.c (fold_unary_loc, fold_binary_loc): ... here. Remove.
|
||||
|
||||
2015-08-31 Tom de Vries <tom@codesourcery.com>
|
||||
|
||||
* tree-ssa-loop-manip.c (find_uses_to_rename_stmt)
|
||||
|
@ -7732,21 +7732,6 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
|
||||
}
|
||||
return NULL_TREE;
|
||||
|
||||
case CONJ_EXPR:
|
||||
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
|
||||
return fold_convert_loc (loc, type, arg0);
|
||||
if (TREE_CODE (arg0) == COMPLEX_EXPR)
|
||||
{
|
||||
tree itype = TREE_TYPE (type);
|
||||
tree rpart = fold_convert_loc (loc, itype, TREE_OPERAND (arg0, 0));
|
||||
tree ipart = fold_convert_loc (loc, itype, TREE_OPERAND (arg0, 1));
|
||||
return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart,
|
||||
negate_expr (ipart));
|
||||
}
|
||||
if (TREE_CODE (arg0) == CONJ_EXPR)
|
||||
return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
|
||||
return NULL_TREE;
|
||||
|
||||
case BIT_NOT_EXPR:
|
||||
/* Convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */
|
||||
if (TREE_CODE (arg0) == BIT_XOR_EXPR
|
||||
@ -7776,81 +7761,6 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
|
||||
return NULL_TREE;
|
||||
return fold_convert_loc (loc, type, tem);
|
||||
|
||||
case REALPART_EXPR:
|
||||
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
|
||||
return fold_convert_loc (loc, type, arg0);
|
||||
if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
|
||||
{
|
||||
tree itype = TREE_TYPE (TREE_TYPE (arg0));
|
||||
tem = fold_build2_loc (loc, TREE_CODE (arg0), itype,
|
||||
fold_build1_loc (loc, REALPART_EXPR, itype,
|
||||
TREE_OPERAND (arg0, 0)),
|
||||
fold_build1_loc (loc, REALPART_EXPR, itype,
|
||||
TREE_OPERAND (arg0, 1)));
|
||||
return fold_convert_loc (loc, type, tem);
|
||||
}
|
||||
if (TREE_CODE (arg0) == CONJ_EXPR)
|
||||
{
|
||||
tree itype = TREE_TYPE (TREE_TYPE (arg0));
|
||||
tem = fold_build1_loc (loc, REALPART_EXPR, itype,
|
||||
TREE_OPERAND (arg0, 0));
|
||||
return fold_convert_loc (loc, type, tem);
|
||||
}
|
||||
if (TREE_CODE (arg0) == CALL_EXPR)
|
||||
{
|
||||
tree fn = get_callee_fndecl (arg0);
|
||||
if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
|
||||
switch (DECL_FUNCTION_CODE (fn))
|
||||
{
|
||||
CASE_FLT_FN (BUILT_IN_CEXPI):
|
||||
fn = mathfn_built_in (type, BUILT_IN_COS);
|
||||
if (fn)
|
||||
return build_call_expr_loc (loc, fn, 1, CALL_EXPR_ARG (arg0, 0));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL_TREE;
|
||||
|
||||
case IMAGPART_EXPR:
|
||||
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
|
||||
return build_zero_cst (type);
|
||||
if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
|
||||
{
|
||||
tree itype = TREE_TYPE (TREE_TYPE (arg0));
|
||||
tem = fold_build2_loc (loc, TREE_CODE (arg0), itype,
|
||||
fold_build1_loc (loc, IMAGPART_EXPR, itype,
|
||||
TREE_OPERAND (arg0, 0)),
|
||||
fold_build1_loc (loc, IMAGPART_EXPR, itype,
|
||||
TREE_OPERAND (arg0, 1)));
|
||||
return fold_convert_loc (loc, type, tem);
|
||||
}
|
||||
if (TREE_CODE (arg0) == CONJ_EXPR)
|
||||
{
|
||||
tree itype = TREE_TYPE (TREE_TYPE (arg0));
|
||||
tem = fold_build1_loc (loc, IMAGPART_EXPR, itype, TREE_OPERAND (arg0, 0));
|
||||
return fold_convert_loc (loc, type, negate_expr (tem));
|
||||
}
|
||||
if (TREE_CODE (arg0) == CALL_EXPR)
|
||||
{
|
||||
tree fn = get_callee_fndecl (arg0);
|
||||
if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
|
||||
switch (DECL_FUNCTION_CODE (fn))
|
||||
{
|
||||
CASE_FLT_FN (BUILT_IN_CEXPI):
|
||||
fn = mathfn_built_in (type, BUILT_IN_SIN);
|
||||
if (fn)
|
||||
return build_call_expr_loc (loc, fn, 1, CALL_EXPR_ARG (arg0, 0));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NULL_TREE;
|
||||
|
||||
case INDIRECT_REF:
|
||||
/* Fold *&X to X if X is an lvalue. */
|
||||
if (TREE_CODE (op0) == ADDR_EXPR)
|
||||
|
39
gcc/match.pd
39
gcc/match.pd
@ -55,10 +55,11 @@ along with GCC; see the file COPYING3. If not see
|
||||
(define_operator_list POW10 BUILT_IN_POW10F BUILT_IN_POW10 BUILT_IN_POW10L)
|
||||
(define_operator_list SQRT BUILT_IN_SQRTF BUILT_IN_SQRT BUILT_IN_SQRTL)
|
||||
(define_operator_list CBRT BUILT_IN_CBRTF BUILT_IN_CBRT BUILT_IN_CBRTL)
|
||||
(define_operator_list SIN BUILT_IN_SIN BUILT_IN_SINL BUILT_IN_SINF)
|
||||
(define_operator_list COS BUILT_IN_COS BUILT_IN_COSL BUILT_IN_COSF)
|
||||
(define_operator_list TAN BUILT_IN_TAN BUILT_IN_TANL BUILT_IN_TANF)
|
||||
(define_operator_list COSH BUILT_IN_COSH BUILT_IN_COSHL BUILT_IN_COSHF)
|
||||
(define_operator_list SIN BUILT_IN_SINF BUILT_IN_SIN BUILT_IN_SINL)
|
||||
(define_operator_list COS BUILT_IN_COSF BUILT_IN_COS BUILT_IN_COSL)
|
||||
(define_operator_list TAN BUILT_IN_TANF BUILT_IN_TAN BUILT_IN_TANL)
|
||||
(define_operator_list COSH BUILT_IN_COSHF BUILT_IN_COSH BUILT_IN_COSHL)
|
||||
(define_operator_list CEXPI BUILT_IN_CEXPIF BUILT_IN_CEXPI BUILT_IN_CEXPIL)
|
||||
|
||||
/* Simplifications of operations with one constant operand and
|
||||
simplifications to constants or single values. */
|
||||
@ -1312,6 +1313,36 @@ along with GCC; see the file COPYING3. If not see
|
||||
(imagpart (complex @0 @1))
|
||||
@1)
|
||||
|
||||
/* Sometimes we only care about half of a complex expression. */
|
||||
(simplify
|
||||
(realpart (convert?:s (conj:s @0)))
|
||||
(convert (realpart @0)))
|
||||
(simplify
|
||||
(imagpart (convert?:s (conj:s @0)))
|
||||
(convert (negate (imagpart @0))))
|
||||
(for part (realpart imagpart)
|
||||
(for op (plus minus)
|
||||
(simplify
|
||||
(part (convert?:s@2 (op:s @0 @1)))
|
||||
(convert (op (part @0) (part @1))))))
|
||||
(simplify
|
||||
(realpart (convert?:s (CEXPI:s @0)))
|
||||
(convert (COS @0)))
|
||||
(simplify
|
||||
(imagpart (convert?:s (CEXPI:s @0)))
|
||||
(convert (SIN @0)))
|
||||
|
||||
/* conj(conj(x)) -> x */
|
||||
(simplify
|
||||
(conj (convert? (conj @0)))
|
||||
(if (tree_nop_conversion_p (TREE_TYPE (@0), type))
|
||||
(convert @0)))
|
||||
|
||||
/* conj({x,y}) -> {x,-y} */
|
||||
(simplify
|
||||
(conj (convert?:s (complex:s @0 @1)))
|
||||
(with { tree itype = TREE_TYPE (type); }
|
||||
(complex (convert:itype @0) (negate (convert:itype @1)))))
|
||||
|
||||
/* BSWAP simplifications, transforms checked by gcc.dg/builtin-bswap-8.c. */
|
||||
(for bswap (BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 BUILT_IN_BSWAP64)
|
||||
|
@ -1,3 +1,7 @@
|
||||
2015-08-31 Marc Glisse <marc.glisse@inria.fr>
|
||||
|
||||
* gcc.dg/tree-ssa/complex-7.c: New file.
|
||||
|
||||
2015-08-30 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
|
||||
|
||||
* gcc.target/powerpc/swaps-p8-19.c: New test.
|
||||
|
15
gcc/testsuite/gcc.dg/tree-ssa/complex-7.c
Normal file
15
gcc/testsuite/gcc.dg/tree-ssa/complex-7.c
Normal file
@ -0,0 +1,15 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O -fdump-tree-forwprop1" } */
|
||||
|
||||
float f(_Complex float x, _Complex float y){
|
||||
x += y;
|
||||
return __builtin_cimagf (x);
|
||||
}
|
||||
|
||||
double g(double x){
|
||||
_Complex double c = __builtin_cexpi (x);
|
||||
return __builtin_creal (c);
|
||||
}
|
||||
|
||||
/* { dg-final { scan-tree-dump "__builtin_cos" "forwprop1"} } */
|
||||
/* { dg-final { scan-tree-dump-times "IMAGPART_EXPR" 2 "forwprop1"} } */
|
Loading…
Reference in New Issue
Block a user