1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
26 #include "stor-layout.h"
29 #include "insn-config.h"
30 #include "insn-attr.h"
31 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
34 #include "langhooks.h"
36 #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
, int);
41 static void do_jump_by_parts_equality (tree
, tree
, rtx
, rtx
, int);
42 static void do_compare_and_jump (tree
, tree
, enum rtx_code
, enum rtx_code
, rtx
,
45 /* Invert probability if there is any. -1 stands for unknown. */
50 return prob
== -1 ? -1 : REG_BR_PROB_BASE
- prob
;
53 /* At the start of a function, record that we have no previously-pushed
54 arguments waiting to be popped. */
57 init_pending_stack_adjust (void)
59 pending_stack_adjust
= 0;
62 /* Discard any pending stack adjustment. This avoid relying on the
63 RTL optimizers to remove useless adjustments when we know the
64 stack pointer value is dead. */
66 discard_pending_stack_adjust (void)
68 stack_pointer_delta
-= pending_stack_adjust
;
69 pending_stack_adjust
= 0;
72 /* When exiting from function, if safe, clear out any pending stack adjust
73 so the adjustment won't get done.
75 Note, if the current function calls alloca, then it must have a
76 frame pointer regardless of the value of flag_omit_frame_pointer. */
79 clear_pending_stack_adjust (void)
82 && (! flag_omit_frame_pointer
|| cfun
->calls_alloca
)
84 discard_pending_stack_adjust ();
87 /* Pop any previously-pushed arguments that have not been popped yet. */
90 do_pending_stack_adjust (void)
92 if (inhibit_defer_pop
== 0)
94 if (pending_stack_adjust
!= 0)
95 adjust_stack (GEN_INT (pending_stack_adjust
));
96 pending_stack_adjust
= 0;
100 /* Remember pending_stack_adjust/stack_pointer_delta.
101 To be used around code that may call do_pending_stack_adjust (),
102 but the generated code could be discarded e.g. using delete_insns_since. */
105 save_pending_stack_adjust (saved_pending_stack_adjust
*save
)
107 save
->x_pending_stack_adjust
= pending_stack_adjust
;
108 save
->x_stack_pointer_delta
= stack_pointer_delta
;
111 /* Restore the saved pending_stack_adjust/stack_pointer_delta. */
114 restore_pending_stack_adjust (saved_pending_stack_adjust
*save
)
116 if (inhibit_defer_pop
== 0)
118 pending_stack_adjust
= save
->x_pending_stack_adjust
;
119 stack_pointer_delta
= save
->x_stack_pointer_delta
;
123 /* Expand conditional expressions. */
125 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
126 LABEL is an rtx of code CODE_LABEL, in this function and all the
130 jumpifnot (tree exp
, rtx label
, int prob
)
132 do_jump (exp
, label
, NULL_RTX
, inv (prob
));
136 jumpifnot_1 (enum tree_code code
, tree op0
, tree op1
, rtx label
, int prob
)
138 do_jump_1 (code
, op0
, op1
, label
, NULL_RTX
, inv (prob
));
141 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
144 jumpif (tree exp
, rtx label
, int prob
)
146 do_jump (exp
, NULL_RTX
, label
, prob
);
150 jumpif_1 (enum tree_code code
, tree op0
, tree op1
, rtx label
, int prob
)
152 do_jump_1 (code
, op0
, op1
, NULL_RTX
, label
, prob
);
155 /* Used internally by prefer_and_bit_test. */
157 static GTY(()) rtx and_reg
;
158 static GTY(()) rtx and_test
;
159 static GTY(()) rtx shift_test
;
161 /* Compare the relative costs of "(X & (1 << BITNUM))" and "(X >> BITNUM) & 1",
162 where X is an arbitrary register of mode MODE. Return true if the former
166 prefer_and_bit_test (enum machine_mode mode
, int bitnum
)
172 /* Set up rtxes for the two variations. Use NULL as a placeholder
173 for the BITNUM-based constants. */
174 and_reg
= gen_rtx_REG (mode
, FIRST_PSEUDO_REGISTER
);
175 and_test
= gen_rtx_AND (mode
, and_reg
, NULL
);
176 shift_test
= gen_rtx_AND (mode
, gen_rtx_ASHIFTRT (mode
, and_reg
, NULL
),
181 /* Change the mode of the previously-created rtxes. */
182 PUT_MODE (and_reg
, mode
);
183 PUT_MODE (and_test
, mode
);
184 PUT_MODE (shift_test
, mode
);
185 PUT_MODE (XEXP (shift_test
, 0), mode
);
188 /* Fill in the integers. */
190 = immed_double_int_const (double_int_zero
.set_bit (bitnum
), mode
);
191 XEXP (XEXP (shift_test
, 0), 1) = GEN_INT (bitnum
);
193 speed_p
= optimize_insn_for_speed_p ();
194 return (rtx_cost (and_test
, IF_THEN_ELSE
, 0, speed_p
)
195 <= rtx_cost (shift_test
, IF_THEN_ELSE
, 0, speed_p
));
198 /* Subroutine of do_jump, dealing with exploded comparisons of the type
199 OP0 CODE OP1 . IF_FALSE_LABEL and IF_TRUE_LABEL like in do_jump.
200 PROB is probability of jump to if_true_label, or -1 if unknown. */
203 do_jump_1 (enum tree_code code
, tree op0
, tree op1
,
204 rtx if_false_label
, rtx if_true_label
, int prob
)
206 enum machine_mode mode
;
207 rtx drop_through_label
= 0;
213 tree inner_type
= TREE_TYPE (op0
);
215 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
216 != MODE_COMPLEX_FLOAT
);
217 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
218 != MODE_COMPLEX_INT
);
220 if (integer_zerop (op1
))
221 do_jump (op0
, if_true_label
, if_false_label
, inv (prob
));
222 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
223 && !can_compare_p (EQ
, TYPE_MODE (inner_type
), ccp_jump
))
224 do_jump_by_parts_equality (op0
, op1
, if_false_label
, if_true_label
,
227 do_compare_and_jump (op0
, op1
, EQ
, EQ
, if_false_label
, if_true_label
,
234 tree inner_type
= TREE_TYPE (op0
);
236 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
237 != MODE_COMPLEX_FLOAT
);
238 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type
))
239 != MODE_COMPLEX_INT
);
241 if (integer_zerop (op1
))
242 do_jump (op0
, if_false_label
, if_true_label
, prob
);
243 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
244 && !can_compare_p (NE
, TYPE_MODE (inner_type
), ccp_jump
))
245 do_jump_by_parts_equality (op0
, op1
, if_true_label
, if_false_label
,
248 do_compare_and_jump (op0
, op1
, NE
, NE
, if_false_label
, if_true_label
,
254 mode
= TYPE_MODE (TREE_TYPE (op0
));
255 if (GET_MODE_CLASS (mode
) == MODE_INT
256 && ! can_compare_p (LT
, mode
, ccp_jump
))
257 do_jump_by_parts_greater (op0
, op1
, 1, if_false_label
, if_true_label
,
260 do_compare_and_jump (op0
, op1
, LT
, LTU
, if_false_label
, if_true_label
,
265 mode
= TYPE_MODE (TREE_TYPE (op0
));
266 if (GET_MODE_CLASS (mode
) == MODE_INT
267 && ! can_compare_p (LE
, mode
, ccp_jump
))
268 do_jump_by_parts_greater (op0
, op1
, 0, if_true_label
, if_false_label
,
271 do_compare_and_jump (op0
, op1
, LE
, LEU
, if_false_label
, if_true_label
,
276 mode
= TYPE_MODE (TREE_TYPE (op0
));
277 if (GET_MODE_CLASS (mode
) == MODE_INT
278 && ! can_compare_p (GT
, mode
, ccp_jump
))
279 do_jump_by_parts_greater (op0
, op1
, 0, if_false_label
, if_true_label
,
282 do_compare_and_jump (op0
, op1
, GT
, GTU
, if_false_label
, if_true_label
,
287 mode
= TYPE_MODE (TREE_TYPE (op0
));
288 if (GET_MODE_CLASS (mode
) == MODE_INT
289 && ! can_compare_p (GE
, mode
, ccp_jump
))
290 do_jump_by_parts_greater (op0
, op1
, 1, if_true_label
, if_false_label
,
293 do_compare_and_jump (op0
, op1
, GE
, GEU
, if_false_label
, if_true_label
,
298 do_compare_and_jump (op0
, op1
, ORDERED
, ORDERED
,
299 if_false_label
, if_true_label
, prob
);
303 do_compare_and_jump (op0
, op1
, UNORDERED
, UNORDERED
,
304 if_false_label
, if_true_label
, prob
);
308 do_compare_and_jump (op0
, op1
, UNLT
, UNLT
, if_false_label
, if_true_label
,
313 do_compare_and_jump (op0
, op1
, UNLE
, UNLE
, if_false_label
, if_true_label
,
318 do_compare_and_jump (op0
, op1
, UNGT
, UNGT
, if_false_label
, if_true_label
,
323 do_compare_and_jump (op0
, op1
, UNGE
, UNGE
, if_false_label
, if_true_label
,
328 do_compare_and_jump (op0
, op1
, UNEQ
, UNEQ
, if_false_label
, if_true_label
,
333 do_compare_and_jump (op0
, op1
, LTGT
, LTGT
, if_false_label
, if_true_label
,
337 case TRUTH_ANDIF_EXPR
:
339 /* Spread the probability that the expression is false evenly between
340 the two conditions. So the first condition is false half the total
341 probability of being false. The second condition is false the other
342 half of the total probability of being false, so its jump has a false
343 probability of half the total, relative to the probability we
344 reached it (i.e. the first condition was true). */
349 int false_prob
= inv (prob
);
350 int op0_false_prob
= false_prob
/ 2;
351 int op1_false_prob
= GCOV_COMPUTE_SCALE ((false_prob
/ 2),
352 inv (op0_false_prob
));
353 /* Get the probability that each jump below is true. */
354 op0_prob
= inv (op0_false_prob
);
355 op1_prob
= inv (op1_false_prob
);
357 if (if_false_label
== NULL_RTX
)
359 drop_through_label
= gen_label_rtx ();
360 do_jump (op0
, drop_through_label
, NULL_RTX
, op0_prob
);
361 do_jump (op1
, NULL_RTX
, if_true_label
, op1_prob
);
365 do_jump (op0
, if_false_label
, NULL_RTX
, op0_prob
);
366 do_jump (op1
, if_false_label
, if_true_label
, op1_prob
);
371 case TRUTH_ORIF_EXPR
:
373 /* Spread the probability evenly between the two conditions. So
374 the first condition has half the total probability of being true.
375 The second condition has the other half of the total probability,
376 so its jump has a probability of half the total, relative to
377 the probability we reached it (i.e. the first condition was false). */
383 op1_prob
= GCOV_COMPUTE_SCALE ((prob
/ 2), inv (op0_prob
));
385 if (if_true_label
== NULL_RTX
)
387 drop_through_label
= gen_label_rtx ();
388 do_jump (op0
, NULL_RTX
, drop_through_label
, op0_prob
);
389 do_jump (op1
, if_false_label
, NULL_RTX
, op1_prob
);
393 do_jump (op0
, NULL_RTX
, if_true_label
, op0_prob
);
394 do_jump (op1
, if_false_label
, if_true_label
, op1_prob
);
403 if (drop_through_label
)
405 do_pending_stack_adjust ();
406 emit_label (drop_through_label
);
410 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
411 the result is zero, or IF_TRUE_LABEL if the result is one.
412 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
413 meaning fall through in that case.
415 do_jump always does any pending stack adjust except when it does not
416 actually perform a jump. An example where there is no jump
417 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
419 PROB is probability of jump to if_true_label, or -1 if unknown. */
422 do_jump (tree exp
, rtx if_false_label
, rtx if_true_label
, int prob
)
424 enum tree_code code
= TREE_CODE (exp
);
428 enum machine_mode mode
;
429 rtx drop_through_label
= 0;
437 temp
= integer_zerop (exp
) ? if_false_label
: if_true_label
;
443 /* This is not true with #pragma weak */
445 /* The address of something can never be zero. */
447 emit_jump (if_true_label
);
452 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == COMPONENT_REF
453 || TREE_CODE (TREE_OPERAND (exp
, 0)) == BIT_FIELD_REF
454 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_REF
455 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_RANGE_REF
)
458 /* If we are narrowing the operand, we have to do the compare in the
460 if ((TYPE_PRECISION (TREE_TYPE (exp
))
461 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
463 case NON_LVALUE_EXPR
:
468 /* These cannot change zero->nonzero or vice versa. */
469 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
, prob
);
473 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
,
479 rtx label1
= gen_label_rtx ();
480 if (!if_true_label
|| !if_false_label
)
482 drop_through_label
= gen_label_rtx ();
484 if_true_label
= drop_through_label
;
486 if_false_label
= drop_through_label
;
489 do_pending_stack_adjust ();
490 do_jump (TREE_OPERAND (exp
, 0), label1
, NULL_RTX
, -1);
491 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
, prob
);
493 do_jump (TREE_OPERAND (exp
, 2), if_false_label
, if_true_label
, prob
);
498 /* Lowered by gimplify.c. */
502 /* Nonzero iff operands of minus differ. */
520 case TRUTH_ANDIF_EXPR
:
521 case TRUTH_ORIF_EXPR
:
523 do_jump_1 (code
, TREE_OPERAND (exp
, 0), TREE_OPERAND (exp
, 1),
524 if_false_label
, if_true_label
, prob
);
528 /* fold_single_bit_test() converts (X & (1 << C)) into (X >> C) & 1.
529 See if the former is preferred for jump tests and restore it
531 if (integer_onep (TREE_OPERAND (exp
, 1)))
533 tree exp0
= TREE_OPERAND (exp
, 0);
534 rtx set_label
, clr_label
;
535 int setclr_prob
= prob
;
537 /* Strip narrowing integral type conversions. */
538 while (CONVERT_EXPR_P (exp0
)
539 && TREE_OPERAND (exp0
, 0) != error_mark_node
540 && TYPE_PRECISION (TREE_TYPE (exp0
))
541 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp0
, 0))))
542 exp0
= TREE_OPERAND (exp0
, 0);
544 /* "exp0 ^ 1" inverts the sense of the single bit test. */
545 if (TREE_CODE (exp0
) == BIT_XOR_EXPR
546 && integer_onep (TREE_OPERAND (exp0
, 1)))
548 exp0
= TREE_OPERAND (exp0
, 0);
549 clr_label
= if_true_label
;
550 set_label
= if_false_label
;
551 setclr_prob
= inv (prob
);
555 clr_label
= if_false_label
;
556 set_label
= if_true_label
;
559 if (TREE_CODE (exp0
) == RSHIFT_EXPR
)
561 tree arg
= TREE_OPERAND (exp0
, 0);
562 tree shift
= TREE_OPERAND (exp0
, 1);
563 tree argtype
= TREE_TYPE (arg
);
564 if (TREE_CODE (shift
) == INTEGER_CST
565 && compare_tree_int (shift
, 0) >= 0
566 && compare_tree_int (shift
, HOST_BITS_PER_WIDE_INT
) < 0
567 && prefer_and_bit_test (TYPE_MODE (argtype
),
568 TREE_INT_CST_LOW (shift
)))
570 unsigned HOST_WIDE_INT mask
571 = (unsigned HOST_WIDE_INT
) 1 << TREE_INT_CST_LOW (shift
);
572 do_jump (build2 (BIT_AND_EXPR
, argtype
, arg
,
573 build_int_cstu (argtype
, mask
)),
574 clr_label
, set_label
, setclr_prob
);
580 /* If we are AND'ing with a small constant, do this comparison in the
581 smallest type that fits. If the machine doesn't have comparisons
582 that small, it will be converted back to the wider comparison.
583 This helps if we are testing the sign bit of a narrower object.
584 combine can't do this for us because it can't know whether a
585 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
587 if (! SLOW_BYTE_ACCESS
588 && TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
589 && TYPE_PRECISION (TREE_TYPE (exp
)) <= HOST_BITS_PER_WIDE_INT
590 && (i
= tree_floor_log2 (TREE_OPERAND (exp
, 1))) >= 0
591 && (mode
= mode_for_size (i
+ 1, MODE_INT
, 0)) != BLKmode
592 && (type
= lang_hooks
.types
.type_for_mode (mode
, 1)) != 0
593 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
594 && have_insn_for (COMPARE
, TYPE_MODE (type
)))
596 do_jump (fold_convert (type
, exp
), if_false_label
, if_true_label
,
601 if (TYPE_PRECISION (TREE_TYPE (exp
)) > 1
602 || TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
)
605 /* Boolean comparisons can be compiled as TRUTH_AND_EXPR. */
608 /* High branch cost, expand as the bitwise AND of the conditions.
609 Do the same if the RHS has side effects, because we're effectively
610 turning a TRUTH_AND_EXPR into a TRUTH_ANDIF_EXPR. */
611 if (BRANCH_COST (optimize_insn_for_speed_p (),
613 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp
, 1)))
615 code
= TRUTH_ANDIF_EXPR
;
620 /* High branch cost, expand as the bitwise OR of the conditions.
621 Do the same if the RHS has side effects, because we're effectively
622 turning a TRUTH_OR_EXPR into a TRUTH_ORIF_EXPR. */
623 if (BRANCH_COST (optimize_insn_for_speed_p (), false) >= 4
624 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp
, 1)))
626 code
= TRUTH_ORIF_EXPR
;
629 /* Fall through and generate the normal code. */
632 temp
= expand_normal (exp
);
633 do_pending_stack_adjust ();
634 /* The RTL optimizers prefer comparisons against pseudos. */
635 if (GET_CODE (temp
) == SUBREG
)
637 /* Compare promoted variables in their promoted mode. */
638 if (SUBREG_PROMOTED_VAR_P (temp
)
639 && REG_P (XEXP (temp
, 0)))
640 temp
= XEXP (temp
, 0);
642 temp
= copy_to_reg (temp
);
644 do_compare_rtx_and_jump (temp
, CONST0_RTX (GET_MODE (temp
)),
645 NE
, TYPE_UNSIGNED (TREE_TYPE (exp
)),
646 GET_MODE (temp
), NULL_RTX
,
647 if_false_label
, if_true_label
, prob
);
650 if (drop_through_label
)
652 do_pending_stack_adjust ();
653 emit_label (drop_through_label
);
657 /* Compare OP0 with OP1, word at a time, in mode MODE.
658 UNSIGNEDP says to do unsigned comparison.
659 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
662 do_jump_by_parts_greater_rtx (enum machine_mode mode
, int unsignedp
, rtx op0
,
663 rtx op1
, rtx if_false_label
, rtx if_true_label
,
666 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
667 rtx drop_through_label
= 0;
668 bool drop_through_if_true
= false, drop_through_if_false
= false;
669 enum rtx_code code
= GT
;
672 if (! if_true_label
|| ! if_false_label
)
673 drop_through_label
= gen_label_rtx ();
676 if_true_label
= drop_through_label
;
677 drop_through_if_true
= true;
679 if (! if_false_label
)
681 if_false_label
= drop_through_label
;
682 drop_through_if_false
= true;
685 /* Deal with the special case 0 > x: only one comparison is necessary and
686 we reverse it to avoid jumping to the drop-through label. */
687 if (op0
== const0_rtx
&& drop_through_if_true
&& !drop_through_if_false
)
690 if_true_label
= if_false_label
;
691 if_false_label
= drop_through_label
;
692 drop_through_if_true
= false;
693 drop_through_if_false
= true;
696 /* Compare a word at a time, high order first. */
697 for (i
= 0; i
< nwords
; i
++)
699 rtx op0_word
, op1_word
;
701 if (WORDS_BIG_ENDIAN
)
703 op0_word
= operand_subword_force (op0
, i
, mode
);
704 op1_word
= operand_subword_force (op1
, i
, mode
);
708 op0_word
= operand_subword_force (op0
, nwords
- 1 - i
, mode
);
709 op1_word
= operand_subword_force (op1
, nwords
- 1 - i
, mode
);
712 /* All but high-order word must be compared as unsigned. */
713 do_compare_rtx_and_jump (op0_word
, op1_word
, code
, (unsignedp
|| i
> 0),
714 word_mode
, NULL_RTX
, NULL_RTX
, if_true_label
,
717 /* Emit only one comparison for 0. Do not emit the last cond jump. */
718 if (op0
== const0_rtx
|| i
== nwords
- 1)
721 /* Consider lower words only if these are equal. */
722 do_compare_rtx_and_jump (op0_word
, op1_word
, NE
, unsignedp
, word_mode
,
723 NULL_RTX
, NULL_RTX
, if_false_label
, inv (prob
));
726 if (!drop_through_if_false
)
727 emit_jump (if_false_label
);
728 if (drop_through_label
)
729 emit_label (drop_through_label
);
732 /* Given a comparison expression EXP for values too wide to be compared
733 with one insn, test the comparison and jump to the appropriate label.
734 The code of EXP is ignored; we always test GT if SWAP is 0,
735 and LT if SWAP is 1. */
738 do_jump_by_parts_greater (tree treeop0
, tree treeop1
, int swap
,
739 rtx if_false_label
, rtx if_true_label
, int prob
)
741 rtx op0
= expand_normal (swap
? treeop1
: treeop0
);
742 rtx op1
= expand_normal (swap
? treeop0
: treeop1
);
743 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (treeop0
));
744 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (treeop0
));
746 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
,
747 if_true_label
, prob
);
750 /* Jump according to whether OP0 is 0. We assume that OP0 has an integer
751 mode, MODE, that is too wide for the available compare insns. Either
752 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
753 to indicate drop through. */
756 do_jump_by_parts_zero_rtx (enum machine_mode mode
, rtx op0
,
757 rtx if_false_label
, rtx if_true_label
, int prob
)
759 int nwords
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
762 rtx drop_through_label
= 0;
764 /* The fastest way of doing this comparison on almost any machine is to
765 "or" all the words and compare the result. If all have to be loaded
766 from memory and this is a very wide item, it's possible this may
767 be slower, but that's highly unlikely. */
769 part
= gen_reg_rtx (word_mode
);
770 emit_move_insn (part
, operand_subword_force (op0
, 0, mode
));
771 for (i
= 1; i
< nwords
&& part
!= 0; i
++)
772 part
= expand_binop (word_mode
, ior_optab
, part
,
773 operand_subword_force (op0
, i
, mode
),
774 part
, 1, OPTAB_WIDEN
);
778 do_compare_rtx_and_jump (part
, const0_rtx
, EQ
, 1, word_mode
,
779 NULL_RTX
, if_false_label
, if_true_label
, prob
);
783 /* If we couldn't do the "or" simply, do this with a series of compares. */
784 if (! if_false_label
)
785 drop_through_label
= if_false_label
= gen_label_rtx ();
787 for (i
= 0; i
< nwords
; i
++)
788 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
789 const0_rtx
, EQ
, 1, word_mode
, NULL_RTX
,
790 if_false_label
, NULL_RTX
, prob
);
793 emit_jump (if_true_label
);
795 if (drop_through_label
)
796 emit_label (drop_through_label
);
799 /* Test for the equality of two RTX expressions OP0 and OP1 in mode MODE,
800 where MODE is an integer mode too wide to be compared with one insn.
801 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
802 to indicate drop through. */
805 do_jump_by_parts_equality_rtx (enum machine_mode mode
, rtx op0
, rtx op1
,
806 rtx if_false_label
, rtx if_true_label
, int prob
)
808 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
809 rtx drop_through_label
= 0;
812 if (op1
== const0_rtx
)
814 do_jump_by_parts_zero_rtx (mode
, op0
, if_false_label
, if_true_label
,
818 else if (op0
== const0_rtx
)
820 do_jump_by_parts_zero_rtx (mode
, op1
, if_false_label
, if_true_label
,
825 if (! if_false_label
)
826 drop_through_label
= if_false_label
= gen_label_rtx ();
828 for (i
= 0; i
< nwords
; i
++)
829 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
830 operand_subword_force (op1
, i
, mode
),
831 EQ
, 0, word_mode
, NULL_RTX
,
832 if_false_label
, NULL_RTX
, prob
);
835 emit_jump (if_true_label
);
836 if (drop_through_label
)
837 emit_label (drop_through_label
);
840 /* Given an EQ_EXPR expression EXP for values too wide to be compared
841 with one insn, test the comparison and jump to the appropriate label. */
844 do_jump_by_parts_equality (tree treeop0
, tree treeop1
, rtx if_false_label
,
845 rtx if_true_label
, int prob
)
847 rtx op0
= expand_normal (treeop0
);
848 rtx op1
= expand_normal (treeop1
);
849 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (treeop0
));
850 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_false_label
,
851 if_true_label
, prob
);
854 /* Split a comparison into two others, the second of which has the other
855 "orderedness". The first is always ORDERED or UNORDERED if MODE
856 does not honor NaNs (which means that it can be skipped in that case;
857 see do_compare_rtx_and_jump).
859 The two conditions are written in *CODE1 and *CODE2. Return true if
860 the conditions must be ANDed, false if they must be ORed. */
863 split_comparison (enum rtx_code code
, enum machine_mode mode
,
864 enum rtx_code
*code1
, enum rtx_code
*code2
)
913 /* Do not turn a trapping comparison into a non-trapping one. */
914 if (HONOR_SNANS (mode
))
932 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
933 The decision as to signed or unsigned comparison must be made by the caller.
935 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
939 do_compare_rtx_and_jump (rtx op0
, rtx op1
, enum rtx_code code
, int unsignedp
,
940 enum machine_mode mode
, rtx size
, rtx if_false_label
,
941 rtx if_true_label
, int prob
)
944 rtx dummy_label
= NULL_RTX
;
946 /* Reverse the comparison if that is safe and we want to jump if it is
947 false. Also convert to the reverse comparison if the target can
950 || ! can_compare_p (code
, mode
, ccp_jump
))
951 && (! FLOAT_MODE_P (mode
)
952 || code
== ORDERED
|| code
== UNORDERED
953 || (! HONOR_NANS (mode
) && (code
== LTGT
|| code
== UNEQ
))
954 || (! HONOR_SNANS (mode
) && (code
== EQ
|| code
== NE
))))
957 if (FLOAT_MODE_P (mode
))
958 rcode
= reverse_condition_maybe_unordered (code
);
960 rcode
= reverse_condition (code
);
962 /* Canonicalize to UNORDERED for the libcall. */
963 if (can_compare_p (rcode
, mode
, ccp_jump
)
964 || (code
== ORDERED
&& ! can_compare_p (ORDERED
, mode
, ccp_jump
)))
967 if_true_label
= if_false_label
;
968 if_false_label
= tem
;
974 /* If one operand is constant, make it the second one. Only do this
975 if the other operand is not constant as well. */
977 if (swap_commutative_operands_p (op0
, op1
))
982 code
= swap_condition (code
);
985 do_pending_stack_adjust ();
987 code
= unsignedp
? unsigned_condition (code
) : code
;
988 if (0 != (tem
= simplify_relational_operation (code
, mode
, VOIDmode
,
991 if (CONSTANT_P (tem
))
993 rtx label
= (tem
== const0_rtx
|| tem
== CONST0_RTX (mode
))
994 ? if_false_label
: if_true_label
;
1000 code
= GET_CODE (tem
);
1001 mode
= GET_MODE (tem
);
1002 op0
= XEXP (tem
, 0);
1003 op1
= XEXP (tem
, 1);
1004 unsignedp
= (code
== GTU
|| code
== LTU
|| code
== GEU
|| code
== LEU
);
1007 if (! if_true_label
)
1008 dummy_label
= if_true_label
= gen_label_rtx ();
1010 if (GET_MODE_CLASS (mode
) == MODE_INT
1011 && ! can_compare_p (code
, mode
, ccp_jump
))
1016 do_jump_by_parts_greater_rtx (mode
, 1, op1
, op0
,
1017 if_false_label
, if_true_label
, prob
);
1021 do_jump_by_parts_greater_rtx (mode
, 1, op0
, op1
,
1022 if_true_label
, if_false_label
,
1027 do_jump_by_parts_greater_rtx (mode
, 1, op0
, op1
,
1028 if_false_label
, if_true_label
, prob
);
1032 do_jump_by_parts_greater_rtx (mode
, 1, op1
, op0
,
1033 if_true_label
, if_false_label
,
1038 do_jump_by_parts_greater_rtx (mode
, 0, op1
, op0
,
1039 if_false_label
, if_true_label
, prob
);
1043 do_jump_by_parts_greater_rtx (mode
, 0, op0
, op1
,
1044 if_true_label
, if_false_label
,
1049 do_jump_by_parts_greater_rtx (mode
, 0, op0
, op1
,
1050 if_false_label
, if_true_label
, prob
);
1054 do_jump_by_parts_greater_rtx (mode
, 0, op1
, op0
,
1055 if_true_label
, if_false_label
,
1060 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_false_label
,
1061 if_true_label
, prob
);
1065 do_jump_by_parts_equality_rtx (mode
, op0
, op1
, if_true_label
,
1066 if_false_label
, inv (prob
));
1075 if (SCALAR_FLOAT_MODE_P (mode
)
1076 && ! can_compare_p (code
, mode
, ccp_jump
)
1077 && can_compare_p (swap_condition (code
), mode
, ccp_jump
))
1080 code
= swap_condition (code
);
1085 else if (SCALAR_FLOAT_MODE_P (mode
)
1086 && ! can_compare_p (code
, mode
, ccp_jump
)
1087 /* Never split ORDERED and UNORDERED.
1088 These must be implemented. */
1089 && (code
!= ORDERED
&& code
!= UNORDERED
)
1090 /* Split a floating-point comparison if
1091 we can jump on other conditions... */
1092 && (have_insn_for (COMPARE
, mode
)
1093 /* ... or if there is no libcall for it. */
1094 || code_to_optab (code
) == unknown_optab
))
1096 enum rtx_code first_code
;
1097 bool and_them
= split_comparison (code
, mode
, &first_code
, &code
);
1099 /* If there are no NaNs, the first comparison should always fall
1101 if (!HONOR_NANS (mode
))
1102 gcc_assert (first_code
== (and_them
? ORDERED
: UNORDERED
));
1109 /* If we only jump if true, just bypass the second jump. */
1110 if (! if_false_label
)
1113 dummy_label
= gen_label_rtx ();
1114 dest_label
= dummy_label
;
1117 dest_label
= if_false_label
;
1118 do_compare_rtx_and_jump (op0
, op1
, first_code
, unsignedp
, mode
,
1119 size
, dest_label
, NULL_RTX
, prob
);
1122 do_compare_rtx_and_jump (op0
, op1
, first_code
, unsignedp
, mode
,
1123 size
, NULL_RTX
, if_true_label
, prob
);
1127 emit_cmp_and_jump_insns (op0
, op1
, code
, size
, mode
, unsignedp
,
1128 if_true_label
, prob
);
1132 emit_jump (if_false_label
);
1134 emit_label (dummy_label
);
1137 /* Generate code for a comparison expression EXP (including code to compute
1138 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
1139 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
1140 generated code will drop through.
1141 SIGNED_CODE should be the rtx operation for this comparison for
1142 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
1144 We force a stack adjustment unless there are currently
1145 things pushed on the stack that aren't yet used. */
1148 do_compare_and_jump (tree treeop0
, tree treeop1
, enum rtx_code signed_code
,
1149 enum rtx_code unsigned_code
, rtx if_false_label
,
1150 rtx if_true_label
, int prob
)
1154 enum machine_mode mode
;
1158 /* Don't crash if the comparison was erroneous. */
1159 op0
= expand_normal (treeop0
);
1160 if (TREE_CODE (treeop0
) == ERROR_MARK
)
1163 op1
= expand_normal (treeop1
);
1164 if (TREE_CODE (treeop1
) == ERROR_MARK
)
1167 type
= TREE_TYPE (treeop0
);
1168 mode
= TYPE_MODE (type
);
1169 if (TREE_CODE (treeop0
) == INTEGER_CST
1170 && (TREE_CODE (treeop1
) != INTEGER_CST
1171 || (GET_MODE_BITSIZE (mode
)
1172 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (treeop1
))))))
1174 /* op0 might have been replaced by promoted constant, in which
1175 case the type of second argument should be used. */
1176 type
= TREE_TYPE (treeop1
);
1177 mode
= TYPE_MODE (type
);
1179 unsignedp
= TYPE_UNSIGNED (type
);
1180 code
= unsignedp
? unsigned_code
: signed_code
;
1182 #ifdef HAVE_canonicalize_funcptr_for_compare
1183 /* If function pointers need to be "canonicalized" before they can
1184 be reliably compared, then canonicalize them.
1185 Only do this if *both* sides of the comparison are function pointers.
1186 If one side isn't, we want a noncanonicalized comparison. See PR
1187 middle-end/17564. */
1188 if (HAVE_canonicalize_funcptr_for_compare
1189 && TREE_CODE (TREE_TYPE (treeop0
)) == POINTER_TYPE
1190 && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop0
)))
1192 && TREE_CODE (TREE_TYPE (treeop1
)) == POINTER_TYPE
1193 && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop1
)))
1196 rtx new_op0
= gen_reg_rtx (mode
);
1197 rtx new_op1
= gen_reg_rtx (mode
);
1199 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0
, op0
));
1202 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1
, op1
));
1207 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
,
1209 ? expr_size (treeop0
) : NULL_RTX
),
1210 if_false_label
, if_true_label
, prob
);
1213 #include "gt-dojump.h"