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, 2004 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"
38 static bool prefer_and_bit_test (enum machine_mode, int);
39 static void do_jump_by_parts_greater (tree, int, rtx, rtx);
40 static void do_jump_by_parts_equality (tree, rtx, rtx);
41 static void do_compare_and_jump (tree, enum rtx_code, enum rtx_code, rtx,
44 /* At the start of a function, record that we have no previously-pushed
45 arguments waiting to be popped. */
48 init_pending_stack_adjust (void)
50 pending_stack_adjust = 0;
53 /* Discard any pending stack adjustment. This avoid relying on the
54 RTL optimizers to remove useless adjustments when we know the
55 stack pointer value is dead. */
56 void discard_pending_stack_adjust (void)
58 stack_pointer_delta -= pending_stack_adjust;
59 pending_stack_adjust = 0;
62 /* When exiting from function, if safe, clear out any pending stack adjust
63 so the adjustment won't get done.
65 Note, if the current function calls alloca, then it must have a
66 frame pointer regardless of the value of flag_omit_frame_pointer. */
69 clear_pending_stack_adjust (void)
72 && (! flag_omit_frame_pointer || current_function_calls_alloca)
74 && ! (DECL_INLINE (current_function_decl) && ! flag_no_inline))
75 discard_pending_stack_adjust ();
78 /* Pop any previously-pushed arguments that have not been popped yet. */
81 do_pending_stack_adjust (void)
83 if (inhibit_defer_pop == 0)
85 if (pending_stack_adjust != 0)
86 adjust_stack (GEN_INT (pending_stack_adjust));
87 pending_stack_adjust = 0;
91 /* Expand conditional expressions. */
93 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
94 LABEL is an rtx of code CODE_LABEL, in this function and all the
98 jumpifnot (tree exp, rtx label)
100 do_jump (exp, label, NULL_RTX);
103 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
106 jumpif (tree exp, rtx label)
108 do_jump (exp, NULL_RTX, label);
111 /* Used internally by prefer_and_bit_test. */
113 static GTY(()) rtx and_reg;
114 static GTY(()) rtx and_test;
115 static GTY(()) rtx shift_test;
117 /* Compare the relative costs of "(X & (1 << BITNUM))" and "(X >> BITNUM) & 1",
118 where X is an arbitrary register of mode MODE. Return true if the former
122 prefer_and_bit_test (enum machine_mode mode, int bitnum)
126 /* Set up rtxes for the two variations. Use NULL as a placeholder
127 for the BITNUM-based constants. */
128 and_reg = gen_rtx_REG (mode, FIRST_PSEUDO_REGISTER);
129 and_test = gen_rtx_AND (mode, and_reg, NULL);
130 shift_test = gen_rtx_AND (mode, gen_rtx_ASHIFTRT (mode, and_reg, NULL),
135 /* Change the mode of the previously-created rtxes. */
136 PUT_MODE (and_reg, mode);
137 PUT_MODE (and_test, mode);
138 PUT_MODE (shift_test, mode);
139 PUT_MODE (XEXP (shift_test, 0), mode);
142 /* Fill in the integers. */
143 XEXP (and_test, 1) = GEN_INT ((unsigned HOST_WIDE_INT) 1 << bitnum);
144 XEXP (XEXP (shift_test, 0), 1) = GEN_INT (bitnum);
146 return (rtx_cost (and_test, IF_THEN_ELSE)
147 <= rtx_cost (shift_test, IF_THEN_ELSE));
150 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
151 the result is zero, or IF_TRUE_LABEL if the result is one.
152 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
153 meaning fall through in that case.
155 do_jump always does any pending stack adjust except when it does not
156 actually perform a jump. An example where there is no jump
157 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null. */
160 do_jump (tree exp, rtx if_false_label, rtx if_true_label)
162 enum tree_code code = TREE_CODE (exp);
166 enum machine_mode mode;
174 temp = integer_zerop (exp) ? if_false_label : if_true_label;
180 /* This is not true with #pragma weak */
182 /* The address of something can never be zero. */
184 emit_jump (if_true_label);
189 if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
190 || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
191 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF
192 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_RANGE_REF)
195 /* If we are narrowing the operand, we have to do the compare in the
197 if ((TYPE_PRECISION (TREE_TYPE (exp))
198 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
200 case NON_LVALUE_EXPR:
205 /* These cannot change zero->nonzero or vice versa. */
206 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
210 /* Nonzero iff operands of minus differ. */
211 do_compare_and_jump (build2 (NE_EXPR, TREE_TYPE (exp),
212 TREE_OPERAND (exp, 0),
213 TREE_OPERAND (exp, 1)),
214 NE, NE, if_false_label, if_true_label);
218 /* fold_single_bit_test() converts (X & (1 << C)) into (X >> C) & 1.
219 See if the former is preferred for jump tests and restore it
221 if (integer_onep (TREE_OPERAND (exp, 1)))
223 tree exp0 = TREE_OPERAND (exp, 0);
224 rtx set_label, clr_label;
226 /* Strip narrowing integral type conversions. */
227 while ((TREE_CODE (exp0) == NOP_EXPR
228 || TREE_CODE (exp0) == CONVERT_EXPR
229 || TREE_CODE (exp0) == NON_LVALUE_EXPR)
230 && TREE_OPERAND (exp0, 0) != error_mark_node
231 && TYPE_PRECISION (TREE_TYPE (exp0))
232 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp0, 0))))
233 exp0 = TREE_OPERAND (exp0, 0);
235 /* "exp0 ^ 1" inverts the sense of the single bit test. */
236 if (TREE_CODE (exp0) == BIT_XOR_EXPR
237 && integer_onep (TREE_OPERAND (exp0, 1)))
239 exp0 = TREE_OPERAND (exp0, 0);
240 clr_label = if_true_label;
241 set_label = if_false_label;
245 clr_label = if_false_label;
246 set_label = if_true_label;
249 if (TREE_CODE (exp0) == RSHIFT_EXPR)
251 tree arg = TREE_OPERAND (exp0, 0);
252 tree shift = TREE_OPERAND (exp0, 1);
253 tree argtype = TREE_TYPE (arg);
254 if (TREE_CODE (shift) == INTEGER_CST
255 && compare_tree_int (shift, 0) >= 0
256 && compare_tree_int (shift, HOST_BITS_PER_WIDE_INT) < 0
257 && prefer_and_bit_test (TYPE_MODE (argtype),
258 TREE_INT_CST_LOW (shift)))
260 HOST_WIDE_INT mask = (HOST_WIDE_INT) 1
261 << TREE_INT_CST_LOW (shift);
262 do_jump (build2 (BIT_AND_EXPR, argtype, arg,
263 build_int_cst_type (argtype, mask)),
264 clr_label, set_label);
270 /* If we are AND'ing with a small constant, do this comparison in the
271 smallest type that fits. If the machine doesn't have comparisons
272 that small, it will be converted back to the wider comparison.
273 This helps if we are testing the sign bit of a narrower object.
274 combine can't do this for us because it can't know whether a
275 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
277 if (! SLOW_BYTE_ACCESS
278 && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
279 && TYPE_PRECISION (TREE_TYPE (exp)) <= HOST_BITS_PER_WIDE_INT
280 && (i = tree_floor_log2 (TREE_OPERAND (exp, 1))) >= 0
281 && (mode = mode_for_size (i + 1, MODE_INT, 0)) != BLKmode
282 && (type = lang_hooks.types.type_for_mode (mode, 1)) != 0
283 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
284 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
285 != CODE_FOR_nothing))
287 do_jump (convert (type, exp), if_false_label, if_true_label);
293 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
296 case TRUTH_ANDIF_EXPR:
297 case TRUTH_ORIF_EXPR:
300 /* Lowered by gimplify.c. */
306 case ARRAY_RANGE_REF:
308 HOST_WIDE_INT bitsize, bitpos;
310 enum machine_mode mode;
315 /* Get description of this reference. We don't actually care
316 about the underlying object here. */
317 get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode,
318 &unsignedp, &volatilep);
320 type = lang_hooks.types.type_for_size (bitsize, unsignedp);
321 if (! SLOW_BYTE_ACCESS
322 && type != 0 && bitsize >= 0
323 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
324 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
325 != CODE_FOR_nothing))
327 do_jump (convert (type, exp), if_false_label, if_true_label);
335 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
337 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type))
338 != MODE_COMPLEX_FLOAT);
339 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type))
340 != MODE_COMPLEX_INT);
342 if (integer_zerop (TREE_OPERAND (exp, 1)))
343 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
344 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
345 && !can_compare_p (EQ, TYPE_MODE (inner_type), ccp_jump))
346 do_jump_by_parts_equality (exp, if_false_label, if_true_label);
348 do_compare_and_jump (exp, EQ, EQ, if_false_label, if_true_label);
354 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
356 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type))
357 != MODE_COMPLEX_FLOAT);
358 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type))
359 != MODE_COMPLEX_INT);
361 if (integer_zerop (TREE_OPERAND (exp, 1)))
362 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
363 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
364 && !can_compare_p (NE, TYPE_MODE (inner_type), ccp_jump))
365 do_jump_by_parts_equality (exp, if_true_label, if_false_label);
367 do_compare_and_jump (exp, NE, NE, if_false_label, if_true_label);
372 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
373 if (GET_MODE_CLASS (mode) == MODE_INT
374 && ! can_compare_p (LT, mode, ccp_jump))
375 do_jump_by_parts_greater (exp, 1, if_false_label, if_true_label);
377 do_compare_and_jump (exp, LT, LTU, if_false_label, if_true_label);
381 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
382 if (GET_MODE_CLASS (mode) == MODE_INT
383 && ! can_compare_p (LE, mode, ccp_jump))
384 do_jump_by_parts_greater (exp, 0, if_true_label, if_false_label);
386 do_compare_and_jump (exp, LE, LEU, if_false_label, if_true_label);
390 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
391 if (GET_MODE_CLASS (mode) == MODE_INT
392 && ! can_compare_p (GT, mode, ccp_jump))
393 do_jump_by_parts_greater (exp, 0, if_false_label, if_true_label);
395 do_compare_and_jump (exp, GT, GTU, if_false_label, if_true_label);
399 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
400 if (GET_MODE_CLASS (mode) == MODE_INT
401 && ! can_compare_p (GE, mode, ccp_jump))
402 do_jump_by_parts_greater (exp, 1, if_true_label, if_false_label);
404 do_compare_and_jump (exp, GE, GEU, if_false_label, if_true_label);
410 enum rtx_code cmp, rcmp;
413 if (code == UNORDERED_EXPR)
414 cmp = UNORDERED, rcmp = ORDERED;
416 cmp = ORDERED, rcmp = UNORDERED;
417 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
420 if (! can_compare_p (cmp, mode, ccp_jump)
421 && (can_compare_p (rcmp, mode, ccp_jump)
422 /* If the target doesn't provide either UNORDERED or ORDERED
423 comparisons, canonicalize on UNORDERED for the library. */
424 || rcmp == UNORDERED))
428 do_compare_and_jump (exp, cmp, cmp, if_false_label, if_true_label);
430 do_compare_and_jump (exp, rcmp, rcmp, if_true_label, if_false_label);
435 enum rtx_code rcode1;
436 enum tree_code tcode1, tcode2;
440 tcode1 = UNORDERED_EXPR;
445 tcode1 = UNORDERED_EXPR;
450 tcode1 = UNORDERED_EXPR;
455 tcode1 = UNORDERED_EXPR;
460 tcode1 = UNORDERED_EXPR;
464 /* It is ok for LTGT_EXPR to trap when the result is unordered,
465 so expand to (a < b) || (a > b). */
472 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
473 if (can_compare_p (rcode1, mode, ccp_jump))
474 do_compare_and_jump (exp, rcode1, rcode1, if_false_label,
478 tree op0 = save_expr (TREE_OPERAND (exp, 0));
479 tree op1 = save_expr (TREE_OPERAND (exp, 1));
481 rtx drop_through_label = 0;
483 /* If the target doesn't support combined unordered
484 compares, decompose into two comparisons. */
485 if (if_true_label == 0)
486 drop_through_label = if_true_label = gen_label_rtx ();
488 cmp0 = fold (build2 (tcode1, TREE_TYPE (exp), op0, op1));
489 cmp1 = fold (build2 (tcode2, TREE_TYPE (exp), op0, op1));
490 do_jump (cmp0, 0, if_true_label);
491 do_jump (cmp1, if_false_label, if_true_label);
493 if (drop_through_label)
495 do_pending_stack_adjust ();
496 emit_label (drop_through_label);
503 __builtin_expect (<test>, 0) and
504 __builtin_expect (<test>, 1)
506 We need to do this here, so that <test> is not converted to a SCC
507 operation on machines that use condition code registers and COMPARE
508 like the PowerPC, and then the jump is done based on whether the SCC
509 operation produced a 1 or 0. */
511 /* Check for a built-in function. */
513 tree fndecl = get_callee_fndecl (exp);
514 tree arglist = TREE_OPERAND (exp, 1);
517 && DECL_BUILT_IN (fndecl)
518 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_EXPECT
519 && arglist != NULL_TREE
520 && TREE_CHAIN (arglist) != NULL_TREE)
522 rtx seq = expand_builtin_expect_jump (exp, if_false_label,
532 /* Fall through and generate the normal code. */
536 temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
537 do_pending_stack_adjust ();
539 if (GET_CODE (temp) == CONST_INT
540 || (GET_CODE (temp) == CONST_DOUBLE && GET_MODE (temp) == VOIDmode)
541 || GET_CODE (temp) == LABEL_REF)
543 rtx target = temp == const0_rtx ? if_false_label : if_true_label;
547 else if (GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
548 && ! can_compare_p (NE, GET_MODE (temp), ccp_jump))
549 /* Note swapping the labels gives us not-equal. */
550 do_jump_by_parts_equality_rtx (temp, if_true_label, if_false_label);
553 gcc_assert (GET_MODE (temp) != VOIDmode);
555 /* The RTL optimizers prefer comparisons against pseudos. */
556 if (GET_CODE (temp) == SUBREG)
558 /* Compare promoted variables in their promoted mode. */
559 if (SUBREG_PROMOTED_VAR_P (temp)
560 && REG_P (XEXP (temp, 0)))
561 temp = XEXP (temp, 0);
563 temp = copy_to_reg (temp);
565 do_compare_rtx_and_jump (temp, CONST0_RTX (GET_MODE (temp)),
566 NE, TYPE_UNSIGNED (TREE_TYPE (exp)),
567 GET_MODE (temp), NULL_RTX,
568 if_false_label, if_true_label);
573 /* Given a comparison expression EXP for values too wide to be compared
574 with one insn, test the comparison and jump to the appropriate label.
575 The code of EXP is ignored; we always test GT if SWAP is 0,
576 and LT if SWAP is 1. */
579 do_jump_by_parts_greater (tree exp, int swap, rtx if_false_label,
582 rtx op0 = expand_expr (TREE_OPERAND (exp, swap), NULL_RTX, VOIDmode, 0);
583 rtx op1 = expand_expr (TREE_OPERAND (exp, !swap), NULL_RTX, VOIDmode, 0);
584 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
585 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
587 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label,
591 /* Compare OP0 with OP1, word at a time, in mode MODE.
592 UNSIGNEDP says to do unsigned comparison.
593 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
596 do_jump_by_parts_greater_rtx (enum machine_mode mode, int unsignedp, rtx op0,
597 rtx op1, rtx if_false_label, rtx if_true_label)
599 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
600 rtx drop_through_label = 0;
603 if (! if_true_label || ! if_false_label)
604 drop_through_label = gen_label_rtx ();
606 if_true_label = drop_through_label;
607 if (! if_false_label)
608 if_false_label = drop_through_label;
610 /* Compare a word at a time, high order first. */
611 for (i = 0; i < nwords; i++)
613 rtx op0_word, op1_word;
615 if (WORDS_BIG_ENDIAN)
617 op0_word = operand_subword_force (op0, i, mode);
618 op1_word = operand_subword_force (op1, i, mode);
622 op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
623 op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
626 /* All but high-order word must be compared as unsigned. */
627 do_compare_rtx_and_jump (op0_word, op1_word, GT,
628 (unsignedp || i > 0), word_mode, NULL_RTX,
629 NULL_RTX, if_true_label);
631 /* Consider lower words only if these are equal. */
632 do_compare_rtx_and_jump (op0_word, op1_word, NE, unsignedp, word_mode,
633 NULL_RTX, NULL_RTX, if_false_label);
637 emit_jump (if_false_label);
638 if (drop_through_label)
639 emit_label (drop_through_label);
642 /* Given an EQ_EXPR expression EXP for values too wide to be compared
643 with one insn, test the comparison and jump to the appropriate label. */
646 do_jump_by_parts_equality (tree exp, rtx if_false_label, rtx if_true_label)
648 rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
649 rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
650 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
651 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
653 rtx drop_through_label = 0;
655 if (! if_false_label)
656 drop_through_label = if_false_label = gen_label_rtx ();
658 for (i = 0; i < nwords; i++)
659 do_compare_rtx_and_jump (operand_subword_force (op0, i, mode),
660 operand_subword_force (op1, i, mode),
661 EQ, TYPE_UNSIGNED (TREE_TYPE (exp)),
662 word_mode, NULL_RTX, if_false_label, NULL_RTX);
665 emit_jump (if_true_label);
666 if (drop_through_label)
667 emit_label (drop_through_label);
670 /* Jump according to whether OP0 is 0.
671 We assume that OP0 has an integer mode that is too wide
672 for the available compare insns. */
675 do_jump_by_parts_equality_rtx (rtx op0, rtx if_false_label, rtx if_true_label)
677 int nwords = GET_MODE_SIZE (GET_MODE (op0)) / UNITS_PER_WORD;
680 rtx drop_through_label = 0;
682 /* The fastest way of doing this comparison on almost any machine is to
683 "or" all the words and compare the result. If all have to be loaded
684 from memory and this is a very wide item, it's possible this may
685 be slower, but that's highly unlikely. */
687 part = gen_reg_rtx (word_mode);
688 emit_move_insn (part, operand_subword_force (op0, 0, GET_MODE (op0)));
689 for (i = 1; i < nwords && part != 0; i++)
690 part = expand_binop (word_mode, ior_optab, part,
691 operand_subword_force (op0, i, GET_MODE (op0)),
692 part, 1, OPTAB_WIDEN);
696 do_compare_rtx_and_jump (part, const0_rtx, EQ, 1, word_mode,
697 NULL_RTX, if_false_label, if_true_label);
702 /* If we couldn't do the "or" simply, do this with a series of compares. */
703 if (! if_false_label)
704 drop_through_label = if_false_label = gen_label_rtx ();
706 for (i = 0; i < nwords; i++)
707 do_compare_rtx_and_jump (operand_subword_force (op0, i, GET_MODE (op0)),
708 const0_rtx, EQ, 1, word_mode, NULL_RTX,
709 if_false_label, NULL_RTX);
712 emit_jump (if_true_label);
714 if (drop_through_label)
715 emit_label (drop_through_label);
718 /* Generate code for a comparison of OP0 and OP1 with rtx code CODE.
719 MODE is the machine mode of the comparison, not of the result.
720 (including code to compute the values to be compared) and set CC0
721 according to the result. The decision as to signed or unsigned
722 comparison must be made by the caller.
724 We force a stack adjustment unless there are currently
725 things pushed on the stack that aren't yet used.
727 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
731 compare_from_rtx (rtx op0, rtx op1, enum rtx_code code, int unsignedp,
732 enum machine_mode mode, rtx size)
736 /* If one operand is constant, make it the second one. Only do this
737 if the other operand is not constant as well. */
739 if (swap_commutative_operands_p (op0, op1))
744 code = swap_condition (code);
749 op0 = force_not_mem (op0);
750 op1 = force_not_mem (op1);
753 do_pending_stack_adjust ();
755 code = unsignedp ? unsigned_condition (code) : code;
756 tem = simplify_relational_operation (code, VOIDmode, mode, op0, op1);
759 if (CONSTANT_P (tem))
762 if (COMPARISON_P (tem))
764 code = GET_CODE (tem);
767 mode = GET_MODE (op0);
768 unsignedp = (code == GTU || code == LTU
769 || code == GEU || code == LEU);
773 emit_cmp_insn (op0, op1, code, size, mode, unsignedp);
776 return gen_rtx_fmt_ee (code, VOIDmode, cc0_rtx, const0_rtx);
778 return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
782 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
783 The decision as to signed or unsigned comparison must be made by the caller.
785 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
789 do_compare_rtx_and_jump (rtx op0, rtx op1, enum rtx_code code, int unsignedp,
790 enum machine_mode mode, rtx size, rtx if_false_label,
794 int dummy_true_label = 0;
796 /* Reverse the comparison if that is safe and we want to jump if it is
798 if (! if_true_label && ! FLOAT_MODE_P (mode))
800 if_true_label = if_false_label;
802 code = reverse_condition (code);
805 /* If one operand is constant, make it the second one. Only do this
806 if the other operand is not constant as well. */
808 if (swap_commutative_operands_p (op0, op1))
813 code = swap_condition (code);
818 op0 = force_not_mem (op0);
819 op1 = force_not_mem (op1);
822 do_pending_stack_adjust ();
824 code = unsignedp ? unsigned_condition (code) : code;
825 if (0 != (tem = simplify_relational_operation (code, mode, VOIDmode,
828 if (CONSTANT_P (tem))
830 rtx label = (tem == const0_rtx || tem == CONST0_RTX (mode))
831 ? if_false_label : if_true_label;
837 code = GET_CODE (tem);
838 mode = GET_MODE (tem);
841 unsignedp = (code == GTU || code == LTU || code == GEU || code == LEU);
846 dummy_true_label = 1;
847 if_true_label = gen_label_rtx ();
850 emit_cmp_and_jump_insns (op0, op1, code, size, mode, unsignedp,
854 emit_jump (if_false_label);
855 if (dummy_true_label)
856 emit_label (if_true_label);
859 /* Generate code for a comparison expression EXP (including code to compute
860 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
861 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
862 generated code will drop through.
863 SIGNED_CODE should be the rtx operation for this comparison for
864 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
866 We force a stack adjustment unless there are currently
867 things pushed on the stack that aren't yet used. */
870 do_compare_and_jump (tree exp, enum rtx_code signed_code,
871 enum rtx_code unsigned_code, rtx if_false_label,
876 enum machine_mode mode;
880 /* Don't crash if the comparison was erroneous. */
881 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
882 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
885 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
886 if (TREE_CODE (TREE_OPERAND (exp, 1)) == ERROR_MARK)
889 type = TREE_TYPE (TREE_OPERAND (exp, 0));
890 mode = TYPE_MODE (type);
891 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
892 && (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST
893 || (GET_MODE_BITSIZE (mode)
894 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp,
897 /* op0 might have been replaced by promoted constant, in which
898 case the type of second argument should be used. */
899 type = TREE_TYPE (TREE_OPERAND (exp, 1));
900 mode = TYPE_MODE (type);
902 unsignedp = TYPE_UNSIGNED (type);
903 code = unsignedp ? unsigned_code : signed_code;
905 #ifdef HAVE_canonicalize_funcptr_for_compare
906 /* If function pointers need to be "canonicalized" before they can
907 be reliably compared, then canonicalize them.
908 Only do this if *both* sides of the comparison are function pointers.
909 If one side isn't, we want a noncanonicalized comparison. See PR
911 if (HAVE_canonicalize_funcptr_for_compare
912 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
913 && TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
915 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
916 && TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
919 rtx new_op0 = gen_reg_rtx (mode);
920 rtx new_op1 = gen_reg_rtx (mode);
922 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0, op0));
925 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1, op1));
930 do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode,
932 ? expr_size (TREE_OPERAND (exp, 0)) : NULL_RTX),
933 if_false_label, if_true_label);
936 #include "gt-dojump.h"