1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
30 #include "insn-config.h"
31 #include "insn-attr.h"
32 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
35 #include "langhooks.h"
37 static void do_jump_by_parts_greater (tree, int, rtx, rtx);
38 static void do_jump_by_parts_equality (tree, rtx, rtx);
39 static void do_compare_and_jump (tree, enum rtx_code, enum rtx_code, rtx,
42 /* At the start of a function, record that we have no previously-pushed
43 arguments waiting to be popped. */
46 init_pending_stack_adjust (void)
48 pending_stack_adjust = 0;
51 /* When exiting from function, if safe, clear out any pending stack adjust
52 so the adjustment won't get done.
54 Note, if the current function calls alloca, then it must have a
55 frame pointer regardless of the value of flag_omit_frame_pointer. */
58 clear_pending_stack_adjust (void)
61 && (! flag_omit_frame_pointer || current_function_calls_alloca)
63 && ! (DECL_INLINE (current_function_decl) && ! flag_no_inline)
64 && ! flag_inline_functions)
66 stack_pointer_delta -= pending_stack_adjust,
67 pending_stack_adjust = 0;
71 /* Pop any previously-pushed arguments that have not been popped yet. */
74 do_pending_stack_adjust (void)
76 if (inhibit_defer_pop == 0)
78 if (pending_stack_adjust != 0)
79 adjust_stack (GEN_INT (pending_stack_adjust));
80 pending_stack_adjust = 0;
84 /* Expand conditional expressions. */
86 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
87 LABEL is an rtx of code CODE_LABEL, in this function and all the
91 jumpifnot (tree exp, rtx label)
93 do_jump (exp, label, NULL_RTX);
96 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
99 jumpif (tree exp, rtx label)
101 do_jump (exp, NULL_RTX, label);
104 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
105 the result is zero, or IF_TRUE_LABEL if the result is one.
106 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
107 meaning fall through in that case.
109 do_jump always does any pending stack adjust except when it does not
110 actually perform a jump. An example where there is no jump
111 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
113 This function is responsible for optimizing cases such as
114 &&, || and comparison operators in EXP. */
117 do_jump (tree exp, rtx if_false_label, rtx if_true_label)
119 enum tree_code code = TREE_CODE (exp);
120 /* Some cases need to create a label to jump to
121 in order to properly fall through.
122 These cases set DROP_THROUGH_LABEL nonzero. */
123 rtx drop_through_label = 0;
127 enum machine_mode mode;
129 #ifdef MAX_INTEGER_COMPUTATION_MODE
130 check_max_integer_computation_mode (exp);
141 temp = integer_zerop (exp) ? if_false_label : if_true_label;
147 /* This is not true with #pragma weak */
149 /* The address of something can never be zero. */
151 emit_jump (if_true_label);
156 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
157 TREE_OPERAND (exp, 0)
158 = (*lang_hooks.unsave_expr_now) (TREE_OPERAND (exp, 0));
162 if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
163 || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
164 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF
165 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_RANGE_REF)
168 /* If we are narrowing the operand, we have to do the compare in the
170 if ((TYPE_PRECISION (TREE_TYPE (exp))
171 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
173 case NON_LVALUE_EXPR:
179 /* These cannot change zero->nonzero or vice versa. */
180 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
183 case WITH_RECORD_EXPR:
184 /* Put the object on the placeholder list, recurse through our first
185 operand, and pop the list. */
186 placeholder_list = tree_cons (TREE_OPERAND (exp, 1), NULL_TREE,
188 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
189 placeholder_list = TREE_CHAIN (placeholder_list);
193 /* This is never less insns than evaluating the PLUS_EXPR followed by
194 a test and can be longer if the test is eliminated. */
196 /* Reduce to minus. */
197 exp = build (MINUS_EXPR, TREE_TYPE (exp),
198 TREE_OPERAND (exp, 0),
199 fold (build1 (NEGATE_EXPR, TREE_TYPE (TREE_OPERAND (exp, 1)),
200 TREE_OPERAND (exp, 1))));
201 /* Process as MINUS. */
205 /* Nonzero iff operands of minus differ. */
206 do_compare_and_jump (build (NE_EXPR, TREE_TYPE (exp),
207 TREE_OPERAND (exp, 0),
208 TREE_OPERAND (exp, 1)),
209 NE, NE, if_false_label, if_true_label);
213 /* If we are AND'ing with a small constant, do this comparison in the
214 smallest type that fits. If the machine doesn't have comparisons
215 that small, it will be converted back to the wider comparison.
216 This helps if we are testing the sign bit of a narrower object.
217 combine can't do this for us because it can't know whether a
218 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
220 if (! SLOW_BYTE_ACCESS
221 && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
222 && TYPE_PRECISION (TREE_TYPE (exp)) <= HOST_BITS_PER_WIDE_INT
223 && (i = tree_floor_log2 (TREE_OPERAND (exp, 1))) >= 0
224 && (mode = mode_for_size (i + 1, MODE_INT, 0)) != BLKmode
225 && (type = (*lang_hooks.types.type_for_mode) (mode, 1)) != 0
226 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
227 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
228 != CODE_FOR_nothing))
230 do_jump (convert (type, exp), if_false_label, if_true_label);
236 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
239 case TRUTH_ANDIF_EXPR:
240 if (if_false_label == 0)
241 if_false_label = drop_through_label = gen_label_rtx ();
242 do_jump (TREE_OPERAND (exp, 0), if_false_label, NULL_RTX);
243 start_cleanup_deferral ();
244 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
245 end_cleanup_deferral ();
248 case TRUTH_ORIF_EXPR:
249 if (if_true_label == 0)
250 if_true_label = drop_through_label = gen_label_rtx ();
251 do_jump (TREE_OPERAND (exp, 0), NULL_RTX, if_true_label);
252 start_cleanup_deferral ();
253 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
254 end_cleanup_deferral ();
259 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
260 preserve_temp_slots (NULL_RTX);
264 do_pending_stack_adjust ();
265 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
271 case ARRAY_RANGE_REF:
273 HOST_WIDE_INT bitsize, bitpos;
275 enum machine_mode mode;
280 /* Get description of this reference. We don't actually care
281 about the underlying object here. */
282 get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode,
283 &unsignedp, &volatilep);
285 type = (*lang_hooks.types.type_for_size) (bitsize, unsignedp);
286 if (! SLOW_BYTE_ACCESS
287 && type != 0 && bitsize >= 0
288 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
289 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
290 != CODE_FOR_nothing))
292 do_jump (convert (type, exp), if_false_label, if_true_label);
299 /* Do (a ? 1 : 0) and (a ? 0 : 1) as special cases. */
300 if (integer_onep (TREE_OPERAND (exp, 1))
301 && integer_zerop (TREE_OPERAND (exp, 2)))
302 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
304 else if (integer_zerop (TREE_OPERAND (exp, 1))
305 && integer_onep (TREE_OPERAND (exp, 2)))
306 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
310 rtx label1 = gen_label_rtx ();
311 drop_through_label = gen_label_rtx ();
313 do_jump (TREE_OPERAND (exp, 0), label1, NULL_RTX);
315 start_cleanup_deferral ();
316 /* Now the THEN-expression. */
317 do_jump (TREE_OPERAND (exp, 1),
318 if_false_label ? if_false_label : drop_through_label,
319 if_true_label ? if_true_label : drop_through_label);
320 /* In case the do_jump just above never jumps. */
321 do_pending_stack_adjust ();
324 /* Now the ELSE-expression. */
325 do_jump (TREE_OPERAND (exp, 2),
326 if_false_label ? if_false_label : drop_through_label,
327 if_true_label ? if_true_label : drop_through_label);
328 end_cleanup_deferral ();
334 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
336 if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
337 || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
339 tree exp0 = save_expr (TREE_OPERAND (exp, 0));
340 tree exp1 = save_expr (TREE_OPERAND (exp, 1));
343 (build (TRUTH_ANDIF_EXPR, TREE_TYPE (exp),
344 fold (build (EQ_EXPR, TREE_TYPE (exp),
345 fold (build1 (REALPART_EXPR,
346 TREE_TYPE (inner_type),
348 fold (build1 (REALPART_EXPR,
349 TREE_TYPE (inner_type),
351 fold (build (EQ_EXPR, TREE_TYPE (exp),
352 fold (build1 (IMAGPART_EXPR,
353 TREE_TYPE (inner_type),
355 fold (build1 (IMAGPART_EXPR,
356 TREE_TYPE (inner_type),
358 if_false_label, if_true_label);
361 else if (integer_zerop (TREE_OPERAND (exp, 1)))
362 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
364 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
365 && !can_compare_p (EQ, TYPE_MODE (inner_type), ccp_jump))
366 do_jump_by_parts_equality (exp, if_false_label, if_true_label);
368 do_compare_and_jump (exp, EQ, EQ, if_false_label, if_true_label);
374 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
376 if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
377 || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
379 tree exp0 = save_expr (TREE_OPERAND (exp, 0));
380 tree exp1 = save_expr (TREE_OPERAND (exp, 1));
383 (build (TRUTH_ORIF_EXPR, TREE_TYPE (exp),
384 fold (build (NE_EXPR, TREE_TYPE (exp),
385 fold (build1 (REALPART_EXPR,
386 TREE_TYPE (inner_type),
388 fold (build1 (REALPART_EXPR,
389 TREE_TYPE (inner_type),
391 fold (build (NE_EXPR, TREE_TYPE (exp),
392 fold (build1 (IMAGPART_EXPR,
393 TREE_TYPE (inner_type),
395 fold (build1 (IMAGPART_EXPR,
396 TREE_TYPE (inner_type),
398 if_false_label, if_true_label);
401 else if (integer_zerop (TREE_OPERAND (exp, 1)))
402 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
404 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
405 && !can_compare_p (NE, TYPE_MODE (inner_type), ccp_jump))
406 do_jump_by_parts_equality (exp, if_true_label, if_false_label);
408 do_compare_and_jump (exp, NE, NE, if_false_label, if_true_label);
413 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
414 if (GET_MODE_CLASS (mode) == MODE_INT
415 && ! can_compare_p (LT, mode, ccp_jump))
416 do_jump_by_parts_greater (exp, 1, if_false_label, if_true_label);
418 do_compare_and_jump (exp, LT, LTU, if_false_label, if_true_label);
422 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
423 if (GET_MODE_CLASS (mode) == MODE_INT
424 && ! can_compare_p (LE, mode, ccp_jump))
425 do_jump_by_parts_greater (exp, 0, if_true_label, if_false_label);
427 do_compare_and_jump (exp, LE, LEU, if_false_label, if_true_label);
431 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
432 if (GET_MODE_CLASS (mode) == MODE_INT
433 && ! can_compare_p (GT, mode, ccp_jump))
434 do_jump_by_parts_greater (exp, 0, if_false_label, if_true_label);
436 do_compare_and_jump (exp, GT, GTU, if_false_label, if_true_label);
440 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
441 if (GET_MODE_CLASS (mode) == MODE_INT
442 && ! can_compare_p (GE, mode, ccp_jump))
443 do_jump_by_parts_greater (exp, 1, if_true_label, if_false_label);
445 do_compare_and_jump (exp, GE, GEU, if_false_label, if_true_label);
451 enum rtx_code cmp, rcmp;
454 if (code == UNORDERED_EXPR)
455 cmp = UNORDERED, rcmp = ORDERED;
457 cmp = ORDERED, rcmp = UNORDERED;
458 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
461 if (! can_compare_p (cmp, mode, ccp_jump)
462 && (can_compare_p (rcmp, mode, ccp_jump)
463 /* If the target doesn't provide either UNORDERED or ORDERED
464 comparisons, canonicalize on UNORDERED for the library. */
465 || rcmp == UNORDERED))
469 do_compare_and_jump (exp, cmp, cmp, if_false_label, if_true_label);
471 do_compare_and_jump (exp, rcmp, rcmp, if_true_label, if_false_label);
476 enum rtx_code rcode1;
477 enum tree_code tcode2;
501 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
502 if (can_compare_p (rcode1, mode, ccp_jump))
503 do_compare_and_jump (exp, rcode1, rcode1, if_false_label,
507 tree op0 = save_expr (TREE_OPERAND (exp, 0));
508 tree op1 = save_expr (TREE_OPERAND (exp, 1));
511 /* If the target doesn't support combined unordered
512 compares, decompose into UNORDERED + comparison. */
513 cmp0 = fold (build (UNORDERED_EXPR, TREE_TYPE (exp), op0, op1));
514 cmp1 = fold (build (tcode2, TREE_TYPE (exp), op0, op1));
515 exp = build (TRUTH_ORIF_EXPR, TREE_TYPE (exp), cmp0, cmp1);
516 do_jump (exp, if_false_label, if_true_label);
522 __builtin_expect (<test>, 0) and
523 __builtin_expect (<test>, 1)
525 We need to do this here, so that <test> is not converted to a SCC
526 operation on machines that use condition code registers and COMPARE
527 like the PowerPC, and then the jump is done based on whether the SCC
528 operation produced a 1 or 0. */
530 /* Check for a built-in function. */
532 tree fndecl = get_callee_fndecl (exp);
533 tree arglist = TREE_OPERAND (exp, 1);
536 && DECL_BUILT_IN (fndecl)
537 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_EXPECT
538 && arglist != NULL_TREE
539 && TREE_CHAIN (arglist) != NULL_TREE)
541 rtx seq = expand_builtin_expect_jump (exp, if_false_label,
551 /* Fall through and generate the normal code. */
555 temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
557 /* This is not needed any more and causes poor code since it causes
558 comparisons and tests from non-SI objects to have different code
560 /* Copy to register to avoid generating bad insns by cse
561 from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
562 if (!cse_not_expected && GET_CODE (temp) == MEM)
563 temp = copy_to_reg (temp);
565 do_pending_stack_adjust ();
566 /* Do any postincrements in the expression that was tested. */
569 if (GET_CODE (temp) == CONST_INT
570 || (GET_CODE (temp) == CONST_DOUBLE && GET_MODE (temp) == VOIDmode)
571 || GET_CODE (temp) == LABEL_REF)
573 rtx target = temp == const0_rtx ? if_false_label : if_true_label;
577 else if (GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
578 && ! can_compare_p (NE, GET_MODE (temp), ccp_jump))
579 /* Note swapping the labels gives us not-equal. */
580 do_jump_by_parts_equality_rtx (temp, if_true_label, if_false_label);
581 else if (GET_MODE (temp) != VOIDmode)
583 /* The RTL optimizers prefer comparisons against pseudos. */
584 if (GET_CODE (temp) == SUBREG)
586 /* Compare promoted variables in their promoted mode. */
587 if (SUBREG_PROMOTED_VAR_P (temp)
588 && GET_CODE (XEXP (temp, 0)) == REG)
589 temp = XEXP (temp, 0);
591 temp = copy_to_reg (temp);
593 do_compare_rtx_and_jump (temp, CONST0_RTX (GET_MODE (temp)),
594 NE, TREE_UNSIGNED (TREE_TYPE (exp)),
595 GET_MODE (temp), NULL_RTX,
596 if_false_label, if_true_label);
602 if (drop_through_label)
604 /* If do_jump produces code that might be jumped around,
605 do any stack adjusts from that code, before the place
606 where control merges in. */
607 do_pending_stack_adjust ();
608 emit_label (drop_through_label);
612 /* Given a comparison expression EXP for values too wide to be compared
613 with one insn, test the comparison and jump to the appropriate label.
614 The code of EXP is ignored; we always test GT if SWAP is 0,
615 and LT if SWAP is 1. */
618 do_jump_by_parts_greater (tree exp, int swap, rtx if_false_label,
621 rtx op0 = expand_expr (TREE_OPERAND (exp, swap), NULL_RTX, VOIDmode, 0);
622 rtx op1 = expand_expr (TREE_OPERAND (exp, !swap), NULL_RTX, VOIDmode, 0);
623 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
624 int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
626 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label, if_true_label);
629 /* Compare OP0 with OP1, word at a time, in mode MODE.
630 UNSIGNEDP says to do unsigned comparison.
631 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
634 do_jump_by_parts_greater_rtx (enum machine_mode mode, int unsignedp, rtx op0,
635 rtx op1, rtx if_false_label, rtx if_true_label)
637 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
638 rtx drop_through_label = 0;
641 if (! if_true_label || ! if_false_label)
642 drop_through_label = gen_label_rtx ();
644 if_true_label = drop_through_label;
645 if (! if_false_label)
646 if_false_label = drop_through_label;
648 /* Compare a word at a time, high order first. */
649 for (i = 0; i < nwords; i++)
651 rtx op0_word, op1_word;
653 if (WORDS_BIG_ENDIAN)
655 op0_word = operand_subword_force (op0, i, mode);
656 op1_word = operand_subword_force (op1, i, mode);
660 op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
661 op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
664 /* All but high-order word must be compared as unsigned. */
665 do_compare_rtx_and_jump (op0_word, op1_word, GT,
666 (unsignedp || i > 0), word_mode, NULL_RTX,
667 NULL_RTX, if_true_label);
669 /* Consider lower words only if these are equal. */
670 do_compare_rtx_and_jump (op0_word, op1_word, NE, unsignedp, word_mode,
671 NULL_RTX, NULL_RTX, if_false_label);
675 emit_jump (if_false_label);
676 if (drop_through_label)
677 emit_label (drop_through_label);
680 /* Given an EQ_EXPR expression EXP for values too wide to be compared
681 with one insn, test the comparison and jump to the appropriate label. */
684 do_jump_by_parts_equality (tree exp, rtx if_false_label, rtx if_true_label)
686 rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
687 rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
688 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
689 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
691 rtx drop_through_label = 0;
693 if (! if_false_label)
694 drop_through_label = if_false_label = gen_label_rtx ();
696 for (i = 0; i < nwords; i++)
697 do_compare_rtx_and_jump (operand_subword_force (op0, i, mode),
698 operand_subword_force (op1, i, mode),
699 EQ, TREE_UNSIGNED (TREE_TYPE (exp)),
700 word_mode, NULL_RTX, if_false_label, NULL_RTX);
703 emit_jump (if_true_label);
704 if (drop_through_label)
705 emit_label (drop_through_label);
708 /* Jump according to whether OP0 is 0.
709 We assume that OP0 has an integer mode that is too wide
710 for the available compare insns. */
713 do_jump_by_parts_equality_rtx (rtx op0, rtx if_false_label, rtx if_true_label)
715 int nwords = GET_MODE_SIZE (GET_MODE (op0)) / UNITS_PER_WORD;
718 rtx drop_through_label = 0;
720 /* The fastest way of doing this comparison on almost any machine is to
721 "or" all the words and compare the result. If all have to be loaded
722 from memory and this is a very wide item, it's possible this may
723 be slower, but that's highly unlikely. */
725 part = gen_reg_rtx (word_mode);
726 emit_move_insn (part, operand_subword_force (op0, 0, GET_MODE (op0)));
727 for (i = 1; i < nwords && part != 0; i++)
728 part = expand_binop (word_mode, ior_optab, part,
729 operand_subword_force (op0, i, GET_MODE (op0)),
730 part, 1, OPTAB_WIDEN);
734 do_compare_rtx_and_jump (part, const0_rtx, EQ, 1, word_mode,
735 NULL_RTX, if_false_label, if_true_label);
740 /* If we couldn't do the "or" simply, do this with a series of compares. */
741 if (! if_false_label)
742 drop_through_label = if_false_label = gen_label_rtx ();
744 for (i = 0; i < nwords; i++)
745 do_compare_rtx_and_jump (operand_subword_force (op0, i, GET_MODE (op0)),
746 const0_rtx, EQ, 1, word_mode, NULL_RTX,
747 if_false_label, NULL_RTX);
750 emit_jump (if_true_label);
752 if (drop_through_label)
753 emit_label (drop_through_label);
756 /* Generate code for a comparison of OP0 and OP1 with rtx code CODE.
757 (including code to compute the values to be compared)
758 and set (CC0) according to the result.
759 The decision as to signed or unsigned comparison must be made by the caller.
761 We force a stack adjustment unless there are currently
762 things pushed on the stack that aren't yet used.
764 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
768 compare_from_rtx (rtx op0, rtx op1, enum rtx_code code, int unsignedp,
769 enum machine_mode mode, rtx size)
774 /* If one operand is constant, make it the second one. Only do this
775 if the other operand is not constant as well. */
777 if (swap_commutative_operands_p (op0, op1))
782 code = swap_condition (code);
787 op0 = force_not_mem (op0);
788 op1 = force_not_mem (op1);
791 do_pending_stack_adjust ();
793 ucode = unsignedp ? unsigned_condition (code) : code;
794 if ((tem = simplify_relational_operation (ucode, mode, op0, op1)) != 0)
798 /* There's no need to do this now that combine.c can eliminate lots of
799 sign extensions. This can be less efficient in certain cases on other
802 /* If this is a signed equality comparison, we can do it as an
803 unsigned comparison since zero-extension is cheaper than sign
804 extension and comparisons with zero are done as unsigned. This is
805 the case even on machines that can do fast sign extension, since
806 zero-extension is easier to combine with other operations than
807 sign-extension is. If we are comparing against a constant, we must
808 convert it to what it would look like unsigned. */
809 if ((code == EQ || code == NE) && ! unsignedp
810 && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
812 if (GET_CODE (op1) == CONST_INT
813 && (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0))) != INTVAL (op1))
814 op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0)));
819 emit_cmp_insn (op0, op1, code, size, mode, unsignedp);
822 return gen_rtx_fmt_ee (code, VOIDmode, cc0_rtx, const0_rtx);
824 return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
828 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
829 The decision as to signed or unsigned comparison must be made by the caller.
831 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
835 do_compare_rtx_and_jump (rtx op0, rtx op1, enum rtx_code code, int unsignedp,
836 enum machine_mode mode, rtx size, rtx if_false_label,
841 int dummy_true_label = 0;
843 /* Reverse the comparison if that is safe and we want to jump if it is
845 if (! if_true_label && ! FLOAT_MODE_P (mode))
847 if_true_label = if_false_label;
849 code = reverse_condition (code);
852 /* If one operand is constant, make it the second one. Only do this
853 if the other operand is not constant as well. */
855 if (swap_commutative_operands_p (op0, op1))
860 code = swap_condition (code);
865 op0 = force_not_mem (op0);
866 op1 = force_not_mem (op1);
869 do_pending_stack_adjust ();
871 ucode = unsignedp ? unsigned_condition (code) : code;
872 if ((tem = simplify_relational_operation (ucode, mode, op0, op1)) != 0)
874 if (tem == const_true_rtx)
877 emit_jump (if_true_label);
882 emit_jump (if_false_label);
888 /* There's no need to do this now that combine.c can eliminate lots of
889 sign extensions. This can be less efficient in certain cases on other
892 /* If this is a signed equality comparison, we can do it as an
893 unsigned comparison since zero-extension is cheaper than sign
894 extension and comparisons with zero are done as unsigned. This is
895 the case even on machines that can do fast sign extension, since
896 zero-extension is easier to combine with other operations than
897 sign-extension is. If we are comparing against a constant, we must
898 convert it to what it would look like unsigned. */
899 if ((code == EQ || code == NE) && ! unsignedp
900 && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
902 if (GET_CODE (op1) == CONST_INT
903 && (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0))) != INTVAL (op1))
904 op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0)));
911 dummy_true_label = 1;
912 if_true_label = gen_label_rtx ();
915 emit_cmp_and_jump_insns (op0, op1, code, size, mode, unsignedp,
919 emit_jump (if_false_label);
920 if (dummy_true_label)
921 emit_label (if_true_label);
924 /* Generate code for a comparison expression EXP (including code to compute
925 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
926 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
927 generated code will drop through.
928 SIGNED_CODE should be the rtx operation for this comparison for
929 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
931 We force a stack adjustment unless there are currently
932 things pushed on the stack that aren't yet used. */
935 do_compare_and_jump (tree exp, enum rtx_code signed_code,
936 enum rtx_code unsigned_code, rtx if_false_label,
941 enum machine_mode mode;
945 /* Don't crash if the comparison was erroneous. */
946 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
947 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
950 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
951 if (TREE_CODE (TREE_OPERAND (exp, 1)) == ERROR_MARK)
954 type = TREE_TYPE (TREE_OPERAND (exp, 0));
955 mode = TYPE_MODE (type);
956 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
957 && (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST
958 || (GET_MODE_BITSIZE (mode)
959 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp,
962 /* op0 might have been replaced by promoted constant, in which
963 case the type of second argument should be used. */
964 type = TREE_TYPE (TREE_OPERAND (exp, 1));
965 mode = TYPE_MODE (type);
967 unsignedp = TREE_UNSIGNED (type);
968 code = unsignedp ? unsigned_code : signed_code;
970 #ifdef HAVE_canonicalize_funcptr_for_compare
971 /* If function pointers need to be "canonicalized" before they can
972 be reliably compared, then canonicalize them. */
973 if (HAVE_canonicalize_funcptr_for_compare
974 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
975 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
978 rtx new_op0 = gen_reg_rtx (mode);
980 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0, op0));
984 if (HAVE_canonicalize_funcptr_for_compare
985 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
986 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
989 rtx new_op1 = gen_reg_rtx (mode);
991 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1, op1));
996 /* Do any postincrements in the expression that was tested. */
999 do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode,
1001 ? expr_size (TREE_OPERAND (exp, 0)) : NULL_RTX),
1002 if_false_label, if_true_label);