1 /* Preamble and helpers for the autogenerated gimple-match.c file.
2 Copyright (C) 2014-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
30 #include "fold-const.h"
31 #include "fold-const-call.h"
32 #include "stor-layout.h"
33 #include "gimple-fold.h"
37 #include "gimple-match.h"
38 #include "tree-pass.h"
39 #include "internal-fn.h"
40 #include "case-cfn-macros.h"
42 #include "optabs-tree.h"
45 /* Forward declarations of the private auto-generated matchers.
46 They expect valueized operands in canonical order and do not
47 perform simplification of all-constant operands. */
48 static bool gimple_simplify (code_helper
*, tree
*,
49 gimple_seq
*, tree (*)(tree
),
50 code_helper
, tree
, tree
);
51 static bool gimple_simplify (code_helper
*, tree
*,
52 gimple_seq
*, tree (*)(tree
),
53 code_helper
, tree
, tree
, tree
);
54 static bool gimple_simplify (code_helper
*, tree
*,
55 gimple_seq
*, tree (*)(tree
),
56 code_helper
, tree
, tree
, tree
, tree
);
59 /* Return whether T is a constant that we'll dispatch to fold to
60 evaluate fully constant expressions. */
63 constant_for_folding (tree t
)
65 return (CONSTANT_CLASS_P (t
)
66 /* The following is only interesting to string builtins. */
67 || (TREE_CODE (t
) == ADDR_EXPR
68 && TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
));
72 /* Helper that matches and simplifies the toplevel result from
73 a gimple_simplify run (where we don't want to build
74 a stmt in case it's used in in-place folding). Replaces
75 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
76 result and returns whether any change was made. */
79 gimple_resimplify1 (gimple_seq
*seq
,
80 code_helper
*res_code
, tree type
, tree
*res_ops
,
81 tree (*valueize
)(tree
))
83 if (constant_for_folding (res_ops
[0]))
86 if (res_code
->is_tree_code ())
87 tem
= const_unop (*res_code
, type
, res_ops
[0]);
89 tem
= fold_const_call (combined_fn (*res_code
), type
, res_ops
[0]);
91 && CONSTANT_CLASS_P (tem
))
93 if (TREE_OVERFLOW_P (tem
))
94 tem
= drop_tree_overflow (tem
);
96 res_ops
[1] = NULL_TREE
;
97 res_ops
[2] = NULL_TREE
;
98 *res_code
= TREE_CODE (res_ops
[0]);
103 /* Limit recursion, there are cases like PR80887 and others, for
104 example when value-numbering presents us with unfolded expressions
105 that we are really not prepared to handle without eventual
106 oscillation like ((_50 + 0) + 8) where _50 gets mapped to _50
107 itself as available expression. */
108 static unsigned depth
;
111 if (dump_file
&& (dump_flags
& TDF_FOLDING
))
112 fprintf (dump_file
, "Aborting expression simplification due to "
118 code_helper res_code2
;
119 tree res_ops2
[3] = {};
120 if (gimple_simplify (&res_code2
, res_ops2
, seq
, valueize
,
121 *res_code
, type
, res_ops
[0]))
124 *res_code
= res_code2
;
125 res_ops
[0] = res_ops2
[0];
126 res_ops
[1] = res_ops2
[1];
127 res_ops
[2] = res_ops2
[2];
135 /* Helper that matches and simplifies the toplevel result from
136 a gimple_simplify run (where we don't want to build
137 a stmt in case it's used in in-place folding). Replaces
138 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
139 result and returns whether any change was made. */
142 gimple_resimplify2 (gimple_seq
*seq
,
143 code_helper
*res_code
, tree type
, tree
*res_ops
,
144 tree (*valueize
)(tree
))
146 if (constant_for_folding (res_ops
[0]) && constant_for_folding (res_ops
[1]))
148 tree tem
= NULL_TREE
;
149 if (res_code
->is_tree_code ())
150 tem
= const_binop (*res_code
, type
, res_ops
[0], res_ops
[1]);
152 tem
= fold_const_call (combined_fn (*res_code
), type
,
153 res_ops
[0], res_ops
[1]);
155 && CONSTANT_CLASS_P (tem
))
157 if (TREE_OVERFLOW_P (tem
))
158 tem
= drop_tree_overflow (tem
);
160 res_ops
[1] = NULL_TREE
;
161 res_ops
[2] = NULL_TREE
;
162 *res_code
= TREE_CODE (res_ops
[0]);
167 /* Canonicalize operand order. */
168 bool canonicalized
= false;
169 if (res_code
->is_tree_code ()
170 && (TREE_CODE_CLASS ((enum tree_code
) *res_code
) == tcc_comparison
171 || commutative_tree_code (*res_code
))
172 && tree_swap_operands_p (res_ops
[0], res_ops
[1]))
174 std::swap (res_ops
[0], res_ops
[1]);
175 if (TREE_CODE_CLASS ((enum tree_code
) *res_code
) == tcc_comparison
)
176 *res_code
= swap_tree_comparison (*res_code
);
177 canonicalized
= true;
180 /* Limit recursion, see gimple_resimplify1. */
181 static unsigned depth
;
184 if (dump_file
&& (dump_flags
& TDF_FOLDING
))
185 fprintf (dump_file
, "Aborting expression simplification due to "
191 code_helper res_code2
;
192 tree res_ops2
[3] = {};
193 if (gimple_simplify (&res_code2
, res_ops2
, seq
, valueize
,
194 *res_code
, type
, res_ops
[0], res_ops
[1]))
197 *res_code
= res_code2
;
198 res_ops
[0] = res_ops2
[0];
199 res_ops
[1] = res_ops2
[1];
200 res_ops
[2] = res_ops2
[2];
205 return canonicalized
;
208 /* Helper that matches and simplifies the toplevel result from
209 a gimple_simplify run (where we don't want to build
210 a stmt in case it's used in in-place folding). Replaces
211 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
212 result and returns whether any change was made. */
215 gimple_resimplify3 (gimple_seq
*seq
,
216 code_helper
*res_code
, tree type
, tree
*res_ops
,
217 tree (*valueize
)(tree
))
219 if (constant_for_folding (res_ops
[0]) && constant_for_folding (res_ops
[1])
220 && constant_for_folding (res_ops
[2]))
222 tree tem
= NULL_TREE
;
223 if (res_code
->is_tree_code ())
224 tem
= fold_ternary
/*_to_constant*/ (*res_code
, type
, res_ops
[0],
225 res_ops
[1], res_ops
[2]);
227 tem
= fold_const_call (combined_fn (*res_code
), type
,
228 res_ops
[0], res_ops
[1], res_ops
[2]);
230 && CONSTANT_CLASS_P (tem
))
232 if (TREE_OVERFLOW_P (tem
))
233 tem
= drop_tree_overflow (tem
);
235 res_ops
[1] = NULL_TREE
;
236 res_ops
[2] = NULL_TREE
;
237 *res_code
= TREE_CODE (res_ops
[0]);
242 /* Canonicalize operand order. */
243 bool canonicalized
= false;
244 if (res_code
->is_tree_code ()
245 && commutative_ternary_tree_code (*res_code
)
246 && tree_swap_operands_p (res_ops
[0], res_ops
[1]))
248 std::swap (res_ops
[0], res_ops
[1]);
249 canonicalized
= true;
252 /* Limit recursion, see gimple_resimplify1. */
253 static unsigned depth
;
256 if (dump_file
&& (dump_flags
& TDF_FOLDING
))
257 fprintf (dump_file
, "Aborting expression simplification due to "
263 code_helper res_code2
;
264 tree res_ops2
[3] = {};
265 if (gimple_simplify (&res_code2
, res_ops2
, seq
, valueize
,
267 res_ops
[0], res_ops
[1], res_ops
[2]))
270 *res_code
= res_code2
;
271 res_ops
[0] = res_ops2
[0];
272 res_ops
[1] = res_ops2
[1];
273 res_ops
[2] = res_ops2
[2];
278 return canonicalized
;
282 /* If in GIMPLE expressions with CODE go as single-rhs build
283 a GENERIC tree for that expression into *OP0. */
286 maybe_build_generic_op (enum tree_code code
, tree type
, tree
*ops
)
292 case VIEW_CONVERT_EXPR
:
293 ops
[0] = build1 (code
, type
, ops
[0]);
296 ops
[0] = build3 (code
, type
, ops
[0], ops
[1], ops
[2]);
297 ops
[1] = ops
[2] = NULL_TREE
;
303 tree (*mprts_hook
) (code_helper
, tree
, tree
*);
305 /* Try to build a call to FN with return type TYPE and the NARGS
306 arguments given in OPS. Return null if the target doesn't support
310 build_call_internal (internal_fn fn
, tree type
, unsigned int nargs
, tree
*ops
)
312 if (direct_internal_fn_p (fn
))
314 tree_pair types
= direct_internal_fn_types (fn
, type
, ops
);
315 if (!direct_internal_fn_supported_p (fn
, types
, OPTIMIZE_FOR_BOTH
))
318 return gimple_build_call_internal (fn
, nargs
, ops
[0], ops
[1], ops
[2]);
321 /* Push the exploded expression described by RCODE, TYPE and OPS
322 as a statement to SEQ if necessary and return a gimple value
323 denoting the value of the expression. If RES is not NULL
324 then the result will be always RES and even gimple values are
328 maybe_push_res_to_seq (code_helper rcode
, tree type
, tree
*ops
,
329 gimple_seq
*seq
, tree res
)
331 if (rcode
.is_tree_code ())
334 && gimple_simplified_result_is_gimple_val (rcode
, ops
))
338 tree tem
= mprts_hook (rcode
, type
, ops
);
344 /* Play safe and do not allow abnormals to be mentioned in
345 newly created statements. */
346 if ((TREE_CODE (ops
[0]) == SSA_NAME
347 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops
[0]))
349 && TREE_CODE (ops
[1]) == SSA_NAME
350 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops
[1]))
352 && TREE_CODE (ops
[2]) == SSA_NAME
353 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops
[2]))
354 || (COMPARISON_CLASS_P (ops
[0])
355 && ((TREE_CODE (TREE_OPERAND (ops
[0], 0)) == SSA_NAME
356 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops
[0],
358 || (TREE_CODE (TREE_OPERAND (ops
[0], 1)) == SSA_NAME
359 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops
[0],
364 if (gimple_in_ssa_p (cfun
))
365 res
= make_ssa_name (type
);
367 res
= create_tmp_reg (type
);
369 maybe_build_generic_op (rcode
, type
, ops
);
370 gimple
*new_stmt
= gimple_build_assign (res
, rcode
,
371 ops
[0], ops
[1], ops
[2]);
372 gimple_seq_add_stmt_without_update (seq
, new_stmt
);
379 combined_fn fn
= rcode
;
380 /* Play safe and do not allow abnormals to be mentioned in
381 newly created statements. */
383 for (nargs
= 0; nargs
< 3; ++nargs
)
387 if (TREE_CODE (ops
[nargs
]) == SSA_NAME
388 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops
[nargs
]))
391 gcc_assert (nargs
!= 0);
392 gcall
*new_stmt
= NULL
;
393 if (internal_fn_p (fn
))
395 /* Generate the given function if we can. */
396 internal_fn ifn
= as_internal_fn (fn
);
397 new_stmt
= build_call_internal (ifn
, type
, nargs
, ops
);
403 /* Find the function we want to call. */
404 tree decl
= builtin_decl_implicit (as_builtin_fn (fn
));
408 /* We can't and should not emit calls to non-const functions. */
409 if (!(flags_from_decl_or_type (decl
) & ECF_CONST
))
412 new_stmt
= gimple_build_call (decl
, nargs
, ops
[0], ops
[1], ops
[2]);
416 if (gimple_in_ssa_p (cfun
))
417 res
= make_ssa_name (type
);
419 res
= create_tmp_reg (type
);
421 gimple_call_set_lhs (new_stmt
, res
);
422 gimple_seq_add_stmt_without_update (seq
, new_stmt
);
428 /* Public API overloads follow for operation being tree_code or
429 built_in_function and for one to three operands or arguments.
430 They return NULL_TREE if nothing could be simplified or
431 the resulting simplified value with parts pushed to SEQ.
432 If SEQ is NULL then if the simplification needs to create
433 new stmts it will fail. If VALUEIZE is non-NULL then all
434 SSA names will be valueized using that hook prior to
435 applying simplifications. */
440 gimple_simplify (enum tree_code code
, tree type
,
442 gimple_seq
*seq
, tree (*valueize
)(tree
))
444 if (constant_for_folding (op0
))
446 tree res
= const_unop (code
, type
, op0
);
448 && CONSTANT_CLASS_P (res
))
454 if (!gimple_simplify (&rcode
, ops
, seq
, valueize
,
457 return maybe_push_res_to_seq (rcode
, type
, ops
, seq
);
463 gimple_simplify (enum tree_code code
, tree type
,
465 gimple_seq
*seq
, tree (*valueize
)(tree
))
467 if (constant_for_folding (op0
) && constant_for_folding (op1
))
469 tree res
= const_binop (code
, type
, op0
, op1
);
471 && CONSTANT_CLASS_P (res
))
475 /* Canonicalize operand order both for matching and fallback stmt
477 if ((commutative_tree_code (code
)
478 || TREE_CODE_CLASS (code
) == tcc_comparison
)
479 && tree_swap_operands_p (op0
, op1
))
481 std::swap (op0
, op1
);
482 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
483 code
= swap_tree_comparison (code
);
488 if (!gimple_simplify (&rcode
, ops
, seq
, valueize
,
489 code
, type
, op0
, op1
))
491 return maybe_push_res_to_seq (rcode
, type
, ops
, seq
);
497 gimple_simplify (enum tree_code code
, tree type
,
498 tree op0
, tree op1
, tree op2
,
499 gimple_seq
*seq
, tree (*valueize
)(tree
))
501 if (constant_for_folding (op0
) && constant_for_folding (op1
)
502 && constant_for_folding (op2
))
504 tree res
= fold_ternary
/*_to_constant */ (code
, type
, op0
, op1
, op2
);
506 && CONSTANT_CLASS_P (res
))
510 /* Canonicalize operand order both for matching and fallback stmt
512 if (commutative_ternary_tree_code (code
)
513 && tree_swap_operands_p (op0
, op1
))
514 std::swap (op0
, op1
);
518 if (!gimple_simplify (&rcode
, ops
, seq
, valueize
,
519 code
, type
, op0
, op1
, op2
))
521 return maybe_push_res_to_seq (rcode
, type
, ops
, seq
);
524 /* Builtin function with one argument. */
527 gimple_simplify (enum built_in_function fn
, tree type
,
529 gimple_seq
*seq
, tree (*valueize
)(tree
))
531 if (constant_for_folding (arg0
))
533 tree res
= fold_const_call (as_combined_fn (fn
), type
, arg0
);
534 if (res
&& CONSTANT_CLASS_P (res
))
540 if (!gimple_simplify (&rcode
, ops
, seq
, valueize
,
541 as_combined_fn (fn
), type
, arg0
))
543 return maybe_push_res_to_seq (rcode
, type
, ops
, seq
);
546 /* Builtin function with two arguments. */
549 gimple_simplify (enum built_in_function fn
, tree type
,
550 tree arg0
, tree arg1
,
551 gimple_seq
*seq
, tree (*valueize
)(tree
))
553 if (constant_for_folding (arg0
)
554 && constant_for_folding (arg1
))
556 tree res
= fold_const_call (as_combined_fn (fn
), type
, arg0
, arg1
);
557 if (res
&& CONSTANT_CLASS_P (res
))
563 if (!gimple_simplify (&rcode
, ops
, seq
, valueize
,
564 as_combined_fn (fn
), type
, arg0
, arg1
))
566 return maybe_push_res_to_seq (rcode
, type
, ops
, seq
);
569 /* Builtin function with three arguments. */
572 gimple_simplify (enum built_in_function fn
, tree type
,
573 tree arg0
, tree arg1
, tree arg2
,
574 gimple_seq
*seq
, tree (*valueize
)(tree
))
576 if (constant_for_folding (arg0
)
577 && constant_for_folding (arg1
)
578 && constant_for_folding (arg2
))
580 tree res
= fold_const_call (as_combined_fn (fn
), type
, arg0
, arg1
, arg2
);
581 if (res
&& CONSTANT_CLASS_P (res
))
587 if (!gimple_simplify (&rcode
, ops
, seq
, valueize
,
588 as_combined_fn (fn
), type
, arg0
, arg1
, arg2
))
590 return maybe_push_res_to_seq (rcode
, type
, ops
, seq
);
593 /* Helper for gimple_simplify valueizing OP using VALUEIZE and setting
594 VALUEIZED to true if valueization changed OP. */
597 do_valueize (tree op
, tree (*valueize
)(tree
), bool &valueized
)
599 if (valueize
&& TREE_CODE (op
) == SSA_NAME
)
601 tree tem
= valueize (op
);
602 if (tem
&& tem
!= op
)
611 /* The main STMT based simplification entry. It is used by the fold_stmt
612 and the fold_stmt_to_constant APIs. */
615 gimple_simplify (gimple
*stmt
,
616 code_helper
*rcode
, tree
*ops
,
618 tree (*valueize
)(tree
), tree (*top_valueize
)(tree
))
620 switch (gimple_code (stmt
))
624 enum tree_code code
= gimple_assign_rhs_code (stmt
);
625 tree type
= TREE_TYPE (gimple_assign_lhs (stmt
));
626 switch (gimple_assign_rhs_class (stmt
))
628 case GIMPLE_SINGLE_RHS
:
629 if (code
== REALPART_EXPR
630 || code
== IMAGPART_EXPR
631 || code
== VIEW_CONVERT_EXPR
)
633 tree op0
= TREE_OPERAND (gimple_assign_rhs1 (stmt
), 0);
634 bool valueized
= false;
635 op0
= do_valueize (op0
, top_valueize
, valueized
);
638 return (gimple_resimplify1 (seq
, rcode
, type
, ops
, valueize
)
641 else if (code
== BIT_FIELD_REF
)
643 tree rhs1
= gimple_assign_rhs1 (stmt
);
644 tree op0
= TREE_OPERAND (rhs1
, 0);
645 bool valueized
= false;
646 op0
= do_valueize (op0
, top_valueize
, valueized
);
649 ops
[1] = TREE_OPERAND (rhs1
, 1);
650 ops
[2] = TREE_OPERAND (rhs1
, 2);
651 return (gimple_resimplify3 (seq
, rcode
, type
, ops
, valueize
)
654 else if (code
== SSA_NAME
657 tree op0
= gimple_assign_rhs1 (stmt
);
658 tree valueized
= top_valueize (op0
);
659 if (!valueized
|| op0
== valueized
)
662 *rcode
= TREE_CODE (op0
);
666 case GIMPLE_UNARY_RHS
:
668 tree rhs1
= gimple_assign_rhs1 (stmt
);
669 bool valueized
= false;
670 rhs1
= do_valueize (rhs1
, top_valueize
, valueized
);
673 return (gimple_resimplify1 (seq
, rcode
, type
, ops
, valueize
)
676 case GIMPLE_BINARY_RHS
:
678 tree rhs1
= gimple_assign_rhs1 (stmt
);
679 tree rhs2
= gimple_assign_rhs2 (stmt
);
680 bool valueized
= false;
681 rhs1
= do_valueize (rhs1
, top_valueize
, valueized
);
682 rhs2
= do_valueize (rhs2
, top_valueize
, valueized
);
686 return (gimple_resimplify2 (seq
, rcode
, type
, ops
, valueize
)
689 case GIMPLE_TERNARY_RHS
:
691 bool valueized
= false;
692 tree rhs1
= gimple_assign_rhs1 (stmt
);
693 /* If this is a [VEC_]COND_EXPR first try to simplify an
694 embedded GENERIC condition. */
695 if (code
== COND_EXPR
696 || code
== VEC_COND_EXPR
)
698 if (COMPARISON_CLASS_P (rhs1
))
700 tree lhs
= TREE_OPERAND (rhs1
, 0);
701 tree rhs
= TREE_OPERAND (rhs1
, 1);
702 lhs
= do_valueize (lhs
, top_valueize
, valueized
);
703 rhs
= do_valueize (rhs
, top_valueize
, valueized
);
704 code_helper rcode2
= TREE_CODE (rhs1
);
708 if ((gimple_resimplify2 (seq
, &rcode2
, TREE_TYPE (rhs1
),
711 && rcode2
.is_tree_code ())
714 if (TREE_CODE_CLASS ((enum tree_code
)rcode2
)
716 rhs1
= build2 (rcode2
, TREE_TYPE (rhs1
),
718 else if (rcode2
== SSA_NAME
719 || rcode2
== INTEGER_CST
720 || rcode2
== VECTOR_CST
)
727 tree rhs2
= gimple_assign_rhs2 (stmt
);
728 tree rhs3
= gimple_assign_rhs3 (stmt
);
729 rhs1
= do_valueize (rhs1
, top_valueize
, valueized
);
730 rhs2
= do_valueize (rhs2
, top_valueize
, valueized
);
731 rhs3
= do_valueize (rhs3
, top_valueize
, valueized
);
736 return (gimple_resimplify3 (seq
, rcode
, type
, ops
, valueize
)
746 /* ??? This way we can't simplify calls with side-effects. */
747 if (gimple_call_lhs (stmt
) != NULL_TREE
748 && gimple_call_num_args (stmt
) >= 1
749 && gimple_call_num_args (stmt
) <= 3)
751 bool valueized
= false;
752 if (gimple_call_internal_p (stmt
))
753 *rcode
= as_combined_fn (gimple_call_internal_fn (stmt
));
756 tree fn
= gimple_call_fn (stmt
);
760 fn
= do_valueize (fn
, top_valueize
, valueized
);
761 if (TREE_CODE (fn
) != ADDR_EXPR
762 || TREE_CODE (TREE_OPERAND (fn
, 0)) != FUNCTION_DECL
)
765 tree decl
= TREE_OPERAND (fn
, 0);
766 if (DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_NORMAL
767 || !gimple_builtin_call_types_compatible_p (stmt
, decl
))
770 *rcode
= as_combined_fn (DECL_FUNCTION_CODE (decl
));
773 tree type
= TREE_TYPE (gimple_call_lhs (stmt
));
774 for (unsigned i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
776 tree arg
= gimple_call_arg (stmt
, i
);
777 ops
[i
] = do_valueize (arg
, top_valueize
, valueized
);
779 switch (gimple_call_num_args (stmt
))
782 return (gimple_resimplify1 (seq
, rcode
, type
, ops
, valueize
)
785 return (gimple_resimplify2 (seq
, rcode
, type
, ops
, valueize
)
788 return (gimple_resimplify3 (seq
, rcode
, type
, ops
, valueize
)
798 tree lhs
= gimple_cond_lhs (stmt
);
799 tree rhs
= gimple_cond_rhs (stmt
);
800 bool valueized
= false;
801 lhs
= do_valueize (lhs
, top_valueize
, valueized
);
802 rhs
= do_valueize (rhs
, top_valueize
, valueized
);
803 *rcode
= gimple_cond_code (stmt
);
806 return (gimple_resimplify2 (seq
, rcode
,
807 boolean_type_node
, ops
, valueize
)
819 /* Helper for the autogenerated code, valueize OP. */
822 do_valueize (tree (*valueize
)(tree
), tree op
)
824 if (valueize
&& TREE_CODE (op
) == SSA_NAME
)
826 tree tem
= valueize (op
);
833 /* Helper for the autogenerated code, get at the definition of NAME when
834 VALUEIZE allows that. */
837 get_def (tree (*valueize
)(tree
), tree name
)
839 if (valueize
&& ! valueize (name
))
841 return SSA_NAME_DEF_STMT (name
);
844 /* Routine to determine if the types T1 and T2 are effectively
845 the same for GIMPLE. If T1 or T2 is not a type, the test
846 applies to their TREE_TYPE. */
849 types_match (tree t1
, tree t2
)
856 return types_compatible_p (t1
, t2
);
859 /* Return if T has a single use. For GIMPLE, we also allow any
860 non-SSA_NAME (ie constants) and zero uses to cope with uses
861 that aren't linked up yet. */
866 return TREE_CODE (t
) != SSA_NAME
|| has_zero_uses (t
) || has_single_use (t
);
869 /* Return true if math operations should be canonicalized,
870 e.g. sqrt(sqrt(x)) -> pow(x, 0.25). */
873 canonicalize_math_p ()
875 return !cfun
|| (cfun
->curr_properties
& PROP_gimple_opt_math
) == 0;
878 /* Return true if math operations that are beneficial only after
879 vectorization should be canonicalized. */
882 canonicalize_math_after_vectorization_p ()
884 return !cfun
|| (cfun
->curr_properties
& PROP_gimple_lvec
) != 0;
887 /* Return true if pow(cst, x) should be optimized into exp(log(cst) * x).
888 As a workaround for SPEC CPU2017 628.pop2_s, don't do it if arg0
889 is an exact integer, arg1 = phi_res +/- cst1 and phi_res = PHI <cst2, ...>
890 where cst2 +/- cst1 is an exact integer, because then pow (arg0, arg1)
891 will likely be exact, while exp (log (arg0) * arg1) might be not.
892 Also don't do it if arg1 is phi_res above and cst2 is an exact integer. */
895 optimize_pow_to_exp (tree arg0
, tree arg1
)
897 gcc_assert (TREE_CODE (arg0
) == REAL_CST
);
898 if (!real_isinteger (TREE_REAL_CST_PTR (arg0
), TYPE_MODE (TREE_TYPE (arg0
))))
901 if (TREE_CODE (arg1
) != SSA_NAME
)
904 gimple
*def
= SSA_NAME_DEF_STMT (arg1
);
905 gphi
*phi
= dyn_cast
<gphi
*> (def
);
906 tree cst1
= NULL_TREE
;
907 enum tree_code code
= ERROR_MARK
;
910 if (!is_gimple_assign (def
))
912 code
= gimple_assign_rhs_code (def
);
921 if (TREE_CODE (gimple_assign_rhs1 (def
)) != SSA_NAME
922 || TREE_CODE (gimple_assign_rhs2 (def
)) != REAL_CST
)
925 cst1
= gimple_assign_rhs2 (def
);
927 phi
= dyn_cast
<gphi
*> (SSA_NAME_DEF_STMT (gimple_assign_rhs1 (def
)));
932 tree cst2
= NULL_TREE
;
933 int n
= gimple_phi_num_args (phi
);
934 for (int i
= 0; i
< n
; i
++)
936 tree arg
= PHI_ARG_DEF (phi
, i
);
937 if (TREE_CODE (arg
) != REAL_CST
)
939 else if (cst2
== NULL_TREE
)
941 else if (!operand_equal_p (cst2
, arg
, 0))
946 cst2
= const_binop (code
, TREE_TYPE (cst2
), cst2
, cst1
);
948 && TREE_CODE (cst2
) == REAL_CST
949 && real_isinteger (TREE_REAL_CST_PTR (cst2
),
950 TYPE_MODE (TREE_TYPE (cst2
))))