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 && ! flag_inline_functions
)
76 discard_pending_stack_adjust ();
79 /* Pop any previously-pushed arguments that have not been popped yet. */
82 do_pending_stack_adjust (void)
84 if (inhibit_defer_pop
== 0)
86 if (pending_stack_adjust
!= 0)
87 adjust_stack (GEN_INT (pending_stack_adjust
));
88 pending_stack_adjust
= 0;
92 /* Expand conditional expressions. */
94 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
95 LABEL is an rtx of code CODE_LABEL, in this function and all the
99 jumpifnot (tree exp
, rtx label
)
101 do_jump (exp
, label
, NULL_RTX
);
104 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
107 jumpif (tree exp
, rtx label
)
109 do_jump (exp
, NULL_RTX
, label
);
112 /* Used internally by prefer_and_bit_test. */
114 static GTY(()) rtx and_reg
;
115 static GTY(()) rtx and_test
;
116 static GTY(()) rtx shift_test
;
118 /* Compare the relative costs of "(X & (1 << BITNUM))" and "(X >> BITNUM) & 1",
119 where X is an arbitrary register of mode MODE. Return true if the former
123 prefer_and_bit_test (enum machine_mode mode
, int bitnum
)
127 /* Set up rtxes for the two variations. Use NULL as a placeholder
128 for the BITNUM-based constants. */
129 and_reg
= gen_rtx_REG (mode
, FIRST_PSEUDO_REGISTER
);
130 and_test
= gen_rtx_AND (mode
, and_reg
, NULL
);
131 shift_test
= gen_rtx_AND (mode
, gen_rtx_ASHIFTRT (mode
, and_reg
, NULL
),
136 /* Change the mode of the previously-created rtxes. */
137 PUT_MODE (and_reg
, mode
);
138 PUT_MODE (and_test
, mode
);
139 PUT_MODE (shift_test
, mode
);
140 PUT_MODE (XEXP (shift_test
, 0), mode
);
143 /* Fill in the integers. */
144 XEXP (and_test
, 1) = GEN_INT ((unsigned HOST_WIDE_INT
) 1 << bitnum
);
145 XEXP (XEXP (shift_test
, 0), 1) = GEN_INT (bitnum
);
147 return (rtx_cost (and_test
, IF_THEN_ELSE
)
148 <= rtx_cost (shift_test
, IF_THEN_ELSE
));
151 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
152 the result is zero, or IF_TRUE_LABEL if the result is one.
153 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
154 meaning fall through in that case.
156 do_jump always does any pending stack adjust except when it does not
157 actually perform a jump. An example where there is no jump
158 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null. */
161 do_jump (tree exp
, rtx if_false_label
, rtx if_true_label
)
163 enum tree_code code
= TREE_CODE (exp
);
167 enum machine_mode mode
;
175 temp
= integer_zerop (exp
) ? if_false_label
: if_true_label
;
181 /* This is not true with #pragma weak */
183 /* The address of something can never be zero. */
185 emit_jump (if_true_label
);
190 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == COMPONENT_REF
191 || TREE_CODE (TREE_OPERAND (exp
, 0)) == BIT_FIELD_REF
192 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_REF
193 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_RANGE_REF
)
196 /* If we are narrowing the operand, we have to do the compare in the
198 if ((TYPE_PRECISION (TREE_TYPE (exp
))
199 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
201 case NON_LVALUE_EXPR
:
206 /* These cannot change zero->nonzero or vice versa. */
207 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
211 /* Nonzero iff operands of minus differ. */
212 do_compare_and_jump (build2 (NE_EXPR
, TREE_TYPE (exp
),
213 TREE_OPERAND (exp
, 0),
214 TREE_OPERAND (exp
, 1)),
215 NE
, NE
, if_false_label
, if_true_label
);
219 /* fold_single_bit_test() converts (X & (1 << C)) into (X >> C) & 1.
220 See if the former is preferred for jump tests and restore it
222 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == RSHIFT_EXPR
223 && integer_onep (TREE_OPERAND (exp
, 1)))
225 tree arg
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
226 tree shift
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 1);
227 tree one
= TREE_OPERAND (exp
, 1);
228 tree argtype
= TREE_TYPE (arg
);
229 if (TREE_CODE (shift
) == INTEGER_CST
230 && compare_tree_int (shift
, 0) > 0
231 && compare_tree_int (shift
, HOST_BITS_PER_WIDE_INT
) < 0
232 && prefer_and_bit_test (TYPE_MODE (argtype
),
233 TREE_INT_CST_LOW (shift
)))
235 do_jump (build2 (BIT_AND_EXPR
, argtype
, arg
,
236 fold (build2 (LSHIFT_EXPR
, argtype
,
238 if_false_label
, if_true_label
);
243 /* If we are AND'ing with a small constant, do this comparison in the
244 smallest type that fits. If the machine doesn't have comparisons
245 that small, it will be converted back to the wider comparison.
246 This helps if we are testing the sign bit of a narrower object.
247 combine can't do this for us because it can't know whether a
248 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
250 if (! SLOW_BYTE_ACCESS
251 && TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
252 && TYPE_PRECISION (TREE_TYPE (exp
)) <= HOST_BITS_PER_WIDE_INT
253 && (i
= tree_floor_log2 (TREE_OPERAND (exp
, 1))) >= 0
254 && (mode
= mode_for_size (i
+ 1, MODE_INT
, 0)) != BLKmode
255 && (type
= lang_hooks
.types
.type_for_mode (mode
, 1)) != 0
256 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
257 && (cmp_optab
->handlers
[(int) TYPE_MODE (type
)].insn_code
258 != CODE_FOR_nothing
))
260 do_jump (convert (type
, exp
), if_false_label
, if_true_label
);
266 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
269 case TRUTH_ANDIF_EXPR
:
270 case TRUTH_ORIF_EXPR
:
273 /* Lowered by gimplify.c. */
279 case ARRAY_RANGE_REF
:
281 HOST_WIDE_INT bitsize
, bitpos
;
283 enum machine_mode mode
;
288 /* Get description of this reference. We don't actually care
289 about the underlying object here. */
290 get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode
,
291 &unsignedp
, &volatilep
);
293 type
= lang_hooks
.types
.type_for_size (bitsize
, unsignedp
);
294 if (! SLOW_BYTE_ACCESS
295 && type
!= 0 && bitsize
>= 0
296 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
297 && (cmp_optab
->handlers
[(int) TYPE_MODE (type
)].insn_code
298 != CODE_FOR_nothing
))
300 do_jump (convert (type
, exp
), if_false_label
, if_true_label
);
308 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
310 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
311 != MODE_COMPLEX_FLOAT
);
312 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
313 != MODE_COMPLEX_INT
);
315 if (integer_zerop (TREE_OPERAND (exp
, 1)))
316 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
317 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
318 && !can_compare_p (EQ
, TYPE_MODE (inner_type
), ccp_jump
))
319 do_jump_by_parts_equality (exp
, if_false_label
, if_true_label
);
321 do_compare_and_jump (exp
, EQ
, EQ
, if_false_label
, if_true_label
);
327 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
329 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
330 != MODE_COMPLEX_FLOAT
);
331 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
332 != MODE_COMPLEX_INT
);
334 if (integer_zerop (TREE_OPERAND (exp
, 1)))
335 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
336 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
337 && !can_compare_p (NE
, TYPE_MODE (inner_type
), ccp_jump
))
338 do_jump_by_parts_equality (exp
, if_true_label
, if_false_label
);
340 do_compare_and_jump (exp
, NE
, NE
, if_false_label
, if_true_label
);
345 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
346 if (GET_MODE_CLASS (mode
) == MODE_INT
347 && ! can_compare_p (LT
, mode
, ccp_jump
))
348 do_jump_by_parts_greater (exp
, 1, if_false_label
, if_true_label
);
350 do_compare_and_jump (exp
, LT
, LTU
, if_false_label
, if_true_label
);
354 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
355 if (GET_MODE_CLASS (mode
) == MODE_INT
356 && ! can_compare_p (LE
, mode
, ccp_jump
))
357 do_jump_by_parts_greater (exp
, 0, if_true_label
, if_false_label
);
359 do_compare_and_jump (exp
, LE
, LEU
, if_false_label
, if_true_label
);
363 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
364 if (GET_MODE_CLASS (mode
) == MODE_INT
365 && ! can_compare_p (GT
, mode
, ccp_jump
))
366 do_jump_by_parts_greater (exp
, 0, if_false_label
, if_true_label
);
368 do_compare_and_jump (exp
, GT
, GTU
, 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 (GE
, mode
, ccp_jump
))
375 do_jump_by_parts_greater (exp
, 1, if_true_label
, if_false_label
);
377 do_compare_and_jump (exp
, GE
, GEU
, if_false_label
, if_true_label
);
383 enum rtx_code cmp
, rcmp
;
386 if (code
== UNORDERED_EXPR
)
387 cmp
= UNORDERED
, rcmp
= ORDERED
;
389 cmp
= ORDERED
, rcmp
= UNORDERED
;
390 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
393 if (! can_compare_p (cmp
, mode
, ccp_jump
)
394 && (can_compare_p (rcmp
, mode
, ccp_jump
)
395 /* If the target doesn't provide either UNORDERED or ORDERED
396 comparisons, canonicalize on UNORDERED for the library. */
397 || rcmp
== UNORDERED
))
401 do_compare_and_jump (exp
, cmp
, cmp
, if_false_label
, if_true_label
);
403 do_compare_and_jump (exp
, rcmp
, rcmp
, if_true_label
, if_false_label
);
408 enum rtx_code rcode1
;
409 enum tree_code tcode1
, tcode2
;
413 tcode1
= UNORDERED_EXPR
;
418 tcode1
= UNORDERED_EXPR
;
423 tcode1
= UNORDERED_EXPR
;
428 tcode1
= UNORDERED_EXPR
;
433 tcode1
= UNORDERED_EXPR
;
437 /* It is ok for LTGT_EXPR to trap when the result is unordered,
438 so expand to (a < b) || (a > b). */
445 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
446 if (can_compare_p (rcode1
, mode
, ccp_jump
))
447 do_compare_and_jump (exp
, rcode1
, rcode1
, if_false_label
,
451 tree op0
= save_expr (TREE_OPERAND (exp
, 0));
452 tree op1
= save_expr (TREE_OPERAND (exp
, 1));
454 rtx drop_through_label
= 0;
456 /* If the target doesn't support combined unordered
457 compares, decompose into two comparisons. */
458 if (if_true_label
== 0)
459 drop_through_label
= if_true_label
= gen_label_rtx ();
461 cmp0
= fold (build2 (tcode1
, TREE_TYPE (exp
), op0
, op1
));
462 cmp1
= fold (build2 (tcode2
, TREE_TYPE (exp
), op0
, op1
));
463 do_jump (cmp0
, 0, if_true_label
);
464 do_jump (cmp1
, if_false_label
, if_true_label
);
466 if (drop_through_label
)
468 do_pending_stack_adjust ();
469 emit_label (drop_through_label
);
476 __builtin_expect (<test>, 0) and
477 __builtin_expect (<test>, 1)
479 We need to do this here, so that <test> is not converted to a SCC
480 operation on machines that use condition code registers and COMPARE
481 like the PowerPC, and then the jump is done based on whether the SCC
482 operation produced a 1 or 0. */
484 /* Check for a built-in function. */
486 tree fndecl
= get_callee_fndecl (exp
);
487 tree arglist
= TREE_OPERAND (exp
, 1);
490 && DECL_BUILT_IN (fndecl
)
491 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_EXPECT
492 && arglist
!= NULL_TREE
493 && TREE_CHAIN (arglist
) != NULL_TREE
)
495 rtx seq
= expand_builtin_expect_jump (exp
, if_false_label
,
505 /* Fall through and generate the normal code. */
509 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, 0);
510 do_pending_stack_adjust ();
512 if (GET_CODE (temp
) == CONST_INT
513 || (GET_CODE (temp
) == CONST_DOUBLE
&& GET_MODE (temp
) == VOIDmode
)
514 || GET_CODE (temp
) == LABEL_REF
)
516 rtx target
= temp
== const0_rtx
? if_false_label
: if_true_label
;
520 else if (GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
521 && ! can_compare_p (NE
, GET_MODE (temp
), ccp_jump
))
522 /* Note swapping the labels gives us not-equal. */
523 do_jump_by_parts_equality_rtx (temp
, if_true_label
, if_false_label
);
526 gcc_assert (GET_MODE (temp
) != VOIDmode
);
528 /* The RTL optimizers prefer comparisons against pseudos. */
529 if (GET_CODE (temp
) == SUBREG
)
531 /* Compare promoted variables in their promoted mode. */
532 if (SUBREG_PROMOTED_VAR_P (temp
)
533 && REG_P (XEXP (temp
, 0)))
534 temp
= XEXP (temp
, 0);
536 temp
= copy_to_reg (temp
);
538 do_compare_rtx_and_jump (temp
, CONST0_RTX (GET_MODE (temp
)),
539 NE
, TYPE_UNSIGNED (TREE_TYPE (exp
)),
540 GET_MODE (temp
), NULL_RTX
,
541 if_false_label
, if_true_label
);
546 /* Given a comparison expression EXP for values too wide to be compared
547 with one insn, test the comparison and jump to the appropriate label.
548 The code of EXP is ignored; we always test GT if SWAP is 0,
549 and LT if SWAP is 1. */
552 do_jump_by_parts_greater (tree exp
, int swap
, rtx if_false_label
,
555 rtx op0
= expand_expr (TREE_OPERAND (exp
, swap
), NULL_RTX
, VOIDmode
, 0);
556 rtx op1
= expand_expr (TREE_OPERAND (exp
, !swap
), NULL_RTX
, VOIDmode
, 0);
557 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
558 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0)));
560 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
,
564 /* Compare OP0 with OP1, word at a time, in mode MODE.
565 UNSIGNEDP says to do unsigned comparison.
566 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
569 do_jump_by_parts_greater_rtx (enum machine_mode mode
, int unsignedp
, rtx op0
,
570 rtx op1
, rtx if_false_label
, rtx if_true_label
)
572 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
573 rtx drop_through_label
= 0;
576 if (! if_true_label
|| ! if_false_label
)
577 drop_through_label
= gen_label_rtx ();
579 if_true_label
= drop_through_label
;
580 if (! if_false_label
)
581 if_false_label
= drop_through_label
;
583 /* Compare a word at a time, high order first. */
584 for (i
= 0; i
< nwords
; i
++)
586 rtx op0_word
, op1_word
;
588 if (WORDS_BIG_ENDIAN
)
590 op0_word
= operand_subword_force (op0
, i
, mode
);
591 op1_word
= operand_subword_force (op1
, i
, mode
);
595 op0_word
= operand_subword_force (op0
, nwords
- 1 - i
, mode
);
596 op1_word
= operand_subword_force (op1
, nwords
- 1 - i
, mode
);
599 /* All but high-order word must be compared as unsigned. */
600 do_compare_rtx_and_jump (op0_word
, op1_word
, GT
,
601 (unsignedp
|| i
> 0), word_mode
, NULL_RTX
,
602 NULL_RTX
, if_true_label
);
604 /* Consider lower words only if these are equal. */
605 do_compare_rtx_and_jump (op0_word
, op1_word
, NE
, unsignedp
, word_mode
,
606 NULL_RTX
, NULL_RTX
, if_false_label
);
610 emit_jump (if_false_label
);
611 if (drop_through_label
)
612 emit_label (drop_through_label
);
615 /* Given an EQ_EXPR expression EXP for values too wide to be compared
616 with one insn, test the comparison and jump to the appropriate label. */
619 do_jump_by_parts_equality (tree exp
, rtx if_false_label
, rtx if_true_label
)
621 rtx op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
622 rtx op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
, VOIDmode
, 0);
623 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
624 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
626 rtx drop_through_label
= 0;
628 if (! if_false_label
)
629 drop_through_label
= if_false_label
= gen_label_rtx ();
631 for (i
= 0; i
< nwords
; i
++)
632 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
633 operand_subword_force (op1
, i
, mode
),
634 EQ
, TYPE_UNSIGNED (TREE_TYPE (exp
)),
635 word_mode
, NULL_RTX
, if_false_label
, NULL_RTX
);
638 emit_jump (if_true_label
);
639 if (drop_through_label
)
640 emit_label (drop_through_label
);
643 /* Jump according to whether OP0 is 0.
644 We assume that OP0 has an integer mode that is too wide
645 for the available compare insns. */
648 do_jump_by_parts_equality_rtx (rtx op0
, rtx if_false_label
, rtx if_true_label
)
650 int nwords
= GET_MODE_SIZE (GET_MODE (op0
)) / UNITS_PER_WORD
;
653 rtx drop_through_label
= 0;
655 /* The fastest way of doing this comparison on almost any machine is to
656 "or" all the words and compare the result. If all have to be loaded
657 from memory and this is a very wide item, it's possible this may
658 be slower, but that's highly unlikely. */
660 part
= gen_reg_rtx (word_mode
);
661 emit_move_insn (part
, operand_subword_force (op0
, 0, GET_MODE (op0
)));
662 for (i
= 1; i
< nwords
&& part
!= 0; i
++)
663 part
= expand_binop (word_mode
, ior_optab
, part
,
664 operand_subword_force (op0
, i
, GET_MODE (op0
)),
665 part
, 1, OPTAB_WIDEN
);
669 do_compare_rtx_and_jump (part
, const0_rtx
, EQ
, 1, word_mode
,
670 NULL_RTX
, if_false_label
, if_true_label
);
675 /* If we couldn't do the "or" simply, do this with a series of compares. */
676 if (! if_false_label
)
677 drop_through_label
= if_false_label
= gen_label_rtx ();
679 for (i
= 0; i
< nwords
; i
++)
680 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, GET_MODE (op0
)),
681 const0_rtx
, EQ
, 1, word_mode
, NULL_RTX
,
682 if_false_label
, NULL_RTX
);
685 emit_jump (if_true_label
);
687 if (drop_through_label
)
688 emit_label (drop_through_label
);
691 /* Generate code for a comparison of OP0 and OP1 with rtx code CODE.
692 (including code to compute the values to be compared)
693 and set (CC0) according to the result.
694 The decision as to signed or unsigned comparison must be made by the caller.
696 We force a stack adjustment unless there are currently
697 things pushed on the stack that aren't yet used.
699 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
703 compare_from_rtx (rtx op0
, rtx op1
, enum rtx_code code
, int unsignedp
,
704 enum machine_mode mode
, rtx size
)
708 /* If one operand is constant, make it the second one. Only do this
709 if the other operand is not constant as well. */
711 if (swap_commutative_operands_p (op0
, op1
))
716 code
= swap_condition (code
);
721 op0
= force_not_mem (op0
);
722 op1
= force_not_mem (op1
);
725 do_pending_stack_adjust ();
727 code
= unsignedp
? unsigned_condition (code
) : code
;
728 if (0 != (tem
= simplify_relational_operation (code
, mode
, VOIDmode
,
731 if (CONSTANT_P (tem
))
734 code
= GET_CODE (tem
);
735 mode
= GET_MODE (tem
);
738 unsignedp
= (code
== GTU
|| code
== LTU
|| code
== GEU
|| code
== LEU
);
741 emit_cmp_insn (op0
, op1
, code
, size
, mode
, unsignedp
);
744 return gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
746 return gen_rtx_fmt_ee (code
, VOIDmode
, op0
, op1
);
750 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
751 The decision as to signed or unsigned comparison must be made by the caller.
753 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
757 do_compare_rtx_and_jump (rtx op0
, rtx op1
, enum rtx_code code
, int unsignedp
,
758 enum machine_mode mode
, rtx size
, rtx if_false_label
,
762 int dummy_true_label
= 0;
764 /* Reverse the comparison if that is safe and we want to jump if it is
766 if (! if_true_label
&& ! FLOAT_MODE_P (mode
))
768 if_true_label
= if_false_label
;
770 code
= reverse_condition (code
);
773 /* If one operand is constant, make it the second one. Only do this
774 if the other operand is not constant as well. */
776 if (swap_commutative_operands_p (op0
, op1
))
781 code
= swap_condition (code
);
786 op0
= force_not_mem (op0
);
787 op1
= force_not_mem (op1
);
790 do_pending_stack_adjust ();
792 code
= unsignedp
? unsigned_condition (code
) : code
;
793 if (0 != (tem
= simplify_relational_operation (code
, mode
, VOIDmode
,
796 if (CONSTANT_P (tem
))
798 rtx label
= (tem
== const0_rtx
|| tem
== CONST0_RTX (mode
))
799 ? if_false_label
: if_true_label
;
805 code
= GET_CODE (tem
);
806 mode
= GET_MODE (tem
);
809 unsignedp
= (code
== GTU
|| code
== LTU
|| code
== GEU
|| code
== LEU
);
814 dummy_true_label
= 1;
815 if_true_label
= gen_label_rtx ();
818 emit_cmp_and_jump_insns (op0
, op1
, code
, size
, mode
, unsignedp
,
822 emit_jump (if_false_label
);
823 if (dummy_true_label
)
824 emit_label (if_true_label
);
827 /* Generate code for a comparison expression EXP (including code to compute
828 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
829 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
830 generated code will drop through.
831 SIGNED_CODE should be the rtx operation for this comparison for
832 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
834 We force a stack adjustment unless there are currently
835 things pushed on the stack that aren't yet used. */
838 do_compare_and_jump (tree exp
, enum rtx_code signed_code
,
839 enum rtx_code unsigned_code
, rtx if_false_label
,
844 enum machine_mode mode
;
848 /* Don't crash if the comparison was erroneous. */
849 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
850 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ERROR_MARK
)
853 op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
, VOIDmode
, 0);
854 if (TREE_CODE (TREE_OPERAND (exp
, 1)) == ERROR_MARK
)
857 type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
858 mode
= TYPE_MODE (type
);
859 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == INTEGER_CST
860 && (TREE_CODE (TREE_OPERAND (exp
, 1)) != INTEGER_CST
861 || (GET_MODE_BITSIZE (mode
)
862 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
,
865 /* op0 might have been replaced by promoted constant, in which
866 case the type of second argument should be used. */
867 type
= TREE_TYPE (TREE_OPERAND (exp
, 1));
868 mode
= TYPE_MODE (type
);
870 unsignedp
= TYPE_UNSIGNED (type
);
871 code
= unsignedp
? unsigned_code
: signed_code
;
873 #ifdef HAVE_canonicalize_funcptr_for_compare
874 /* If function pointers need to be "canonicalized" before they can
875 be reliably compared, then canonicalize them. */
876 if (HAVE_canonicalize_funcptr_for_compare
877 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == POINTER_TYPE
878 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))))
881 rtx new_op0
= gen_reg_rtx (mode
);
883 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0
, op0
));
887 if (HAVE_canonicalize_funcptr_for_compare
888 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 1))) == POINTER_TYPE
889 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 1))))
892 rtx new_op1
= gen_reg_rtx (mode
);
894 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1
, op1
));
899 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
,
901 ? expr_size (TREE_OPERAND (exp
, 0)) : NULL_RTX
),
902 if_false_label
, if_true_label
);
905 #include "gt-dojump.h"