}
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
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)
(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. */
(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)