From d92f7c8d56ed100aa7af60eb689d156a91b4514c Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 31 Aug 2015 13:58:03 +0000 Subject: [PATCH] Move some complex simplifications to match.pd 2015-08-31 Marc Glisse 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227343 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 ++++ gcc/fold-const.c | 90 ------------------------------- gcc/match.pd | 39 ++++++++++++-- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/tree-ssa/complex-7.c | 15 ++++++ 5 files changed, 63 insertions(+), 94 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/complex-7.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d343599c7e..0e97a190a20 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-08-31 Marc Glisse + + * 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 * tree-ssa-loop-manip.c (find_uses_to_rename_stmt) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c826e6790cd..a5d58a86692 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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) diff --git a/gcc/match.pd b/gcc/match.pd index 289bc5c5d58..50de7bbf8a6 100644 --- a/gcc/match.pd +++ b/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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8869251bb14..24f93142db6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-08-31 Marc Glisse + + * gcc.dg/tree-ssa/complex-7.c: New file. + 2015-08-30 Bill Schmidt * gcc.target/powerpc/swaps-p8-19.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/complex-7.c b/gcc/testsuite/gcc.dg/tree-ssa/complex-7.c new file mode 100644 index 00000000000..20a2a3785f6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/complex-7.c @@ -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"} } */ -- 2.11.4.GIT