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, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 #include "basic-block.h"
41 static bool prefer_and_bit_test (enum machine_mode
, int);
42 static void do_jump_by_parts_greater (tree
, tree
, int, rtx
, rtx
, int);
43 static void do_jump_by_parts_equality (tree
, tree
, rtx
, rtx
, int);
44 static void do_compare_and_jump (tree
, tree
, enum rtx_code
, enum rtx_code
, rtx
,
47 /* Invert probability if there is any. -1 stands for unknown. */
52 return prob
== -1 ? -1 : REG_BR_PROB_BASE
- prob
;
55 /* At the start of a function, record that we have no previously-pushed
56 arguments waiting to be popped. */
59 init_pending_stack_adjust (void)
61 pending_stack_adjust
= 0;
64 /* Discard any pending stack adjustment. This avoid relying on the
65 RTL optimizers to remove useless adjustments when we know the
66 stack pointer value is dead. */
68 discard_pending_stack_adjust (void)
70 stack_pointer_delta
-= pending_stack_adjust
;
71 pending_stack_adjust
= 0;
74 /* When exiting from function, if safe, clear out any pending stack adjust
75 so the adjustment won't get done.
77 Note, if the current function calls alloca, then it must have a
78 frame pointer regardless of the value of flag_omit_frame_pointer. */
81 clear_pending_stack_adjust (void)
84 && (! flag_omit_frame_pointer
|| cfun
->calls_alloca
)
86 discard_pending_stack_adjust ();
89 /* Pop any previously-pushed arguments that have not been popped yet. */
92 do_pending_stack_adjust (void)
94 if (inhibit_defer_pop
== 0)
96 if (pending_stack_adjust
!= 0)
97 adjust_stack (GEN_INT (pending_stack_adjust
));
98 pending_stack_adjust
= 0;
102 /* Expand conditional expressions. */
104 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
105 LABEL is an rtx of code CODE_LABEL, in this function and all the
109 jumpifnot (tree exp
, rtx label
, int prob
)
111 do_jump (exp
, label
, NULL_RTX
, inv (prob
));
115 jumpifnot_1 (enum tree_code code
, tree op0
, tree op1
, rtx label
, int prob
)
117 do_jump_1 (code
, op0
, op1
, label
, NULL_RTX
, inv (prob
));
120 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
123 jumpif (tree exp
, rtx label
, int prob
)
125 do_jump (exp
, NULL_RTX
, label
, prob
);
129 jumpif_1 (enum tree_code code
, tree op0
, tree op1
, rtx label
, int prob
)
131 do_jump_1 (code
, op0
, op1
, NULL_RTX
, label
, prob
);
134 /* Used internally by prefer_and_bit_test. */
136 static GTY(()) rtx and_reg
;
137 static GTY(()) rtx and_test
;
138 static GTY(()) rtx shift_test
;
140 /* Compare the relative costs of "(X & (1 << BITNUM))" and "(X >> BITNUM) & 1",
141 where X is an arbitrary register of mode MODE. Return true if the former
145 prefer_and_bit_test (enum machine_mode mode
, int bitnum
)
151 /* Set up rtxes for the two variations. Use NULL as a placeholder
152 for the BITNUM-based constants. */
153 and_reg
= gen_rtx_REG (mode
, FIRST_PSEUDO_REGISTER
);
154 and_test
= gen_rtx_AND (mode
, and_reg
, NULL
);
155 shift_test
= gen_rtx_AND (mode
, gen_rtx_ASHIFTRT (mode
, and_reg
, NULL
),
160 /* Change the mode of the previously-created rtxes. */
161 PUT_MODE (and_reg
, mode
);
162 PUT_MODE (and_test
, mode
);
163 PUT_MODE (shift_test
, mode
);
164 PUT_MODE (XEXP (shift_test
, 0), mode
);
167 /* Fill in the integers. */
169 = immed_double_int_const (double_int_setbit (double_int_zero
, bitnum
),
171 XEXP (XEXP (shift_test
, 0), 1) = GEN_INT (bitnum
);
173 speed_p
= optimize_insn_for_speed_p ();
174 return (rtx_cost (and_test
, IF_THEN_ELSE
, 0, speed_p
)
175 <= rtx_cost (shift_test
, IF_THEN_ELSE
, 0, speed_p
));
178 /* Subroutine of do_jump, dealing with exploded comparisons of the type
179 OP0 CODE OP1 . IF_FALSE_LABEL and IF_TRUE_LABEL like in do_jump.
180 PROB is probability of jump to if_true_label, or -1 if unknown. */
183 do_jump_1 (enum tree_code code
, tree op0
, tree op1
,
184 rtx if_false_label
, rtx if_true_label
, int prob
)
186 enum machine_mode mode
;
187 rtx drop_through_label
= 0;
193 tree inner_type
= TREE_TYPE (op0
);
195 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
196 != MODE_COMPLEX_FLOAT
);
197 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
198 != MODE_COMPLEX_INT
);
200 if (integer_zerop (op1
))
201 do_jump (op0
, if_true_label
, if_false_label
, inv (prob
));
202 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
203 && !can_compare_p (EQ
, TYPE_MODE (inner_type
), ccp_jump
))
204 do_jump_by_parts_equality (op0
, op1
, if_false_label
, if_true_label
,
207 do_compare_and_jump (op0
, op1
, EQ
, EQ
, if_false_label
, if_true_label
,
214 tree inner_type
= TREE_TYPE (op0
);
216 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
217 != MODE_COMPLEX_FLOAT
);
218 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
219 != MODE_COMPLEX_INT
);
221 if (integer_zerop (op1
))
222 do_jump (op0
, if_false_label
, if_true_label
, prob
);
223 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
224 && !can_compare_p (NE
, TYPE_MODE (inner_type
), ccp_jump
))
225 do_jump_by_parts_equality (op0
, op1
, if_true_label
, if_false_label
,
228 do_compare_and_jump (op0
, op1
, NE
, NE
, if_false_label
, if_true_label
,
234 mode
= TYPE_MODE (TREE_TYPE (op0
));
235 if (GET_MODE_CLASS (mode
) == MODE_INT
236 && ! can_compare_p (LT
, mode
, ccp_jump
))
237 do_jump_by_parts_greater (op0
, op1
, 1, if_false_label
, if_true_label
,
240 do_compare_and_jump (op0
, op1
, LT
, LTU
, if_false_label
, if_true_label
,
245 mode
= TYPE_MODE (TREE_TYPE (op0
));
246 if (GET_MODE_CLASS (mode
) == MODE_INT
247 && ! can_compare_p (LE
, mode
, ccp_jump
))
248 do_jump_by_parts_greater (op0
, op1
, 0, if_true_label
, if_false_label
,
251 do_compare_and_jump (op0
, op1
, LE
, LEU
, if_false_label
, if_true_label
,
256 mode
= TYPE_MODE (TREE_TYPE (op0
));
257 if (GET_MODE_CLASS (mode
) == MODE_INT
258 && ! can_compare_p (GT
, mode
, ccp_jump
))
259 do_jump_by_parts_greater (op0
, op1
, 0, if_false_label
, if_true_label
,
262 do_compare_and_jump (op0
, op1
, GT
, GTU
, if_false_label
, if_true_label
,
267 mode
= TYPE_MODE (TREE_TYPE (op0
));
268 if (GET_MODE_CLASS (mode
) == MODE_INT
269 && ! can_compare_p (GE
, mode
, ccp_jump
))
270 do_jump_by_parts_greater (op0
, op1
, 1, if_true_label
, if_false_label
,
273 do_compare_and_jump (op0
, op1
, GE
, GEU
, if_false_label
, if_true_label
,
278 do_compare_and_jump (op0
, op1
, ORDERED
, ORDERED
,
279 if_false_label
, if_true_label
, prob
);
283 do_compare_and_jump (op0
, op1
, UNORDERED
, UNORDERED
,
284 if_false_label
, if_true_label
, prob
);
288 do_compare_and_jump (op0
, op1
, UNLT
, UNLT
, if_false_label
, if_true_label
,
293 do_compare_and_jump (op0
, op1
, UNLE
, UNLE
, if_false_label
, if_true_label
,
298 do_compare_and_jump (op0
, op1
, UNGT
, UNGT
, if_false_label
, if_true_label
,
303 do_compare_and_jump (op0
, op1
, UNGE
, UNGE
, if_false_label
, if_true_label
,
308 do_compare_and_jump (op0
, op1
, UNEQ
, UNEQ
, if_false_label
, if_true_label
,
313 do_compare_and_jump (op0
, op1
, LTGT
, LTGT
, if_false_label
, if_true_label
,
317 case TRUTH_ANDIF_EXPR
:
318 if (if_false_label
== NULL_RTX
)
320 drop_through_label
= gen_label_rtx ();
321 do_jump (op0
, drop_through_label
, NULL_RTX
, prob
);
322 do_jump (op1
, NULL_RTX
, if_true_label
, prob
);
326 do_jump (op0
, if_false_label
, NULL_RTX
, prob
);
327 do_jump (op1
, if_false_label
, if_true_label
, prob
);
331 case TRUTH_ORIF_EXPR
:
332 if (if_true_label
== NULL_RTX
)
334 drop_through_label
= gen_label_rtx ();
335 do_jump (op0
, NULL_RTX
, drop_through_label
, prob
);
336 do_jump (op1
, if_false_label
, NULL_RTX
, prob
);
340 do_jump (op0
, NULL_RTX
, if_true_label
, prob
);
341 do_jump (op1
, if_false_label
, if_true_label
, prob
);
349 if (drop_through_label
)
351 do_pending_stack_adjust ();
352 emit_label (drop_through_label
);
356 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
357 the result is zero, or IF_TRUE_LABEL if the result is one.
358 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
359 meaning fall through in that case.
361 do_jump always does any pending stack adjust except when it does not
362 actually perform a jump. An example where there is no jump
363 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
365 PROB is probability of jump to if_true_label, or -1 if unknown. */
368 do_jump (tree exp
, rtx if_false_label
, rtx if_true_label
, int prob
)
370 enum tree_code code
= TREE_CODE (exp
);
374 enum machine_mode mode
;
375 rtx drop_through_label
= 0;
383 temp
= integer_zerop (exp
) ? if_false_label
: if_true_label
;
389 /* This is not true with #pragma weak */
391 /* The address of something can never be zero. */
393 emit_jump (if_true_label
);
398 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == COMPONENT_REF
399 || TREE_CODE (TREE_OPERAND (exp
, 0)) == BIT_FIELD_REF
400 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_REF
401 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_RANGE_REF
)
404 /* If we are narrowing the operand, we have to do the compare in the
406 if ((TYPE_PRECISION (TREE_TYPE (exp
))
407 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
409 case NON_LVALUE_EXPR
:
414 /* These cannot change zero->nonzero or vice versa. */
415 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
, prob
);
419 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
,
425 rtx label1
= gen_label_rtx ();
426 if (!if_true_label
|| !if_false_label
)
428 drop_through_label
= gen_label_rtx ();
430 if_true_label
= drop_through_label
;
432 if_false_label
= drop_through_label
;
435 do_pending_stack_adjust ();
436 do_jump (TREE_OPERAND (exp
, 0), label1
, NULL_RTX
, -1);
437 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
, prob
);
439 do_jump (TREE_OPERAND (exp
, 2), if_false_label
, if_true_label
, prob
);
444 /* Lowered by gimplify.c. */
448 /* Nonzero iff operands of minus differ. */
466 case TRUTH_ANDIF_EXPR
:
467 case TRUTH_ORIF_EXPR
:
469 do_jump_1 (code
, TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
470 if_false_label
, if_true_label
, prob
);
474 /* fold_single_bit_test() converts (X & (1 << C)) into (X >> C) & 1.
475 See if the former is preferred for jump tests and restore it
477 if (integer_onep (TREE_OPERAND (exp
, 1)))
479 tree exp0
= TREE_OPERAND (exp
, 0);
480 rtx set_label
, clr_label
;
481 int setclr_prob
= prob
;
483 /* Strip narrowing integral type conversions. */
484 while (CONVERT_EXPR_P (exp0
)
485 && TREE_OPERAND (exp0
, 0) != error_mark_node
486 && TYPE_PRECISION (TREE_TYPE (exp0
))
487 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp0
, 0))))
488 exp0
= TREE_OPERAND (exp0
, 0);
490 /* "exp0 ^ 1" inverts the sense of the single bit test. */
491 if (TREE_CODE (exp0
) == BIT_XOR_EXPR
492 && integer_onep (TREE_OPERAND (exp0
, 1)))
494 exp0
= TREE_OPERAND (exp0
, 0);
495 clr_label
= if_true_label
;
496 set_label
= if_false_label
;
497 setclr_prob
= inv (prob
);
501 clr_label
= if_false_label
;
502 set_label
= if_true_label
;
505 if (TREE_CODE (exp0
) == RSHIFT_EXPR
)
507 tree arg
= TREE_OPERAND (exp0
, 0);
508 tree shift
= TREE_OPERAND (exp0
, 1);
509 tree argtype
= TREE_TYPE (arg
);
510 if (TREE_CODE (shift
) == INTEGER_CST
511 && compare_tree_int (shift
, 0) >= 0
512 && compare_tree_int (shift
, HOST_BITS_PER_WIDE_INT
) < 0
513 && prefer_and_bit_test (TYPE_MODE (argtype
),
514 TREE_INT_CST_LOW (shift
)))
516 unsigned HOST_WIDE_INT mask
517 = (unsigned HOST_WIDE_INT
) 1 << TREE_INT_CST_LOW (shift
);
518 do_jump (build2 (BIT_AND_EXPR
, argtype
, arg
,
519 build_int_cstu (argtype
, mask
)),
520 clr_label
, set_label
, setclr_prob
);
526 /* If we are AND'ing with a small constant, do this comparison in the
527 smallest type that fits. If the machine doesn't have comparisons
528 that small, it will be converted back to the wider comparison.
529 This helps if we are testing the sign bit of a narrower object.
530 combine can't do this for us because it can't know whether a
531 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
533 if (! SLOW_BYTE_ACCESS
534 && TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
535 && TYPE_PRECISION (TREE_TYPE (exp
)) <= HOST_BITS_PER_WIDE_INT
536 && (i
= tree_floor_log2 (TREE_OPERAND (exp
, 1))) >= 0
537 && (mode
= mode_for_size (i
+ 1, MODE_INT
, 0)) != BLKmode
538 && (type
= lang_hooks
.types
.type_for_mode (mode
, 1)) != 0
539 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
540 && have_insn_for (COMPARE
, TYPE_MODE (type
)))
542 do_jump (fold_convert (type
, exp
), if_false_label
, if_true_label
,
547 if (TYPE_PRECISION (TREE_TYPE (exp
)) > 1
548 || TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
)
551 /* Boolean comparisons can be compiled as TRUTH_AND_EXPR. */
554 /* High branch cost, expand as the bitwise AND of the conditions.
555 Do the same if the RHS has side effects, because we're effectively
556 turning a TRUTH_AND_EXPR into a TRUTH_ANDIF_EXPR. */
557 if (BRANCH_COST (optimize_insn_for_speed_p (),
559 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp
, 1)))
561 code
= TRUTH_ANDIF_EXPR
;
566 /* High branch cost, expand as the bitwise OR of the conditions.
567 Do the same if the RHS has side effects, because we're effectively
568 turning a TRUTH_OR_EXPR into a TRUTH_ORIF_EXPR. */
569 if (BRANCH_COST (optimize_insn_for_speed_p (), false) >= 4
570 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp
, 1)))
572 code
= TRUTH_ORIF_EXPR
;
575 /* Fall through and generate the normal code. */
578 temp
= expand_normal (exp
);
579 do_pending_stack_adjust ();
580 /* The RTL optimizers prefer comparisons against pseudos. */
581 if (GET_CODE (temp
) == SUBREG
)
583 /* Compare promoted variables in their promoted mode. */
584 if (SUBREG_PROMOTED_VAR_P (temp
)
585 && REG_P (XEXP (temp
, 0)))
586 temp
= XEXP (temp
, 0);
588 temp
= copy_to_reg (temp
);
590 do_compare_rtx_and_jump (temp
, CONST0_RTX (GET_MODE (temp
)),
591 NE
, TYPE_UNSIGNED (TREE_TYPE (exp
)),
592 GET_MODE (temp
), NULL_RTX
,
593 if_false_label
, if_true_label
, prob
);
596 if (drop_through_label
)
598 do_pending_stack_adjust ();
599 emit_label (drop_through_label
);
603 /* Compare OP0 with OP1, word at a time, in mode MODE.
604 UNSIGNEDP says to do unsigned comparison.
605 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
608 do_jump_by_parts_greater_rtx (enum machine_mode mode
, int unsignedp
, rtx op0
,
609 rtx op1
, rtx if_false_label
, rtx if_true_label
,
612 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
613 rtx drop_through_label
= 0;
614 bool drop_through_if_true
= false, drop_through_if_false
= false;
615 enum rtx_code code
= GT
;
618 if (! if_true_label
|| ! if_false_label
)
619 drop_through_label
= gen_label_rtx ();
622 if_true_label
= drop_through_label
;
623 drop_through_if_true
= true;
625 if (! if_false_label
)
627 if_false_label
= drop_through_label
;
628 drop_through_if_false
= true;
631 /* Deal with the special case 0 > x: only one comparison is necessary and
632 we reverse it to avoid jumping to the drop-through label. */
633 if (op0
== const0_rtx
&& drop_through_if_true
&& !drop_through_if_false
)
636 if_true_label
= if_false_label
;
637 if_false_label
= drop_through_label
;
638 drop_through_if_true
= false;
639 drop_through_if_false
= true;
642 /* Compare a word at a time, high order first. */
643 for (i
= 0; i
< nwords
; i
++)
645 rtx op0_word
, op1_word
;
647 if (WORDS_BIG_ENDIAN
)
649 op0_word
= operand_subword_force (op0
, i
, mode
);
650 op1_word
= operand_subword_force (op1
, i
, mode
);
654 op0_word
= operand_subword_force (op0
, nwords
- 1 - i
, mode
);
655 op1_word
= operand_subword_force (op1
, nwords
- 1 - i
, mode
);
658 /* All but high-order word must be compared as unsigned. */
659 do_compare_rtx_and_jump (op0_word
, op1_word
, code
, (unsignedp
|| i
> 0),
660 word_mode
, NULL_RTX
, NULL_RTX
, if_true_label
,
663 /* Emit only one comparison for 0. Do not emit the last cond jump. */
664 if (op0
== const0_rtx
|| i
== nwords
- 1)
667 /* Consider lower words only if these are equal. */
668 do_compare_rtx_and_jump (op0_word
, op1_word
, NE
, unsignedp
, word_mode
,
669 NULL_RTX
, NULL_RTX
, if_false_label
, inv (prob
));
672 if (!drop_through_if_false
)
673 emit_jump (if_false_label
);
674 if (drop_through_label
)
675 emit_label (drop_through_label
);
678 /* Given a comparison expression EXP for values too wide to be compared
679 with one insn, test the comparison and jump to the appropriate label.
680 The code of EXP is ignored; we always test GT if SWAP is 0,
681 and LT if SWAP is 1. */
684 do_jump_by_parts_greater (tree treeop0
, tree treeop1
, int swap
,
685 rtx if_false_label
, rtx if_true_label
, int prob
)
687 rtx op0
= expand_normal (swap
? treeop1
: treeop0
);
688 rtx op1
= expand_normal (swap
? treeop0
: treeop1
);
689 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (treeop0
));
690 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (treeop0
));
692 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
,
693 if_true_label
, prob
);
696 /* Jump according to whether OP0 is 0. We assume that OP0 has an integer
697 mode, MODE, that is too wide for the available compare insns. Either
698 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
699 to indicate drop through. */
702 do_jump_by_parts_zero_rtx (enum machine_mode mode
, rtx op0
,
703 rtx if_false_label
, rtx if_true_label
, int prob
)
705 int nwords
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
708 rtx drop_through_label
= 0;
710 /* The fastest way of doing this comparison on almost any machine is to
711 "or" all the words and compare the result. If all have to be loaded
712 from memory and this is a very wide item, it's possible this may
713 be slower, but that's highly unlikely. */
715 part
= gen_reg_rtx (word_mode
);
716 emit_move_insn (part
, operand_subword_force (op0
, 0, mode
));
717 for (i
= 1; i
< nwords
&& part
!= 0; i
++)
718 part
= expand_binop (word_mode
, ior_optab
, part
,
719 operand_subword_force (op0
, i
, mode
),
720 part
, 1, OPTAB_WIDEN
);
724 do_compare_rtx_and_jump (part
, const0_rtx
, EQ
, 1, word_mode
,
725 NULL_RTX
, if_false_label
, if_true_label
, prob
);
729 /* If we couldn't do the "or" simply, do this with a series of compares. */
730 if (! if_false_label
)
731 drop_through_label
= if_false_label
= gen_label_rtx ();
733 for (i
= 0; i
< nwords
; i
++)
734 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
735 const0_rtx
, EQ
, 1, word_mode
, NULL_RTX
,
736 if_false_label
, NULL_RTX
, prob
);
739 emit_jump (if_true_label
);
741 if (drop_through_label
)
742 emit_label (drop_through_label
);
745 /* Test for the equality of two RTX expressions OP0 and OP1 in mode MODE,
746 where MODE is an integer mode too wide to be compared with one insn.
747 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
748 to indicate drop through. */
751 do_jump_by_parts_equality_rtx (enum machine_mode mode
, rtx op0
, rtx op1
,
752 rtx if_false_label
, rtx if_true_label
, int prob
)
754 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
755 rtx drop_through_label
= 0;
758 if (op1
== const0_rtx
)
760 do_jump_by_parts_zero_rtx (mode
, op0
, if_false_label
, if_true_label
,
764 else if (op0
== const0_rtx
)
766 do_jump_by_parts_zero_rtx (mode
, op1
, if_false_label
, if_true_label
,
771 if (! if_false_label
)
772 drop_through_label
= if_false_label
= gen_label_rtx ();
774 for (i
= 0; i
< nwords
; i
++)
775 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
776 operand_subword_force (op1
, i
, mode
),
777 EQ
, 0, word_mode
, NULL_RTX
,
778 if_false_label
, NULL_RTX
, prob
);
781 emit_jump (if_true_label
);
782 if (drop_through_label
)
783 emit_label (drop_through_label
);
786 /* Given an EQ_EXPR expression EXP for values too wide to be compared
787 with one insn, test the comparison and jump to the appropriate label. */
790 do_jump_by_parts_equality (tree treeop0
, tree treeop1
, rtx if_false_label
,
791 rtx if_true_label
, int prob
)
793 rtx op0
= expand_normal (treeop0
);
794 rtx op1
= expand_normal (treeop1
);
795 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (treeop0
));
796 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_false_label
,
797 if_true_label
, prob
);
800 /* Split a comparison into two others, the second of which has the other
801 "orderedness". The first is always ORDERED or UNORDERED if MODE
802 does not honor NaNs (which means that it can be skipped in that case;
803 see do_compare_rtx_and_jump).
805 The two conditions are written in *CODE1 and *CODE2. Return true if
806 the conditions must be ANDed, false if they must be ORed. */
809 split_comparison (enum rtx_code code
, enum machine_mode mode
,
810 enum rtx_code
*code1
, enum rtx_code
*code2
)
859 /* Do not turn a trapping comparison into a non-trapping one. */
860 if (HONOR_SNANS (mode
))
878 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
879 The decision as to signed or unsigned comparison must be made by the caller.
881 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
885 do_compare_rtx_and_jump (rtx op0
, rtx op1
, enum rtx_code code
, int unsignedp
,
886 enum machine_mode mode
, rtx size
, rtx if_false_label
,
887 rtx if_true_label
, int prob
)
890 rtx dummy_label
= NULL_RTX
;
893 /* Reverse the comparison if that is safe and we want to jump if it is
894 false. Also convert to the reverse comparison if the target can
897 || ! can_compare_p (code
, mode
, ccp_jump
))
898 && (! FLOAT_MODE_P (mode
)
899 || code
== ORDERED
|| code
== UNORDERED
900 || (! HONOR_NANS (mode
) && (code
== LTGT
|| code
== UNEQ
))
901 || (! HONOR_SNANS (mode
) && (code
== EQ
|| code
== NE
))))
904 if (FLOAT_MODE_P (mode
))
905 rcode
= reverse_condition_maybe_unordered (code
);
907 rcode
= reverse_condition (code
);
909 /* Canonicalize to UNORDERED for the libcall. */
910 if (can_compare_p (rcode
, mode
, ccp_jump
)
911 || (code
== ORDERED
&& ! can_compare_p (ORDERED
, mode
, ccp_jump
)))
914 if_true_label
= if_false_label
;
915 if_false_label
= tem
;
921 /* If one operand is constant, make it the second one. Only do this
922 if the other operand is not constant as well. */
924 if (swap_commutative_operands_p (op0
, op1
))
929 code
= swap_condition (code
);
932 do_pending_stack_adjust ();
934 code
= unsignedp
? unsigned_condition (code
) : code
;
935 if (0 != (tem
= simplify_relational_operation (code
, mode
, VOIDmode
,
938 if (CONSTANT_P (tem
))
940 rtx label
= (tem
== const0_rtx
|| tem
== CONST0_RTX (mode
))
941 ? if_false_label
: if_true_label
;
947 code
= GET_CODE (tem
);
948 mode
= GET_MODE (tem
);
951 unsignedp
= (code
== GTU
|| code
== LTU
|| code
== GEU
|| code
== LEU
);
955 dummy_label
= if_true_label
= gen_label_rtx ();
957 if (GET_MODE_CLASS (mode
) == MODE_INT
958 && ! can_compare_p (code
, mode
, ccp_jump
))
963 do_jump_by_parts_greater_rtx (mode
, 1, op1
, op0
,
964 if_false_label
, if_true_label
, prob
);
968 do_jump_by_parts_greater_rtx (mode
, 1, op0
, op1
,
969 if_true_label
, if_false_label
,
974 do_jump_by_parts_greater_rtx (mode
, 1, op0
, op1
,
975 if_false_label
, if_true_label
, prob
);
979 do_jump_by_parts_greater_rtx (mode
, 1, op1
, op0
,
980 if_true_label
, if_false_label
,
985 do_jump_by_parts_greater_rtx (mode
, 0, op1
, op0
,
986 if_false_label
, if_true_label
, prob
);
990 do_jump_by_parts_greater_rtx (mode
, 0, op0
, op1
,
991 if_true_label
, if_false_label
,
996 do_jump_by_parts_greater_rtx (mode
, 0, op0
, op1
,
997 if_false_label
, if_true_label
, prob
);
1001 do_jump_by_parts_greater_rtx (mode
, 0, op1
, op0
,
1002 if_true_label
, if_false_label
,
1007 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_false_label
,
1008 if_true_label
, prob
);
1012 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_true_label
,
1013 if_false_label
, inv (prob
));
1022 if (SCALAR_FLOAT_MODE_P (mode
)
1023 && ! can_compare_p (code
, mode
, ccp_jump
)
1024 && can_compare_p (swap_condition (code
), mode
, ccp_jump
))
1027 code
= swap_condition (code
);
1033 else if (SCALAR_FLOAT_MODE_P (mode
)
1034 && ! can_compare_p (code
, mode
, ccp_jump
)
1036 /* Never split ORDERED and UNORDERED. These must be implemented. */
1037 && (code
!= ORDERED
&& code
!= UNORDERED
)
1039 /* Split a floating-point comparison if we can jump on other
1041 && (have_insn_for (COMPARE
, mode
)
1043 /* ... or if there is no libcall for it. */
1044 || code_to_optab
[code
] == NULL
))
1046 enum rtx_code first_code
;
1047 bool and_them
= split_comparison (code
, mode
, &first_code
, &code
);
1049 /* If there are no NaNs, the first comparison should always fall
1051 if (!HONOR_NANS (mode
))
1052 gcc_assert (first_code
== (and_them
? ORDERED
: UNORDERED
));
1059 /* If we only jump if true, just bypass the second jump. */
1060 if (! if_false_label
)
1063 dummy_label
= gen_label_rtx ();
1064 dest_label
= dummy_label
;
1067 dest_label
= if_false_label
;
1068 do_compare_rtx_and_jump (op0
, op1
, first_code
, unsignedp
, mode
,
1069 size
, dest_label
, NULL_RTX
, prob
);
1072 do_compare_rtx_and_jump (op0
, op1
, first_code
, unsignedp
, mode
,
1073 size
, NULL_RTX
, if_true_label
, prob
);
1077 last
= get_last_insn ();
1078 emit_cmp_and_jump_insns (op0
, op1
, code
, size
, mode
, unsignedp
,
1080 if (prob
!= -1 && profile_status
!= PROFILE_ABSENT
)
1082 for (last
= NEXT_INSN (last
);
1083 last
&& NEXT_INSN (last
);
1084 last
= NEXT_INSN (last
))
1090 || !any_condjump_p (last
))
1093 fprintf (dump_file
, "Failed to add probability note\n");
1097 gcc_assert (!find_reg_note (last
, REG_BR_PROB
, 0));
1098 add_reg_note (last
, REG_BR_PROB
, GEN_INT (prob
));
1104 emit_jump (if_false_label
);
1106 emit_label (dummy_label
);
1109 /* Generate code for a comparison expression EXP (including code to compute
1110 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
1111 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
1112 generated code will drop through.
1113 SIGNED_CODE should be the rtx operation for this comparison for
1114 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
1116 We force a stack adjustment unless there are currently
1117 things pushed on the stack that aren't yet used. */
1120 do_compare_and_jump (tree treeop0
, tree treeop1
, enum rtx_code signed_code
,
1121 enum rtx_code unsigned_code
, rtx if_false_label
,
1122 rtx if_true_label
, int prob
)
1126 enum machine_mode mode
;
1130 /* Don't crash if the comparison was erroneous. */
1131 op0
= expand_normal (treeop0
);
1132 if (TREE_CODE (treeop0
) == ERROR_MARK
)
1135 op1
= expand_normal (treeop1
);
1136 if (TREE_CODE (treeop1
) == ERROR_MARK
)
1139 type
= TREE_TYPE (treeop0
);
1140 mode
= TYPE_MODE (type
);
1141 if (TREE_CODE (treeop0
) == INTEGER_CST
1142 && (TREE_CODE (treeop1
) != INTEGER_CST
1143 || (GET_MODE_BITSIZE (mode
)
1144 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (treeop1
))))))
1146 /* op0 might have been replaced by promoted constant, in which
1147 case the type of second argument should be used. */
1148 type
= TREE_TYPE (treeop1
);
1149 mode
= TYPE_MODE (type
);
1151 unsignedp
= TYPE_UNSIGNED (type
);
1152 code
= unsignedp
? unsigned_code
: signed_code
;
1154 #ifdef HAVE_canonicalize_funcptr_for_compare
1155 /* If function pointers need to be "canonicalized" before they can
1156 be reliably compared, then canonicalize them.
1157 Only do this if *both* sides of the comparison are function pointers.
1158 If one side isn't, we want a noncanonicalized comparison. See PR
1159 middle-end/17564. */
1160 if (HAVE_canonicalize_funcptr_for_compare
1161 && TREE_CODE (TREE_TYPE (treeop0
)) == POINTER_TYPE
1162 && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop0
)))
1164 && TREE_CODE (TREE_TYPE (treeop1
)) == POINTER_TYPE
1165 && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop1
)))
1168 rtx new_op0
= gen_reg_rtx (mode
);
1169 rtx new_op1
= gen_reg_rtx (mode
);
1171 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0
, op0
));
1174 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1
, op1
));
1179 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
,
1181 ? expr_size (treeop0
) : NULL_RTX
),
1182 if_false_label
, if_true_label
, prob
);
1185 #include "gt-dojump.h"