PR jit/66539: Properly add testcase
[official-gcc.git] / gcc / gimple-match-head.c
blob8fbb4897c245ea88fec5f8a77304fdc7fc822d2f
1 /* Preamble and helpers for the autogenerated gimple-match.c file.
2 Copyright (C) 2014-2015 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
9 version.
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
14 for more details.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "input.h"
25 #include "alias.h"
26 #include "symtab.h"
27 #include "options.h"
28 #include "tree.h"
29 #include "fold-const.h"
30 #include "stringpool.h"
31 #include "stor-layout.h"
32 #include "flags.h"
33 #include "hard-reg-set.h"
34 #include "function.h"
35 #include "predict.h"
36 #include "basic-block.h"
37 #include "tree-ssa-alias.h"
38 #include "internal-fn.h"
39 #include "gimple-expr.h"
40 #include "is-a.h"
41 #include "gimple.h"
42 #include "gimple-ssa.h"
43 #include "tree-ssanames.h"
44 #include "gimple-fold.h"
45 #include "gimple-iterator.h"
46 #include "rtl.h"
47 #include "insn-config.h"
48 #include "expmed.h"
49 #include "dojump.h"
50 #include "explow.h"
51 #include "calls.h"
52 #include "emit-rtl.h"
53 #include "varasm.h"
54 #include "stmt.h"
55 #include "expr.h"
56 #include "tree-dfa.h"
57 #include "builtins.h"
58 #include "tree-phinodes.h"
59 #include "ssa-iterators.h"
60 #include "dumpfile.h"
61 #include "gimple-match.h"
64 /* Forward declarations of the private auto-generated matchers.
65 They expect valueized operands in canonical order and do not
66 perform simplification of all-constant operands. */
67 static bool gimple_simplify (code_helper *, tree *,
68 gimple_seq *, tree (*)(tree),
69 code_helper, tree, tree);
70 static bool gimple_simplify (code_helper *, tree *,
71 gimple_seq *, tree (*)(tree),
72 code_helper, tree, tree, tree);
73 static bool gimple_simplify (code_helper *, tree *,
74 gimple_seq *, tree (*)(tree),
75 code_helper, tree, tree, tree, tree);
78 /* Return whether T is a constant that we'll dispatch to fold to
79 evaluate fully constant expressions. */
81 static inline bool
82 constant_for_folding (tree t)
84 return (CONSTANT_CLASS_P (t)
85 /* The following is only interesting to string builtins. */
86 || (TREE_CODE (t) == ADDR_EXPR
87 && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST));
91 /* Helper that matches and simplifies the toplevel result from
92 a gimple_simplify run (where we don't want to build
93 a stmt in case it's used in in-place folding). Replaces
94 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
95 result and returns whether any change was made. */
97 static bool
98 gimple_resimplify1 (gimple_seq *seq,
99 code_helper *res_code, tree type, tree *res_ops,
100 tree (*valueize)(tree))
102 if (constant_for_folding (res_ops[0]))
104 tree tem = NULL_TREE;
105 if (res_code->is_tree_code ())
106 tem = const_unop (*res_code, type, res_ops[0]);
107 else
109 tree decl = builtin_decl_implicit (*res_code);
110 if (decl)
112 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 1, false);
113 if (tem)
115 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
116 STRIP_NOPS (tem);
117 tem = fold_convert (type, tem);
121 if (tem != NULL_TREE
122 && CONSTANT_CLASS_P (tem))
124 res_ops[0] = tem;
125 res_ops[1] = NULL_TREE;
126 res_ops[2] = NULL_TREE;
127 *res_code = TREE_CODE (res_ops[0]);
128 return true;
132 code_helper res_code2;
133 tree res_ops2[3] = {};
134 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
135 *res_code, type, res_ops[0]))
137 *res_code = res_code2;
138 res_ops[0] = res_ops2[0];
139 res_ops[1] = res_ops2[1];
140 res_ops[2] = res_ops2[2];
141 return true;
144 return false;
147 /* Helper that matches and simplifies the toplevel result from
148 a gimple_simplify run (where we don't want to build
149 a stmt in case it's used in in-place folding). Replaces
150 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
151 result and returns whether any change was made. */
153 static bool
154 gimple_resimplify2 (gimple_seq *seq,
155 code_helper *res_code, tree type, tree *res_ops,
156 tree (*valueize)(tree))
158 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1]))
160 tree tem = NULL_TREE;
161 if (res_code->is_tree_code ())
162 tem = const_binop (*res_code, type, res_ops[0], res_ops[1]);
163 else
165 tree decl = builtin_decl_implicit (*res_code);
166 if (decl)
168 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 2, false);
169 if (tem)
171 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
172 STRIP_NOPS (tem);
173 tem = fold_convert (type, tem);
177 if (tem != NULL_TREE
178 && CONSTANT_CLASS_P (tem))
180 res_ops[0] = tem;
181 res_ops[1] = NULL_TREE;
182 res_ops[2] = NULL_TREE;
183 *res_code = TREE_CODE (res_ops[0]);
184 return true;
188 /* Canonicalize operand order. */
189 bool canonicalized = false;
190 if (res_code->is_tree_code ()
191 && (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison
192 || commutative_tree_code (*res_code))
193 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
195 tree tem = res_ops[0];
196 res_ops[0] = res_ops[1];
197 res_ops[1] = tem;
198 if (TREE_CODE_CLASS ((enum tree_code) *res_code) == tcc_comparison)
199 *res_code = swap_tree_comparison (*res_code);
200 canonicalized = true;
203 code_helper res_code2;
204 tree res_ops2[3] = {};
205 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
206 *res_code, type, res_ops[0], res_ops[1]))
208 *res_code = res_code2;
209 res_ops[0] = res_ops2[0];
210 res_ops[1] = res_ops2[1];
211 res_ops[2] = res_ops2[2];
212 return true;
215 return canonicalized;
218 /* Helper that matches and simplifies the toplevel result from
219 a gimple_simplify run (where we don't want to build
220 a stmt in case it's used in in-place folding). Replaces
221 *RES_CODE and *RES_OPS with a simplified and/or canonicalized
222 result and returns whether any change was made. */
224 static bool
225 gimple_resimplify3 (gimple_seq *seq,
226 code_helper *res_code, tree type, tree *res_ops,
227 tree (*valueize)(tree))
229 if (constant_for_folding (res_ops[0]) && constant_for_folding (res_ops[1])
230 && constant_for_folding (res_ops[2]))
232 tree tem = NULL_TREE;
233 if (res_code->is_tree_code ())
234 tem = fold_ternary/*_to_constant*/ (*res_code, type, res_ops[0],
235 res_ops[1], res_ops[2]);
236 else
238 tree decl = builtin_decl_implicit (*res_code);
239 if (decl)
241 tem = fold_builtin_n (UNKNOWN_LOCATION, decl, res_ops, 3, false);
242 if (tem)
244 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
245 STRIP_NOPS (tem);
246 tem = fold_convert (type, tem);
250 if (tem != NULL_TREE
251 && CONSTANT_CLASS_P (tem))
253 res_ops[0] = tem;
254 res_ops[1] = NULL_TREE;
255 res_ops[2] = NULL_TREE;
256 *res_code = TREE_CODE (res_ops[0]);
257 return true;
261 /* Canonicalize operand order. */
262 bool canonicalized = false;
263 if (res_code->is_tree_code ()
264 && commutative_ternary_tree_code (*res_code)
265 && tree_swap_operands_p (res_ops[0], res_ops[1], false))
267 tree tem = res_ops[0];
268 res_ops[0] = res_ops[1];
269 res_ops[1] = tem;
270 canonicalized = true;
273 code_helper res_code2;
274 tree res_ops2[3] = {};
275 if (gimple_simplify (&res_code2, res_ops2, seq, valueize,
276 *res_code, type,
277 res_ops[0], res_ops[1], res_ops[2]))
279 *res_code = res_code2;
280 res_ops[0] = res_ops2[0];
281 res_ops[1] = res_ops2[1];
282 res_ops[2] = res_ops2[2];
283 return true;
286 return canonicalized;
290 /* If in GIMPLE expressions with CODE go as single-rhs build
291 a GENERIC tree for that expression into *OP0. */
293 void
294 maybe_build_generic_op (enum tree_code code, tree type,
295 tree *op0, tree op1, tree op2)
297 switch (code)
299 case REALPART_EXPR:
300 case IMAGPART_EXPR:
301 case VIEW_CONVERT_EXPR:
302 *op0 = build1 (code, type, *op0);
303 break;
304 case BIT_FIELD_REF:
305 *op0 = build3 (code, type, *op0, op1, op2);
306 break;
307 default:;
311 /* Push the exploded expression described by RCODE, TYPE and OPS
312 as a statement to SEQ if necessary and return a gimple value
313 denoting the value of the expression. If RES is not NULL
314 then the result will be always RES and even gimple values are
315 pushed to SEQ. */
317 tree
318 maybe_push_res_to_seq (code_helper rcode, tree type, tree *ops,
319 gimple_seq *seq, tree res)
321 if (rcode.is_tree_code ())
323 if (!res
324 && (TREE_CODE_LENGTH ((tree_code) rcode) == 0
325 || ((tree_code) rcode) == ADDR_EXPR)
326 && is_gimple_val (ops[0]))
327 return ops[0];
328 if (!seq)
329 return NULL_TREE;
330 /* Play safe and do not allow abnormals to be mentioned in
331 newly created statements. */
332 if ((TREE_CODE (ops[0]) == SSA_NAME
333 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
334 || (ops[1]
335 && TREE_CODE (ops[1]) == SSA_NAME
336 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
337 || (ops[2]
338 && TREE_CODE (ops[2]) == SSA_NAME
339 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
340 return NULL_TREE;
341 if (!res)
342 res = make_ssa_name (type);
343 maybe_build_generic_op (rcode, type, &ops[0], ops[1], ops[2]);
344 gimple new_stmt = gimple_build_assign (res, rcode,
345 ops[0], ops[1], ops[2]);
346 gimple_seq_add_stmt_without_update (seq, new_stmt);
347 return res;
349 else
351 if (!seq)
352 return NULL_TREE;
353 tree decl = builtin_decl_implicit (rcode);
354 if (!decl)
355 return NULL_TREE;
356 unsigned nargs = type_num_arguments (TREE_TYPE (decl));
357 gcc_assert (nargs <= 3);
358 /* Play safe and do not allow abnormals to be mentioned in
359 newly created statements. */
360 if ((TREE_CODE (ops[0]) == SSA_NAME
361 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[0]))
362 || (nargs >= 2
363 && TREE_CODE (ops[1]) == SSA_NAME
364 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[1]))
365 || (nargs == 3
366 && TREE_CODE (ops[2]) == SSA_NAME
367 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
368 return NULL_TREE;
369 if (!res)
370 res = make_ssa_name (type);
371 gimple new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], ops[2]);
372 gimple_call_set_lhs (new_stmt, res);
373 gimple_seq_add_stmt_without_update (seq, new_stmt);
374 return res;
379 /* Public API overloads follow for operation being tree_code or
380 built_in_function and for one to three operands or arguments.
381 They return NULL_TREE if nothing could be simplified or
382 the resulting simplified value with parts pushed to SEQ.
383 If SEQ is NULL then if the simplification needs to create
384 new stmts it will fail. If VALUEIZE is non-NULL then all
385 SSA names will be valueized using that hook prior to
386 applying simplifications. */
388 /* Unary ops. */
390 tree
391 gimple_simplify (enum tree_code code, tree type,
392 tree op0,
393 gimple_seq *seq, tree (*valueize)(tree))
395 if (constant_for_folding (op0))
397 tree res = const_unop (code, type, op0);
398 if (res != NULL_TREE
399 && CONSTANT_CLASS_P (res))
400 return res;
403 code_helper rcode;
404 tree ops[3] = {};
405 if (!gimple_simplify (&rcode, ops, seq, valueize,
406 code, type, op0))
407 return NULL_TREE;
408 return maybe_push_res_to_seq (rcode, type, ops, seq);
411 /* Binary ops. */
413 tree
414 gimple_simplify (enum tree_code code, tree type,
415 tree op0, tree op1,
416 gimple_seq *seq, tree (*valueize)(tree))
418 if (constant_for_folding (op0) && constant_for_folding (op1))
420 tree res = const_binop (code, type, op0, op1);
421 if (res != NULL_TREE
422 && CONSTANT_CLASS_P (res))
423 return res;
426 /* Canonicalize operand order both for matching and fallback stmt
427 generation. */
428 if ((commutative_tree_code (code)
429 || TREE_CODE_CLASS (code) == tcc_comparison)
430 && tree_swap_operands_p (op0, op1, false))
432 tree tem = op0;
433 op0 = op1;
434 op1 = tem;
435 if (TREE_CODE_CLASS (code) == tcc_comparison)
436 code = swap_tree_comparison (code);
439 code_helper rcode;
440 tree ops[3] = {};
441 if (!gimple_simplify (&rcode, ops, seq, valueize,
442 code, type, op0, op1))
443 return NULL_TREE;
444 return maybe_push_res_to_seq (rcode, type, ops, seq);
447 /* Ternary ops. */
449 tree
450 gimple_simplify (enum tree_code code, tree type,
451 tree op0, tree op1, tree op2,
452 gimple_seq *seq, tree (*valueize)(tree))
454 if (constant_for_folding (op0) && constant_for_folding (op1)
455 && constant_for_folding (op2))
457 tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2);
458 if (res != NULL_TREE
459 && CONSTANT_CLASS_P (res))
460 return res;
463 /* Canonicalize operand order both for matching and fallback stmt
464 generation. */
465 if (commutative_ternary_tree_code (code)
466 && tree_swap_operands_p (op0, op1, false))
468 tree tem = op0;
469 op0 = op1;
470 op1 = tem;
473 code_helper rcode;
474 tree ops[3] = {};
475 if (!gimple_simplify (&rcode, ops, seq, valueize,
476 code, type, op0, op1, op2))
477 return NULL_TREE;
478 return maybe_push_res_to_seq (rcode, type, ops, seq);
481 /* Builtin function with one argument. */
483 tree
484 gimple_simplify (enum built_in_function fn, tree type,
485 tree arg0,
486 gimple_seq *seq, tree (*valueize)(tree))
488 if (constant_for_folding (arg0))
490 tree decl = builtin_decl_implicit (fn);
491 if (decl)
493 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, &arg0, 1, false);
494 if (res)
496 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
497 STRIP_NOPS (res);
498 res = fold_convert (type, res);
499 if (CONSTANT_CLASS_P (res))
500 return res;
505 code_helper rcode;
506 tree ops[3] = {};
507 if (!gimple_simplify (&rcode, ops, seq, valueize,
508 fn, type, arg0))
509 return NULL_TREE;
510 return maybe_push_res_to_seq (rcode, type, ops, seq);
513 /* Builtin function with two arguments. */
515 tree
516 gimple_simplify (enum built_in_function fn, tree type,
517 tree arg0, tree arg1,
518 gimple_seq *seq, tree (*valueize)(tree))
520 if (constant_for_folding (arg0)
521 && constant_for_folding (arg1))
523 tree decl = builtin_decl_implicit (fn);
524 if (decl)
526 tree args[2];
527 args[0] = arg0;
528 args[1] = arg1;
529 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 2, false);
530 if (res)
532 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
533 STRIP_NOPS (res);
534 res = fold_convert (type, res);
535 if (CONSTANT_CLASS_P (res))
536 return res;
541 code_helper rcode;
542 tree ops[3] = {};
543 if (!gimple_simplify (&rcode, ops, seq, valueize,
544 fn, type, arg0, arg1))
545 return NULL_TREE;
546 return maybe_push_res_to_seq (rcode, type, ops, seq);
549 /* Builtin function with three arguments. */
551 tree
552 gimple_simplify (enum built_in_function fn, tree type,
553 tree arg0, tree arg1, tree arg2,
554 gimple_seq *seq, tree (*valueize)(tree))
556 if (constant_for_folding (arg0)
557 && constant_for_folding (arg1)
558 && constant_for_folding (arg2))
560 tree decl = builtin_decl_implicit (fn);
561 if (decl)
563 tree args[3];
564 args[0] = arg0;
565 args[1] = arg1;
566 args[2] = arg2;
567 tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, args, 3, false);
568 if (res)
570 /* fold_builtin_n wraps the result inside a NOP_EXPR. */
571 STRIP_NOPS (res);
572 res = fold_convert (type, res);
573 if (CONSTANT_CLASS_P (res))
574 return res;
579 code_helper rcode;
580 tree ops[3] = {};
581 if (!gimple_simplify (&rcode, ops, seq, valueize,
582 fn, type, arg0, arg1, arg2))
583 return NULL_TREE;
584 return maybe_push_res_to_seq (rcode, type, ops, seq);
588 /* The main STMT based simplification entry. It is used by the fold_stmt
589 and the fold_stmt_to_constant APIs. */
591 bool
592 gimple_simplify (gimple stmt,
593 code_helper *rcode, tree *ops,
594 gimple_seq *seq,
595 tree (*valueize)(tree), tree (*top_valueize)(tree))
597 switch (gimple_code (stmt))
599 case GIMPLE_ASSIGN:
601 enum tree_code code = gimple_assign_rhs_code (stmt);
602 tree type = TREE_TYPE (gimple_assign_lhs (stmt));
603 switch (gimple_assign_rhs_class (stmt))
605 case GIMPLE_SINGLE_RHS:
606 if (code == REALPART_EXPR
607 || code == IMAGPART_EXPR
608 || code == VIEW_CONVERT_EXPR)
610 tree op0 = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
611 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
613 tree tem = top_valueize (op0);
614 if (tem)
615 op0 = tem;
617 *rcode = code;
618 ops[0] = op0;
619 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
621 else if (code == BIT_FIELD_REF)
623 tree rhs1 = gimple_assign_rhs1 (stmt);
624 tree op0 = TREE_OPERAND (rhs1, 0);
625 if (top_valueize && TREE_CODE (op0) == SSA_NAME)
627 tree tem = top_valueize (op0);
628 if (tem)
629 op0 = tem;
631 *rcode = code;
632 ops[0] = op0;
633 ops[1] = TREE_OPERAND (rhs1, 1);
634 ops[2] = TREE_OPERAND (rhs1, 2);
635 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
637 else if (code == SSA_NAME
638 && top_valueize)
640 tree op0 = gimple_assign_rhs1 (stmt);
641 tree valueized = top_valueize (op0);
642 if (!valueized || op0 == valueized)
643 return false;
644 ops[0] = valueized;
645 *rcode = TREE_CODE (op0);
646 return true;
648 break;
649 case GIMPLE_UNARY_RHS:
651 tree rhs1 = gimple_assign_rhs1 (stmt);
652 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
654 tree tem = top_valueize (rhs1);
655 if (tem)
656 rhs1 = tem;
658 *rcode = code;
659 ops[0] = rhs1;
660 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
662 case GIMPLE_BINARY_RHS:
664 tree rhs1 = gimple_assign_rhs1 (stmt);
665 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
667 tree tem = top_valueize (rhs1);
668 if (tem)
669 rhs1 = tem;
671 tree rhs2 = gimple_assign_rhs2 (stmt);
672 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
674 tree tem = top_valueize (rhs2);
675 if (tem)
676 rhs2 = tem;
678 *rcode = code;
679 ops[0] = rhs1;
680 ops[1] = rhs2;
681 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
683 case GIMPLE_TERNARY_RHS:
685 tree rhs1 = gimple_assign_rhs1 (stmt);
686 if (top_valueize && TREE_CODE (rhs1) == SSA_NAME)
688 tree tem = top_valueize (rhs1);
689 if (tem)
690 rhs1 = tem;
692 tree rhs2 = gimple_assign_rhs2 (stmt);
693 if (top_valueize && TREE_CODE (rhs2) == SSA_NAME)
695 tree tem = top_valueize (rhs2);
696 if (tem)
697 rhs2 = tem;
699 tree rhs3 = gimple_assign_rhs3 (stmt);
700 if (top_valueize && TREE_CODE (rhs3) == SSA_NAME)
702 tree tem = top_valueize (rhs3);
703 if (tem)
704 rhs3 = tem;
706 *rcode = code;
707 ops[0] = rhs1;
708 ops[1] = rhs2;
709 ops[2] = rhs3;
710 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
712 default:
713 gcc_unreachable ();
715 break;
718 case GIMPLE_CALL:
719 /* ??? This way we can't simplify calls with side-effects. */
720 if (gimple_call_lhs (stmt) != NULL_TREE)
722 tree fn = gimple_call_fn (stmt);
723 /* ??? Internal function support missing. */
724 if (!fn)
725 return false;
726 if (top_valueize && TREE_CODE (fn) == SSA_NAME)
728 tree tem = top_valueize (fn);
729 if (tem)
730 fn = tem;
732 if (!fn
733 || TREE_CODE (fn) != ADDR_EXPR
734 || TREE_CODE (TREE_OPERAND (fn, 0)) != FUNCTION_DECL
735 || DECL_BUILT_IN_CLASS (TREE_OPERAND (fn, 0)) != BUILT_IN_NORMAL
736 || !builtin_decl_implicit (DECL_FUNCTION_CODE (TREE_OPERAND (fn, 0)))
737 || !gimple_builtin_call_types_compatible_p (stmt,
738 TREE_OPERAND (fn, 0)))
739 return false;
741 tree decl = TREE_OPERAND (fn, 0);
742 tree type = TREE_TYPE (gimple_call_lhs (stmt));
743 switch (gimple_call_num_args (stmt))
745 case 1:
747 tree arg1 = gimple_call_arg (stmt, 0);
748 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
750 tree tem = top_valueize (arg1);
751 if (tem)
752 arg1 = tem;
754 *rcode = DECL_FUNCTION_CODE (decl);
755 ops[0] = arg1;
756 return gimple_resimplify1 (seq, rcode, type, ops, valueize);
758 case 2:
760 tree arg1 = gimple_call_arg (stmt, 0);
761 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
763 tree tem = top_valueize (arg1);
764 if (tem)
765 arg1 = tem;
767 tree arg2 = gimple_call_arg (stmt, 1);
768 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
770 tree tem = top_valueize (arg2);
771 if (tem)
772 arg2 = tem;
774 *rcode = DECL_FUNCTION_CODE (decl);
775 ops[0] = arg1;
776 ops[1] = arg2;
777 return gimple_resimplify2 (seq, rcode, type, ops, valueize);
779 case 3:
781 tree arg1 = gimple_call_arg (stmt, 0);
782 if (top_valueize && TREE_CODE (arg1) == SSA_NAME)
784 tree tem = top_valueize (arg1);
785 if (tem)
786 arg1 = tem;
788 tree arg2 = gimple_call_arg (stmt, 1);
789 if (top_valueize && TREE_CODE (arg2) == SSA_NAME)
791 tree tem = top_valueize (arg2);
792 if (tem)
793 arg2 = tem;
795 tree arg3 = gimple_call_arg (stmt, 2);
796 if (top_valueize && TREE_CODE (arg3) == SSA_NAME)
798 tree tem = top_valueize (arg3);
799 if (tem)
800 arg3 = tem;
802 *rcode = DECL_FUNCTION_CODE (decl);
803 ops[0] = arg1;
804 ops[1] = arg2;
805 ops[2] = arg3;
806 return gimple_resimplify3 (seq, rcode, type, ops, valueize);
808 default:
809 return false;
812 break;
814 case GIMPLE_COND:
816 tree lhs = gimple_cond_lhs (stmt);
817 if (top_valueize && TREE_CODE (lhs) == SSA_NAME)
819 tree tem = top_valueize (lhs);
820 if (tem)
821 lhs = tem;
823 tree rhs = gimple_cond_rhs (stmt);
824 if (top_valueize && TREE_CODE (rhs) == SSA_NAME)
826 tree tem = top_valueize (rhs);
827 if (tem)
828 rhs = tem;
830 *rcode = gimple_cond_code (stmt);
831 ops[0] = lhs;
832 ops[1] = rhs;
833 return gimple_resimplify2 (seq, rcode, boolean_type_node, ops, valueize);
836 default:
837 break;
840 return false;
844 /* Helper for the autogenerated code, valueize OP. */
846 inline tree
847 do_valueize (tree (*valueize)(tree), tree op)
849 if (valueize && TREE_CODE (op) == SSA_NAME)
850 return valueize (op);
851 return op;
854 /* Routine to determine if the types T1 and T2 are effectively
855 the same for GIMPLE. If T1 or T2 is not a type, the test
856 applies to their TREE_TYPE. */
858 static inline bool
859 types_match (tree t1, tree t2)
861 if (!TYPE_P (t1))
862 t1 = TREE_TYPE (t1);
863 if (!TYPE_P (t2))
864 t2 = TREE_TYPE (t2);
866 return types_compatible_p (t1, t2);
869 /* Return if T has a single use. For GIMPLE, we also allow any
870 non-SSA_NAME (ie constants) and zero uses to cope with uses
871 that aren't linked up yet. */
873 static inline bool
874 single_use (tree t)
876 return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t);