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
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"
39 static bool prefer_and_bit_test (enum machine_mode
, int);
40 static void do_jump_by_parts_greater (tree
, tree
, int, rtx
, rtx
);
41 static void do_jump_by_parts_equality (tree
, tree
, rtx
, rtx
);
42 static void do_compare_and_jump (tree
, tree
, enum rtx_code
, enum rtx_code
, rtx
,
45 /* At the start of a function, record that we have no previously-pushed
46 arguments waiting to be popped. */
49 init_pending_stack_adjust (void)
51 pending_stack_adjust
= 0;
54 /* Discard any pending stack adjustment. This avoid relying on the
55 RTL optimizers to remove useless adjustments when we know the
56 stack pointer value is dead. */
58 discard_pending_stack_adjust (void)
60 stack_pointer_delta
-= pending_stack_adjust
;
61 pending_stack_adjust
= 0;
64 /* When exiting from function, if safe, clear out any pending stack adjust
65 so the adjustment won't get done.
67 Note, if the current function calls alloca, then it must have a
68 frame pointer regardless of the value of flag_omit_frame_pointer. */
71 clear_pending_stack_adjust (void)
74 && (! flag_omit_frame_pointer
|| cfun
->calls_alloca
)
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
);
105 jumpifnot_1 (enum tree_code code
, tree op0
, tree op1
, rtx label
)
107 do_jump_1 (code
, op0
, op1
, label
, NULL_RTX
);
110 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
113 jumpif (tree exp
, rtx label
)
115 do_jump (exp
, NULL_RTX
, label
);
119 jumpif_1 (enum tree_code code
, tree op0
, tree op1
, rtx label
)
121 do_jump_1 (code
, op0
, op1
, NULL_RTX
, label
);
124 /* Used internally by prefer_and_bit_test. */
126 static GTY(()) rtx and_reg
;
127 static GTY(()) rtx and_test
;
128 static GTY(()) rtx shift_test
;
130 /* Compare the relative costs of "(X & (1 << BITNUM))" and "(X >> BITNUM) & 1",
131 where X is an arbitrary register of mode MODE. Return true if the former
135 prefer_and_bit_test (enum machine_mode mode
, int bitnum
)
139 /* Set up rtxes for the two variations. Use NULL as a placeholder
140 for the BITNUM-based constants. */
141 and_reg
= gen_rtx_REG (mode
, FIRST_PSEUDO_REGISTER
);
142 and_test
= gen_rtx_AND (mode
, and_reg
, NULL
);
143 shift_test
= gen_rtx_AND (mode
, gen_rtx_ASHIFTRT (mode
, and_reg
, NULL
),
148 /* Change the mode of the previously-created rtxes. */
149 PUT_MODE (and_reg
, mode
);
150 PUT_MODE (and_test
, mode
);
151 PUT_MODE (shift_test
, mode
);
152 PUT_MODE (XEXP (shift_test
, 0), mode
);
155 /* Fill in the integers. */
157 = immed_double_const ((unsigned HOST_WIDE_INT
) 1 << bitnum
, 0, mode
);
158 XEXP (XEXP (shift_test
, 0), 1) = GEN_INT (bitnum
);
160 return (rtx_cost (and_test
, IF_THEN_ELSE
, optimize_insn_for_speed_p ())
161 <= rtx_cost (shift_test
, IF_THEN_ELSE
, optimize_insn_for_speed_p ()));
164 /* Subroutine of do_jump, dealing with exploded comparisons of the type
165 OP0 CODE OP1 . IF_FALSE_LABEL and IF_TRUE_LABEL like in do_jump. */
168 do_jump_1 (enum tree_code code
, tree op0
, tree op1
,
169 rtx if_false_label
, rtx if_true_label
)
171 enum machine_mode mode
;
172 rtx drop_through_label
= 0;
178 tree inner_type
= TREE_TYPE (op0
);
180 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
181 != MODE_COMPLEX_FLOAT
);
182 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
183 != MODE_COMPLEX_INT
);
185 if (integer_zerop (op1
))
186 do_jump (op0
, if_true_label
, if_false_label
);
187 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
188 && !can_compare_p (EQ
, TYPE_MODE (inner_type
), ccp_jump
))
189 do_jump_by_parts_equality (op0
, op1
, if_false_label
, if_true_label
);
191 do_compare_and_jump (op0
, op1
, EQ
, EQ
, if_false_label
, if_true_label
);
197 tree inner_type
= TREE_TYPE (op0
);
199 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
200 != MODE_COMPLEX_FLOAT
);
201 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
202 != MODE_COMPLEX_INT
);
204 if (integer_zerop (op1
))
205 do_jump (op0
, if_false_label
, if_true_label
);
206 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
207 && !can_compare_p (NE
, TYPE_MODE (inner_type
), ccp_jump
))
208 do_jump_by_parts_equality (op0
, op1
, if_true_label
, if_false_label
);
210 do_compare_and_jump (op0
, op1
, NE
, NE
, if_false_label
, if_true_label
);
215 mode
= TYPE_MODE (TREE_TYPE (op0
));
216 if (GET_MODE_CLASS (mode
) == MODE_INT
217 && ! can_compare_p (LT
, mode
, ccp_jump
))
218 do_jump_by_parts_greater (op0
, op1
, 1, if_false_label
, if_true_label
);
220 do_compare_and_jump (op0
, op1
, LT
, LTU
, if_false_label
, if_true_label
);
224 mode
= TYPE_MODE (TREE_TYPE (op0
));
225 if (GET_MODE_CLASS (mode
) == MODE_INT
226 && ! can_compare_p (LE
, mode
, ccp_jump
))
227 do_jump_by_parts_greater (op0
, op1
, 0, if_true_label
, if_false_label
);
229 do_compare_and_jump (op0
, op1
, LE
, LEU
, if_false_label
, if_true_label
);
233 mode
= TYPE_MODE (TREE_TYPE (op0
));
234 if (GET_MODE_CLASS (mode
) == MODE_INT
235 && ! can_compare_p (GT
, mode
, ccp_jump
))
236 do_jump_by_parts_greater (op0
, op1
, 0, if_false_label
, if_true_label
);
238 do_compare_and_jump (op0
, op1
, GT
, GTU
, if_false_label
, if_true_label
);
242 mode
= TYPE_MODE (TREE_TYPE (op0
));
243 if (GET_MODE_CLASS (mode
) == MODE_INT
244 && ! can_compare_p (GE
, mode
, ccp_jump
))
245 do_jump_by_parts_greater (op0
, op1
, 1, if_true_label
, if_false_label
);
247 do_compare_and_jump (op0
, op1
, GE
, GEU
, if_false_label
, if_true_label
);
251 do_compare_and_jump (op0
, op1
, ORDERED
, ORDERED
,
252 if_false_label
, if_true_label
);
256 do_compare_and_jump (op0
, op1
, UNORDERED
, UNORDERED
,
257 if_false_label
, if_true_label
);
261 do_compare_and_jump (op0
, op1
, UNLT
, UNLT
, if_false_label
, if_true_label
);
265 do_compare_and_jump (op0
, op1
, UNLE
, UNLE
, if_false_label
, if_true_label
);
269 do_compare_and_jump (op0
, op1
, UNGT
, UNGT
, if_false_label
, if_true_label
);
273 do_compare_and_jump (op0
, op1
, UNGE
, UNGE
, if_false_label
, if_true_label
);
277 do_compare_and_jump (op0
, op1
, UNEQ
, UNEQ
, if_false_label
, if_true_label
);
281 do_compare_and_jump (op0
, op1
, LTGT
, LTGT
, if_false_label
, if_true_label
);
284 case TRUTH_ANDIF_EXPR
:
285 if (if_false_label
== NULL_RTX
)
287 drop_through_label
= gen_label_rtx ();
288 do_jump (op0
, drop_through_label
, NULL_RTX
);
289 do_jump (op1
, NULL_RTX
, if_true_label
);
293 do_jump (op0
, if_false_label
, NULL_RTX
);
294 do_jump (op1
, if_false_label
, if_true_label
);
298 case TRUTH_ORIF_EXPR
:
299 if (if_true_label
== NULL_RTX
)
301 drop_through_label
= gen_label_rtx ();
302 do_jump (op0
, NULL_RTX
, drop_through_label
);
303 do_jump (op1
, if_false_label
, NULL_RTX
);
307 do_jump (op0
, NULL_RTX
, if_true_label
);
308 do_jump (op1
, if_false_label
, if_true_label
);
316 if (drop_through_label
)
318 do_pending_stack_adjust ();
319 emit_label (drop_through_label
);
323 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
324 the result is zero, or IF_TRUE_LABEL if the result is one.
325 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
326 meaning fall through in that case.
328 do_jump always does any pending stack adjust except when it does not
329 actually perform a jump. An example where there is no jump
330 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null. */
333 do_jump (tree exp
, rtx if_false_label
, rtx if_true_label
)
335 enum tree_code code
= TREE_CODE (exp
);
339 enum machine_mode mode
;
340 rtx drop_through_label
= 0;
348 temp
= integer_zerop (exp
) ? if_false_label
: if_true_label
;
354 /* This is not true with #pragma weak */
356 /* The address of something can never be zero. */
358 emit_jump (if_true_label
);
363 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == COMPONENT_REF
364 || TREE_CODE (TREE_OPERAND (exp
, 0)) == BIT_FIELD_REF
365 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_REF
366 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_RANGE_REF
)
369 /* If we are narrowing the operand, we have to do the compare in the
371 if ((TYPE_PRECISION (TREE_TYPE (exp
))
372 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
374 case NON_LVALUE_EXPR
:
379 /* These cannot change zero->nonzero or vice versa. */
380 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
384 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
389 rtx label1
= gen_label_rtx ();
390 if (!if_true_label
|| !if_false_label
)
392 drop_through_label
= gen_label_rtx ();
394 if_true_label
= drop_through_label
;
396 if_false_label
= drop_through_label
;
399 do_pending_stack_adjust ();
400 do_jump (TREE_OPERAND (exp
, 0), label1
, NULL_RTX
);
401 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
403 do_jump (TREE_OPERAND (exp
, 2), if_false_label
, if_true_label
);
408 /* Lowered by gimplify.c. */
414 case ARRAY_RANGE_REF
:
416 HOST_WIDE_INT bitsize
, bitpos
;
418 enum machine_mode mode
;
423 /* Get description of this reference. We don't actually care
424 about the underlying object here. */
425 get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode
,
426 &unsignedp
, &volatilep
, false);
428 type
= lang_hooks
.types
.type_for_size (bitsize
, unsignedp
);
429 if (! SLOW_BYTE_ACCESS
430 && type
!= 0 && bitsize
>= 0
431 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
432 && have_insn_for (COMPARE
, TYPE_MODE (type
)))
434 do_jump (fold_convert (type
, exp
), if_false_label
, if_true_label
);
441 /* Nonzero iff operands of minus differ. */
459 case TRUTH_ANDIF_EXPR
:
460 case TRUTH_ORIF_EXPR
:
461 do_jump_1 (code
, TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
462 if_false_label
, if_true_label
);
466 /* fold_single_bit_test() converts (X & (1 << C)) into (X >> C) & 1.
467 See if the former is preferred for jump tests and restore it
469 if (integer_onep (TREE_OPERAND (exp
, 1)))
471 tree exp0
= TREE_OPERAND (exp
, 0);
472 rtx set_label
, clr_label
;
474 /* Strip narrowing integral type conversions. */
475 while (CONVERT_EXPR_P (exp0
)
476 && TREE_OPERAND (exp0
, 0) != error_mark_node
477 && TYPE_PRECISION (TREE_TYPE (exp0
))
478 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp0
, 0))))
479 exp0
= TREE_OPERAND (exp0
, 0);
481 /* "exp0 ^ 1" inverts the sense of the single bit test. */
482 if (TREE_CODE (exp0
) == BIT_XOR_EXPR
483 && integer_onep (TREE_OPERAND (exp0
, 1)))
485 exp0
= TREE_OPERAND (exp0
, 0);
486 clr_label
= if_true_label
;
487 set_label
= if_false_label
;
491 clr_label
= if_false_label
;
492 set_label
= if_true_label
;
495 if (TREE_CODE (exp0
) == RSHIFT_EXPR
)
497 tree arg
= TREE_OPERAND (exp0
, 0);
498 tree shift
= TREE_OPERAND (exp0
, 1);
499 tree argtype
= TREE_TYPE (arg
);
500 if (TREE_CODE (shift
) == INTEGER_CST
501 && compare_tree_int (shift
, 0) >= 0
502 && compare_tree_int (shift
, HOST_BITS_PER_WIDE_INT
) < 0
503 && prefer_and_bit_test (TYPE_MODE (argtype
),
504 TREE_INT_CST_LOW (shift
)))
506 unsigned HOST_WIDE_INT mask
507 = (unsigned HOST_WIDE_INT
) 1 << TREE_INT_CST_LOW (shift
);
508 do_jump (build2 (BIT_AND_EXPR
, argtype
, arg
,
509 build_int_cst_wide_type (argtype
, mask
, 0)),
510 clr_label
, set_label
);
516 /* If we are AND'ing with a small constant, do this comparison in the
517 smallest type that fits. If the machine doesn't have comparisons
518 that small, it will be converted back to the wider comparison.
519 This helps if we are testing the sign bit of a narrower object.
520 combine can't do this for us because it can't know whether a
521 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
523 if (! SLOW_BYTE_ACCESS
524 && TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
525 && TYPE_PRECISION (TREE_TYPE (exp
)) <= HOST_BITS_PER_WIDE_INT
526 && (i
= tree_floor_log2 (TREE_OPERAND (exp
, 1))) >= 0
527 && (mode
= mode_for_size (i
+ 1, MODE_INT
, 0)) != BLKmode
528 && (type
= lang_hooks
.types
.type_for_mode (mode
, 1)) != 0
529 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
530 && have_insn_for (COMPARE
, TYPE_MODE (type
)))
532 do_jump (fold_convert (type
, exp
), if_false_label
, if_true_label
);
536 if (TYPE_PRECISION (TREE_TYPE (exp
)) > 1
537 || TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
)
540 /* Boolean comparisons can be compiled as TRUTH_AND_EXPR. */
543 /* High branch cost, expand as the bitwise AND of the conditions.
544 Do the same if the RHS has side effects, because we're effectively
545 turning a TRUTH_AND_EXPR into a TRUTH_ANDIF_EXPR. */
546 if (BRANCH_COST (optimize_insn_for_speed_p (),
548 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp
, 1)))
553 /* High branch cost, expand as the bitwise OR of the conditions.
554 Do the same if the RHS has side effects, because we're effectively
555 turning a TRUTH_OR_EXPR into a TRUTH_ORIF_EXPR. */
556 if (BRANCH_COST (optimize_insn_for_speed_p (), false)>= 4
557 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp
, 1)))
560 /* Fall through and generate the normal code. */
563 temp
= expand_normal (exp
);
564 do_pending_stack_adjust ();
565 /* The RTL optimizers prefer comparisons against pseudos. */
566 if (GET_CODE (temp
) == SUBREG
)
568 /* Compare promoted variables in their promoted mode. */
569 if (SUBREG_PROMOTED_VAR_P (temp
)
570 && REG_P (XEXP (temp
, 0)))
571 temp
= XEXP (temp
, 0);
573 temp
= copy_to_reg (temp
);
575 do_compare_rtx_and_jump (temp
, CONST0_RTX (GET_MODE (temp
)),
576 NE
, TYPE_UNSIGNED (TREE_TYPE (exp
)),
577 GET_MODE (temp
), NULL_RTX
,
578 if_false_label
, if_true_label
);
581 if (drop_through_label
)
583 do_pending_stack_adjust ();
584 emit_label (drop_through_label
);
588 /* Compare OP0 with OP1, word at a time, in mode MODE.
589 UNSIGNEDP says to do unsigned comparison.
590 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
593 do_jump_by_parts_greater_rtx (enum machine_mode mode
, int unsignedp
, rtx op0
,
594 rtx op1
, rtx if_false_label
, rtx if_true_label
)
596 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
597 rtx drop_through_label
= 0;
600 if (! if_true_label
|| ! if_false_label
)
601 drop_through_label
= gen_label_rtx ();
603 if_true_label
= drop_through_label
;
604 if (! if_false_label
)
605 if_false_label
= drop_through_label
;
607 /* Compare a word at a time, high order first. */
608 for (i
= 0; i
< nwords
; i
++)
610 rtx op0_word
, op1_word
;
612 if (WORDS_BIG_ENDIAN
)
614 op0_word
= operand_subword_force (op0
, i
, mode
);
615 op1_word
= operand_subword_force (op1
, i
, mode
);
619 op0_word
= operand_subword_force (op0
, nwords
- 1 - i
, mode
);
620 op1_word
= operand_subword_force (op1
, nwords
- 1 - i
, mode
);
623 /* All but high-order word must be compared as unsigned. */
624 do_compare_rtx_and_jump (op0_word
, op1_word
, GT
,
625 (unsignedp
|| i
> 0), word_mode
, NULL_RTX
,
626 NULL_RTX
, if_true_label
);
628 /* Consider lower words only if these are equal. */
629 do_compare_rtx_and_jump (op0_word
, op1_word
, NE
, unsignedp
, word_mode
,
630 NULL_RTX
, NULL_RTX
, if_false_label
);
634 emit_jump (if_false_label
);
635 if (drop_through_label
)
636 emit_label (drop_through_label
);
639 /* Given a comparison expression EXP for values too wide to be compared
640 with one insn, test the comparison and jump to the appropriate label.
641 The code of EXP is ignored; we always test GT if SWAP is 0,
642 and LT if SWAP is 1. */
645 do_jump_by_parts_greater (tree treeop0
, tree treeop1
, int swap
,
646 rtx if_false_label
, rtx if_true_label
)
648 rtx op0
= expand_normal (swap
? treeop1
: treeop0
);
649 rtx op1
= expand_normal (swap
? treeop0
: treeop1
);
650 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (treeop0
));
651 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (treeop0
));
653 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
,
657 /* Jump according to whether OP0 is 0. We assume that OP0 has an integer
658 mode, MODE, that is too wide for the available compare insns. Either
659 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
660 to indicate drop through. */
663 do_jump_by_parts_zero_rtx (enum machine_mode mode
, rtx op0
,
664 rtx if_false_label
, rtx if_true_label
)
666 int nwords
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
669 rtx drop_through_label
= 0;
671 /* The fastest way of doing this comparison on almost any machine is to
672 "or" all the words and compare the result. If all have to be loaded
673 from memory and this is a very wide item, it's possible this may
674 be slower, but that's highly unlikely. */
676 part
= gen_reg_rtx (word_mode
);
677 emit_move_insn (part
, operand_subword_force (op0
, 0, mode
));
678 for (i
= 1; i
< nwords
&& part
!= 0; i
++)
679 part
= expand_binop (word_mode
, ior_optab
, part
,
680 operand_subword_force (op0
, i
, mode
),
681 part
, 1, OPTAB_WIDEN
);
685 do_compare_rtx_and_jump (part
, const0_rtx
, EQ
, 1, word_mode
,
686 NULL_RTX
, if_false_label
, if_true_label
);
691 /* If we couldn't do the "or" simply, do this with a series of compares. */
692 if (! if_false_label
)
693 drop_through_label
= if_false_label
= gen_label_rtx ();
695 for (i
= 0; i
< nwords
; i
++)
696 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
697 const0_rtx
, EQ
, 1, word_mode
, NULL_RTX
,
698 if_false_label
, NULL_RTX
);
701 emit_jump (if_true_label
);
703 if (drop_through_label
)
704 emit_label (drop_through_label
);
707 /* Test for the equality of two RTX expressions OP0 and OP1 in mode MODE,
708 where MODE is an integer mode too wide to be compared with one insn.
709 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
710 to indicate drop through. */
713 do_jump_by_parts_equality_rtx (enum machine_mode mode
, rtx op0
, rtx op1
,
714 rtx if_false_label
, rtx if_true_label
)
716 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
717 rtx drop_through_label
= 0;
720 if (op1
== const0_rtx
)
722 do_jump_by_parts_zero_rtx (mode
, op0
, if_false_label
, if_true_label
);
725 else if (op0
== const0_rtx
)
727 do_jump_by_parts_zero_rtx (mode
, op1
, if_false_label
, if_true_label
);
731 if (! if_false_label
)
732 drop_through_label
= if_false_label
= gen_label_rtx ();
734 for (i
= 0; i
< nwords
; i
++)
735 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
736 operand_subword_force (op1
, i
, mode
),
737 EQ
, 0, word_mode
, NULL_RTX
,
738 if_false_label
, NULL_RTX
);
741 emit_jump (if_true_label
);
742 if (drop_through_label
)
743 emit_label (drop_through_label
);
746 /* Given an EQ_EXPR expression EXP for values too wide to be compared
747 with one insn, test the comparison and jump to the appropriate label. */
750 do_jump_by_parts_equality (tree treeop0
, tree treeop1
, rtx if_false_label
,
753 rtx op0
= expand_normal (treeop0
);
754 rtx op1
= expand_normal (treeop1
);
755 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (treeop0
));
756 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_false_label
,
760 /* Split a comparison into two others, the second of which has the other
761 "orderedness". The first is always ORDERED or UNORDERED if MODE
762 does not honor NaNs (which means that it can be skipped in that case;
763 see do_compare_rtx_and_jump).
765 The two conditions are written in *CODE1 and *CODE2. Return true if
766 the conditions must be ANDed, false if they must be ORed. */
769 split_comparison (enum rtx_code code
, enum machine_mode mode
,
770 enum rtx_code
*code1
, enum rtx_code
*code2
)
819 /* Do not turn a trapping comparison into a non-trapping one. */
820 if (HONOR_SNANS (mode
))
838 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
839 The decision as to signed or unsigned comparison must be made by the caller.
841 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
845 do_compare_rtx_and_jump (rtx op0
, rtx op1
, enum rtx_code code
, int unsignedp
,
846 enum machine_mode mode
, rtx size
, rtx if_false_label
,
850 rtx dummy_label
= NULL_RTX
;
852 /* Reverse the comparison if that is safe and we want to jump if it is
853 false. Also convert to the reverse comparison if the target can
856 || ! can_compare_p (code
, mode
, ccp_jump
))
857 && (! FLOAT_MODE_P (mode
)
858 || code
== ORDERED
|| code
== UNORDERED
859 || (! HONOR_NANS (mode
) && (code
== LTGT
|| code
== UNEQ
))
860 || (! HONOR_SNANS (mode
) && (code
== EQ
|| code
== NE
))))
863 if (FLOAT_MODE_P (mode
))
864 rcode
= reverse_condition_maybe_unordered (code
);
866 rcode
= reverse_condition (code
);
868 /* Canonicalize to UNORDERED for the libcall. */
869 if (can_compare_p (rcode
, mode
, ccp_jump
)
870 || (code
== ORDERED
&& ! can_compare_p (ORDERED
, mode
, ccp_jump
)))
873 if_true_label
= if_false_label
;
874 if_false_label
= tem
;
879 /* If one operand is constant, make it the second one. Only do this
880 if the other operand is not constant as well. */
882 if (swap_commutative_operands_p (op0
, op1
))
887 code
= swap_condition (code
);
890 do_pending_stack_adjust ();
892 code
= unsignedp
? unsigned_condition (code
) : code
;
893 if (0 != (tem
= simplify_relational_operation (code
, mode
, VOIDmode
,
896 if (CONSTANT_P (tem
))
898 rtx label
= (tem
== const0_rtx
|| tem
== CONST0_RTX (mode
))
899 ? if_false_label
: if_true_label
;
905 code
= GET_CODE (tem
);
906 mode
= GET_MODE (tem
);
909 unsignedp
= (code
== GTU
|| code
== LTU
|| code
== GEU
|| code
== LEU
);
913 dummy_label
= if_true_label
= gen_label_rtx ();
915 if (GET_MODE_CLASS (mode
) == MODE_INT
916 && ! can_compare_p (code
, mode
, ccp_jump
))
921 do_jump_by_parts_greater_rtx (mode
, 1, op1
, op0
,
922 if_false_label
, if_true_label
);
926 do_jump_by_parts_greater_rtx (mode
, 1, op0
, op1
,
927 if_true_label
, if_false_label
);
931 do_jump_by_parts_greater_rtx (mode
, 1, op0
, op1
,
932 if_false_label
, if_true_label
);
936 do_jump_by_parts_greater_rtx (mode
, 1, op1
, op0
,
937 if_true_label
, if_false_label
);
941 do_jump_by_parts_greater_rtx (mode
, 0, op1
, op0
,
942 if_false_label
, if_true_label
);
946 do_jump_by_parts_greater_rtx (mode
, 0, op0
, op1
,
947 if_true_label
, if_false_label
);
951 do_jump_by_parts_greater_rtx (mode
, 0, op0
, op1
,
952 if_false_label
, if_true_label
);
956 do_jump_by_parts_greater_rtx (mode
, 0, op1
, op0
,
957 if_true_label
, if_false_label
);
961 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_false_label
,
966 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_true_label
,
976 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
977 && ! can_compare_p (code
, mode
, ccp_jump
)
978 && can_compare_p (swap_condition (code
), mode
, ccp_jump
))
981 code
= swap_condition (code
);
987 else if (GET_MODE_CLASS (mode
) == MODE_FLOAT
988 && ! can_compare_p (code
, mode
, ccp_jump
)
990 /* Never split ORDERED and UNORDERED. These must be implemented. */
991 && (code
!= ORDERED
&& code
!= UNORDERED
)
993 /* Split a floating-point comparison if we can jump on other
995 && (have_insn_for (COMPARE
, mode
)
997 /* ... or if there is no libcall for it. */
998 || code_to_optab
[code
] == NULL
))
1000 enum rtx_code first_code
;
1001 bool and_them
= split_comparison (code
, mode
, &first_code
, &code
);
1003 /* If there are no NaNs, the first comparison should always fall
1005 if (!HONOR_NANS (mode
))
1006 gcc_assert (first_code
== (and_them
? ORDERED
: UNORDERED
));
1013 /* If we only jump if true, just bypass the second jump. */
1014 if (! if_false_label
)
1017 dummy_label
= gen_label_rtx ();
1018 dest_label
= dummy_label
;
1021 dest_label
= if_false_label
;
1022 do_compare_rtx_and_jump (op0
, op1
, first_code
, unsignedp
, mode
,
1023 size
, dest_label
, NULL_RTX
);
1026 do_compare_rtx_and_jump (op0
, op1
, first_code
, unsignedp
, mode
,
1027 size
, NULL_RTX
, if_true_label
);
1031 emit_cmp_and_jump_insns (op0
, op1
, code
, size
, mode
, unsignedp
,
1036 emit_jump (if_false_label
);
1038 emit_label (dummy_label
);
1041 /* Generate code for a comparison expression EXP (including code to compute
1042 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
1043 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
1044 generated code will drop through.
1045 SIGNED_CODE should be the rtx operation for this comparison for
1046 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
1048 We force a stack adjustment unless there are currently
1049 things pushed on the stack that aren't yet used. */
1052 do_compare_and_jump (tree treeop0
, tree treeop1
, enum rtx_code signed_code
,
1053 enum rtx_code unsigned_code
, rtx if_false_label
,
1058 enum machine_mode mode
;
1062 /* Don't crash if the comparison was erroneous. */
1063 op0
= expand_normal (treeop0
);
1064 if (TREE_CODE (treeop0
) == ERROR_MARK
)
1067 op1
= expand_normal (treeop1
);
1068 if (TREE_CODE (treeop1
) == ERROR_MARK
)
1071 type
= TREE_TYPE (treeop0
);
1072 mode
= TYPE_MODE (type
);
1073 if (TREE_CODE (treeop0
) == INTEGER_CST
1074 && (TREE_CODE (treeop1
) != INTEGER_CST
1075 || (GET_MODE_BITSIZE (mode
)
1076 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (treeop1
))))))
1078 /* op0 might have been replaced by promoted constant, in which
1079 case the type of second argument should be used. */
1080 type
= TREE_TYPE (treeop1
);
1081 mode
= TYPE_MODE (type
);
1083 unsignedp
= TYPE_UNSIGNED (type
);
1084 code
= unsignedp
? unsigned_code
: signed_code
;
1086 #ifdef HAVE_canonicalize_funcptr_for_compare
1087 /* If function pointers need to be "canonicalized" before they can
1088 be reliably compared, then canonicalize them.
1089 Only do this if *both* sides of the comparison are function pointers.
1090 If one side isn't, we want a noncanonicalized comparison. See PR
1091 middle-end/17564. */
1092 if (HAVE_canonicalize_funcptr_for_compare
1093 && TREE_CODE (TREE_TYPE (treeop0
)) == POINTER_TYPE
1094 && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop0
)))
1096 && TREE_CODE (TREE_TYPE (treeop1
)) == POINTER_TYPE
1097 && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop1
)))
1100 rtx new_op0
= gen_reg_rtx (mode
);
1101 rtx new_op1
= gen_reg_rtx (mode
);
1103 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0
, op0
));
1106 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1
, op1
));
1111 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
,
1113 ? expr_size (treeop0
) : NULL_RTX
),
1114 if_false_label
, if_true_label
);
1117 #include "gt-dojump.h"