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 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"
37 static void do_jump_by_parts_greater
PARAMS ((tree
, int, rtx
, rtx
));
38 static void do_jump_by_parts_equality
PARAMS ((tree
, rtx
, rtx
));
39 static void do_compare_and_jump
PARAMS ((tree
, enum rtx_code
, enum rtx_code
,
42 /* At the start of a function, record that we have no previously-pushed
43 arguments waiting to be popped. */
46 init_pending_stack_adjust ()
48 pending_stack_adjust
= 0;
51 /* When exiting from function, if safe, clear out any pending stack adjust
52 so the adjustment won't get done.
54 Note, if the current function calls alloca, then it must have a
55 frame pointer regardless of the value of flag_omit_frame_pointer. */
58 clear_pending_stack_adjust ()
60 #ifdef EXIT_IGNORE_STACK
62 && (! flag_omit_frame_pointer
|| current_function_calls_alloca
)
64 && ! (DECL_INLINE (current_function_decl
) && ! flag_no_inline
)
65 && ! flag_inline_functions
)
67 stack_pointer_delta
-= pending_stack_adjust
,
68 pending_stack_adjust
= 0;
73 /* Pop any previously-pushed arguments that have not been popped yet. */
76 do_pending_stack_adjust ()
78 if (inhibit_defer_pop
== 0)
80 if (pending_stack_adjust
!= 0)
81 adjust_stack (GEN_INT (pending_stack_adjust
));
82 pending_stack_adjust
= 0;
86 /* Expand conditional expressions. */
88 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
89 LABEL is an rtx of code CODE_LABEL, in this function and all the
93 jumpifnot (exp
, label
)
97 do_jump (exp
, label
, NULL_RTX
);
100 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
107 do_jump (exp
, NULL_RTX
, label
);
110 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
111 the result is zero, or IF_TRUE_LABEL if the result is one.
112 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
113 meaning fall through in that case.
115 do_jump always does any pending stack adjust except when it does not
116 actually perform a jump. An example where there is no jump
117 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
119 This function is responsible for optimizing cases such as
120 &&, || and comparison operators in EXP. */
123 do_jump (exp
, if_false_label
, if_true_label
)
125 rtx if_false_label
, if_true_label
;
127 enum tree_code code
= TREE_CODE (exp
);
128 /* Some cases need to create a label to jump to
129 in order to properly fall through.
130 These cases set DROP_THROUGH_LABEL nonzero. */
131 rtx drop_through_label
= 0;
135 enum machine_mode mode
;
137 #ifdef MAX_INTEGER_COMPUTATION_MODE
138 check_max_integer_computation_mode (exp
);
149 temp
= integer_zerop (exp
) ? if_false_label
: if_true_label
;
155 /* This is not true with #pragma weak */
157 /* The address of something can never be zero. */
159 emit_jump (if_true_label
);
164 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == COMPONENT_REF
165 || TREE_CODE (TREE_OPERAND (exp
, 0)) == BIT_FIELD_REF
166 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_REF
167 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_RANGE_REF
)
170 /* If we are narrowing the operand, we have to do the compare in the
172 if ((TYPE_PRECISION (TREE_TYPE (exp
))
173 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
175 case NON_LVALUE_EXPR
:
181 /* These cannot change zero->nonzero or vice versa. */
182 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
185 case WITH_RECORD_EXPR
:
186 /* Put the object on the placeholder list, recurse through our first
187 operand, and pop the list. */
188 placeholder_list
= tree_cons (TREE_OPERAND (exp
, 1), NULL_TREE
,
190 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
191 placeholder_list
= TREE_CHAIN (placeholder_list
);
195 /* This is never less insns than evaluating the PLUS_EXPR followed by
196 a test and can be longer if the test is eliminated. */
198 /* Reduce to minus. */
199 exp
= build (MINUS_EXPR
, TREE_TYPE (exp
),
200 TREE_OPERAND (exp
, 0),
201 fold (build1 (NEGATE_EXPR
, TREE_TYPE (TREE_OPERAND (exp
, 1)),
202 TREE_OPERAND (exp
, 1))));
203 /* Process as MINUS. */
207 /* Nonzero iff operands of minus differ. */
208 do_compare_and_jump (build (NE_EXPR
, TREE_TYPE (exp
),
209 TREE_OPERAND (exp
, 0),
210 TREE_OPERAND (exp
, 1)),
211 NE
, NE
, if_false_label
, if_true_label
);
215 /* If we are AND'ing with a small constant, do this comparison in the
216 smallest type that fits. If the machine doesn't have comparisons
217 that small, it will be converted back to the wider comparison.
218 This helps if we are testing the sign bit of a narrower object.
219 combine can't do this for us because it can't know whether a
220 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
222 if (! SLOW_BYTE_ACCESS
223 && TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
224 && TYPE_PRECISION (TREE_TYPE (exp
)) <= HOST_BITS_PER_WIDE_INT
225 && (i
= tree_floor_log2 (TREE_OPERAND (exp
, 1))) >= 0
226 && (mode
= mode_for_size (i
+ 1, MODE_INT
, 0)) != BLKmode
227 && (type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 1)) != 0
228 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
229 && (cmp_optab
->handlers
[(int) TYPE_MODE (type
)].insn_code
230 != CODE_FOR_nothing
))
232 do_jump (convert (type
, exp
), if_false_label
, if_true_label
);
238 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
241 case TRUTH_ANDIF_EXPR
:
242 if (if_false_label
== 0)
243 if_false_label
= drop_through_label
= gen_label_rtx ();
244 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, NULL_RTX
);
245 start_cleanup_deferral ();
246 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
247 end_cleanup_deferral ();
250 case TRUTH_ORIF_EXPR
:
251 if (if_true_label
== 0)
252 if_true_label
= drop_through_label
= gen_label_rtx ();
253 do_jump (TREE_OPERAND (exp
, 0), NULL_RTX
, if_true_label
);
254 start_cleanup_deferral ();
255 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
256 end_cleanup_deferral ();
261 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
, 0);
262 preserve_temp_slots (NULL_RTX
);
266 do_pending_stack_adjust ();
267 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
273 case ARRAY_RANGE_REF
:
275 HOST_WIDE_INT bitsize
, bitpos
;
277 enum machine_mode mode
;
282 /* Get description of this reference. We don't actually care
283 about the underlying object here. */
284 get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode
,
285 &unsignedp
, &volatilep
);
287 type
= (*lang_hooks
.types
.type_for_size
) (bitsize
, unsignedp
);
288 if (! SLOW_BYTE_ACCESS
289 && type
!= 0 && bitsize
>= 0
290 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
291 && (cmp_optab
->handlers
[(int) TYPE_MODE (type
)].insn_code
292 != CODE_FOR_nothing
))
294 do_jump (convert (type
, exp
), if_false_label
, if_true_label
);
301 /* Do (a ? 1 : 0) and (a ? 0 : 1) as special cases. */
302 if (integer_onep (TREE_OPERAND (exp
, 1))
303 && integer_zerop (TREE_OPERAND (exp
, 2)))
304 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
306 else if (integer_zerop (TREE_OPERAND (exp
, 1))
307 && integer_onep (TREE_OPERAND (exp
, 2)))
308 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
312 rtx label1
= gen_label_rtx ();
313 drop_through_label
= gen_label_rtx ();
315 do_jump (TREE_OPERAND (exp
, 0), label1
, NULL_RTX
);
317 start_cleanup_deferral ();
318 /* Now the THEN-expression. */
319 do_jump (TREE_OPERAND (exp
, 1),
320 if_false_label
? if_false_label
: drop_through_label
,
321 if_true_label
? if_true_label
: drop_through_label
);
322 /* In case the do_jump just above never jumps. */
323 do_pending_stack_adjust ();
326 /* Now the ELSE-expression. */
327 do_jump (TREE_OPERAND (exp
, 2),
328 if_false_label
? if_false_label
: drop_through_label
,
329 if_true_label
? if_true_label
: drop_through_label
);
330 end_cleanup_deferral ();
336 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
338 if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_FLOAT
339 || GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_INT
)
341 tree exp0
= save_expr (TREE_OPERAND (exp
, 0));
342 tree exp1
= save_expr (TREE_OPERAND (exp
, 1));
345 (build (TRUTH_ANDIF_EXPR
, TREE_TYPE (exp
),
346 fold (build (EQ_EXPR
, TREE_TYPE (exp
),
347 fold (build1 (REALPART_EXPR
,
348 TREE_TYPE (inner_type
),
350 fold (build1 (REALPART_EXPR
,
351 TREE_TYPE (inner_type
),
353 fold (build (EQ_EXPR
, TREE_TYPE (exp
),
354 fold (build1 (IMAGPART_EXPR
,
355 TREE_TYPE (inner_type
),
357 fold (build1 (IMAGPART_EXPR
,
358 TREE_TYPE (inner_type
),
360 if_false_label
, if_true_label
);
363 else if (integer_zerop (TREE_OPERAND (exp
, 1)))
364 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
366 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
367 && !can_compare_p (EQ
, TYPE_MODE (inner_type
), ccp_jump
))
368 do_jump_by_parts_equality (exp
, if_false_label
, if_true_label
);
370 do_compare_and_jump (exp
, EQ
, EQ
, if_false_label
, if_true_label
);
376 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
378 if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_FLOAT
379 || GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_INT
)
381 tree exp0
= save_expr (TREE_OPERAND (exp
, 0));
382 tree exp1
= save_expr (TREE_OPERAND (exp
, 1));
385 (build (TRUTH_ORIF_EXPR
, TREE_TYPE (exp
),
386 fold (build (NE_EXPR
, TREE_TYPE (exp
),
387 fold (build1 (REALPART_EXPR
,
388 TREE_TYPE (inner_type
),
390 fold (build1 (REALPART_EXPR
,
391 TREE_TYPE (inner_type
),
393 fold (build (NE_EXPR
, TREE_TYPE (exp
),
394 fold (build1 (IMAGPART_EXPR
,
395 TREE_TYPE (inner_type
),
397 fold (build1 (IMAGPART_EXPR
,
398 TREE_TYPE (inner_type
),
400 if_false_label
, if_true_label
);
403 else if (integer_zerop (TREE_OPERAND (exp
, 1)))
404 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
406 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
407 && !can_compare_p (NE
, TYPE_MODE (inner_type
), ccp_jump
))
408 do_jump_by_parts_equality (exp
, if_true_label
, if_false_label
);
410 do_compare_and_jump (exp
, NE
, NE
, if_false_label
, if_true_label
);
415 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
416 if (GET_MODE_CLASS (mode
) == MODE_INT
417 && ! can_compare_p (LT
, mode
, ccp_jump
))
418 do_jump_by_parts_greater (exp
, 1, if_false_label
, if_true_label
);
420 do_compare_and_jump (exp
, LT
, LTU
, if_false_label
, if_true_label
);
424 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
425 if (GET_MODE_CLASS (mode
) == MODE_INT
426 && ! can_compare_p (LE
, mode
, ccp_jump
))
427 do_jump_by_parts_greater (exp
, 0, if_true_label
, if_false_label
);
429 do_compare_and_jump (exp
, LE
, LEU
, if_false_label
, if_true_label
);
433 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
434 if (GET_MODE_CLASS (mode
) == MODE_INT
435 && ! can_compare_p (GT
, mode
, ccp_jump
))
436 do_jump_by_parts_greater (exp
, 0, if_false_label
, if_true_label
);
438 do_compare_and_jump (exp
, GT
, GTU
, if_false_label
, if_true_label
);
442 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
443 if (GET_MODE_CLASS (mode
) == MODE_INT
444 && ! can_compare_p (GE
, mode
, ccp_jump
))
445 do_jump_by_parts_greater (exp
, 1, if_true_label
, if_false_label
);
447 do_compare_and_jump (exp
, GE
, GEU
, if_false_label
, if_true_label
);
453 enum rtx_code cmp
, rcmp
;
456 if (code
== UNORDERED_EXPR
)
457 cmp
= UNORDERED
, rcmp
= ORDERED
;
459 cmp
= ORDERED
, rcmp
= UNORDERED
;
460 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
463 if (! can_compare_p (cmp
, mode
, ccp_jump
)
464 && (can_compare_p (rcmp
, mode
, ccp_jump
)
465 /* If the target doesn't provide either UNORDERED or ORDERED
466 comparisons, canonicalize on UNORDERED for the library. */
467 || rcmp
== UNORDERED
))
471 do_compare_and_jump (exp
, cmp
, cmp
, if_false_label
, if_true_label
);
473 do_compare_and_jump (exp
, rcmp
, rcmp
, if_true_label
, if_false_label
);
478 enum rtx_code rcode1
;
479 enum tree_code tcode2
;
503 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
504 if (can_compare_p (rcode1
, mode
, ccp_jump
))
505 do_compare_and_jump (exp
, rcode1
, rcode1
, if_false_label
,
509 tree op0
= save_expr (TREE_OPERAND (exp
, 0));
510 tree op1
= save_expr (TREE_OPERAND (exp
, 1));
513 /* If the target doesn't support combined unordered
514 compares, decompose into UNORDERED + comparison. */
515 cmp0
= fold (build (UNORDERED_EXPR
, TREE_TYPE (exp
), op0
, op1
));
516 cmp1
= fold (build (tcode2
, TREE_TYPE (exp
), op0
, op1
));
517 exp
= build (TRUTH_ORIF_EXPR
, TREE_TYPE (exp
), cmp0
, cmp1
);
518 do_jump (exp
, if_false_label
, if_true_label
);
524 __builtin_expect (<test>, 0) and
525 __builtin_expect (<test>, 1)
527 We need to do this here, so that <test> is not converted to a SCC
528 operation on machines that use condition code registers and COMPARE
529 like the PowerPC, and then the jump is done based on whether the SCC
530 operation produced a 1 or 0. */
532 /* Check for a built-in function. */
533 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
535 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
536 tree arglist
= TREE_OPERAND (exp
, 1);
538 if (TREE_CODE (fndecl
) == FUNCTION_DECL
539 && DECL_BUILT_IN (fndecl
)
540 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_EXPECT
541 && arglist
!= NULL_TREE
542 && TREE_CHAIN (arglist
) != NULL_TREE
)
544 rtx seq
= expand_builtin_expect_jump (exp
, if_false_label
,
554 /* fall through and generate the normal code. */
558 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, 0);
560 /* This is not needed any more and causes poor code since it causes
561 comparisons and tests from non-SI objects to have different code
563 /* Copy to register to avoid generating bad insns by cse
564 from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
565 if (!cse_not_expected
&& GET_CODE (temp
) == MEM
)
566 temp
= copy_to_reg (temp
);
568 do_pending_stack_adjust ();
569 /* Do any postincrements in the expression that was tested. */
572 if (GET_CODE (temp
) == CONST_INT
573 || (GET_CODE (temp
) == CONST_DOUBLE
&& GET_MODE (temp
) == VOIDmode
)
574 || GET_CODE (temp
) == LABEL_REF
)
576 rtx target
= temp
== const0_rtx
? if_false_label
: if_true_label
;
580 else if (GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
581 && ! can_compare_p (NE
, GET_MODE (temp
), ccp_jump
))
582 /* Note swapping the labels gives us not-equal. */
583 do_jump_by_parts_equality_rtx (temp
, if_true_label
, if_false_label
);
584 else if (GET_MODE (temp
) != VOIDmode
)
585 do_compare_rtx_and_jump (temp
, CONST0_RTX (GET_MODE (temp
)),
586 NE
, TREE_UNSIGNED (TREE_TYPE (exp
)),
587 GET_MODE (temp
), NULL_RTX
,
588 if_false_label
, if_true_label
);
593 if (drop_through_label
)
595 /* If do_jump produces code that might be jumped around,
596 do any stack adjusts from that code, before the place
597 where control merges in. */
598 do_pending_stack_adjust ();
599 emit_label (drop_through_label
);
603 /* Given a comparison expression EXP for values too wide to be compared
604 with one insn, test the comparison and jump to the appropriate label.
605 The code of EXP is ignored; we always test GT if SWAP is 0,
606 and LT if SWAP is 1. */
609 do_jump_by_parts_greater (exp
, swap
, if_false_label
, if_true_label
)
612 rtx if_false_label
, if_true_label
;
614 rtx op0
= expand_expr (TREE_OPERAND (exp
, swap
), NULL_RTX
, VOIDmode
, 0);
615 rtx op1
= expand_expr (TREE_OPERAND (exp
, !swap
), NULL_RTX
, VOIDmode
, 0);
616 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
617 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0)));
619 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
, if_true_label
);
622 /* Compare OP0 with OP1, word at a time, in mode MODE.
623 UNSIGNEDP says to do unsigned comparison.
624 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
627 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
, if_true_label
)
628 enum machine_mode mode
;
631 rtx if_false_label
, if_true_label
;
633 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
634 rtx drop_through_label
= 0;
637 if (! if_true_label
|| ! if_false_label
)
638 drop_through_label
= gen_label_rtx ();
640 if_true_label
= drop_through_label
;
641 if (! if_false_label
)
642 if_false_label
= drop_through_label
;
644 /* Compare a word at a time, high order first. */
645 for (i
= 0; i
< nwords
; i
++)
647 rtx op0_word
, op1_word
;
649 if (WORDS_BIG_ENDIAN
)
651 op0_word
= operand_subword_force (op0
, i
, mode
);
652 op1_word
= operand_subword_force (op1
, i
, mode
);
656 op0_word
= operand_subword_force (op0
, nwords
- 1 - i
, mode
);
657 op1_word
= operand_subword_force (op1
, nwords
- 1 - i
, mode
);
660 /* All but high-order word must be compared as unsigned. */
661 do_compare_rtx_and_jump (op0_word
, op1_word
, GT
,
662 (unsignedp
|| i
> 0), word_mode
, NULL_RTX
,
663 NULL_RTX
, if_true_label
);
665 /* Consider lower words only if these are equal. */
666 do_compare_rtx_and_jump (op0_word
, op1_word
, NE
, unsignedp
, word_mode
,
667 NULL_RTX
, NULL_RTX
, if_false_label
);
671 emit_jump (if_false_label
);
672 if (drop_through_label
)
673 emit_label (drop_through_label
);
676 /* Given an EQ_EXPR expression EXP for values too wide to be compared
677 with one insn, test the comparison and jump to the appropriate label. */
680 do_jump_by_parts_equality (exp
, if_false_label
, if_true_label
)
682 rtx if_false_label
, if_true_label
;
684 rtx op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
685 rtx op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
, VOIDmode
, 0);
686 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
687 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
689 rtx drop_through_label
= 0;
691 if (! if_false_label
)
692 drop_through_label
= if_false_label
= gen_label_rtx ();
694 for (i
= 0; i
< nwords
; i
++)
695 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
696 operand_subword_force (op1
, i
, mode
),
697 EQ
, TREE_UNSIGNED (TREE_TYPE (exp
)),
698 word_mode
, NULL_RTX
, if_false_label
, NULL_RTX
);
701 emit_jump (if_true_label
);
702 if (drop_through_label
)
703 emit_label (drop_through_label
);
706 /* Jump according to whether OP0 is 0.
707 We assume that OP0 has an integer mode that is too wide
708 for the available compare insns. */
711 do_jump_by_parts_equality_rtx (op0
, if_false_label
, if_true_label
)
713 rtx if_false_label
, if_true_label
;
715 int nwords
= GET_MODE_SIZE (GET_MODE (op0
)) / UNITS_PER_WORD
;
718 rtx drop_through_label
= 0;
720 /* The fastest way of doing this comparison on almost any machine is to
721 "or" all the words and compare the result. If all have to be loaded
722 from memory and this is a very wide item, it's possible this may
723 be slower, but that's highly unlikely. */
725 part
= gen_reg_rtx (word_mode
);
726 emit_move_insn (part
, operand_subword_force (op0
, 0, GET_MODE (op0
)));
727 for (i
= 1; i
< nwords
&& part
!= 0; i
++)
728 part
= expand_binop (word_mode
, ior_optab
, part
,
729 operand_subword_force (op0
, i
, GET_MODE (op0
)),
730 part
, 1, OPTAB_WIDEN
);
734 do_compare_rtx_and_jump (part
, const0_rtx
, EQ
, 1, word_mode
,
735 NULL_RTX
, if_false_label
, if_true_label
);
740 /* If we couldn't do the "or" simply, do this with a series of compares. */
741 if (! if_false_label
)
742 drop_through_label
= if_false_label
= gen_label_rtx ();
744 for (i
= 0; i
< nwords
; i
++)
745 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, GET_MODE (op0
)),
746 const0_rtx
, EQ
, 1, word_mode
, NULL_RTX
,
747 if_false_label
, NULL_RTX
);
750 emit_jump (if_true_label
);
752 if (drop_through_label
)
753 emit_label (drop_through_label
);
756 /* Generate code for a comparison of OP0 and OP1 with rtx code CODE.
757 (including code to compute the values to be compared)
758 and set (CC0) according to the result.
759 The decision as to signed or unsigned comparison must be made by the caller.
761 We force a stack adjustment unless there are currently
762 things pushed on the stack that aren't yet used.
764 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
768 compare_from_rtx (op0
, op1
, code
, unsignedp
, mode
, size
)
772 enum machine_mode mode
;
778 /* If one operand is constant, make it the second one. Only do this
779 if the other operand is not constant as well. */
781 if (swap_commutative_operands_p (op0
, op1
))
786 code
= swap_condition (code
);
791 op0
= force_not_mem (op0
);
792 op1
= force_not_mem (op1
);
795 do_pending_stack_adjust ();
797 ucode
= unsignedp
? unsigned_condition (code
) : code
;
798 if ((tem
= simplify_relational_operation (ucode
, mode
, op0
, op1
)) != 0)
802 /* There's no need to do this now that combine.c can eliminate lots of
803 sign extensions. This can be less efficient in certain cases on other
806 /* If this is a signed equality comparison, we can do it as an
807 unsigned comparison since zero-extension is cheaper than sign
808 extension and comparisons with zero are done as unsigned. This is
809 the case even on machines that can do fast sign extension, since
810 zero-extension is easier to combine with other operations than
811 sign-extension is. If we are comparing against a constant, we must
812 convert it to what it would look like unsigned. */
813 if ((code
== EQ
|| code
== NE
) && ! unsignedp
814 && GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
)
816 if (GET_CODE (op1
) == CONST_INT
817 && (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
))) != INTVAL (op1
))
818 op1
= GEN_INT (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
)));
823 emit_cmp_insn (op0
, op1
, code
, size
, mode
, unsignedp
);
826 return gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
828 return gen_rtx_fmt_ee (code
, VOIDmode
, op0
, op1
);
832 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
833 The decision as to signed or unsigned comparison must be made by the caller.
835 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
839 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
, size
,
840 if_false_label
, if_true_label
)
844 enum machine_mode mode
;
846 rtx if_false_label
, if_true_label
;
850 int dummy_true_label
= 0;
852 /* Reverse the comparison if that is safe and we want to jump if it is
854 if (! if_true_label
&& ! FLOAT_MODE_P (mode
))
856 if_true_label
= if_false_label
;
858 code
= reverse_condition (code
);
861 /* If one operand is constant, make it the second one. Only do this
862 if the other operand is not constant as well. */
864 if (swap_commutative_operands_p (op0
, op1
))
869 code
= swap_condition (code
);
874 op0
= force_not_mem (op0
);
875 op1
= force_not_mem (op1
);
878 do_pending_stack_adjust ();
880 ucode
= unsignedp
? unsigned_condition (code
) : code
;
881 if ((tem
= simplify_relational_operation (ucode
, mode
, op0
, op1
)) != 0)
883 if (tem
== const_true_rtx
)
886 emit_jump (if_true_label
);
891 emit_jump (if_false_label
);
897 /* There's no need to do this now that combine.c can eliminate lots of
898 sign extensions. This can be less efficient in certain cases on other
901 /* If this is a signed equality comparison, we can do it as an
902 unsigned comparison since zero-extension is cheaper than sign
903 extension and comparisons with zero are done as unsigned. This is
904 the case even on machines that can do fast sign extension, since
905 zero-extension is easier to combine with other operations than
906 sign-extension is. If we are comparing against a constant, we must
907 convert it to what it would look like unsigned. */
908 if ((code
== EQ
|| code
== NE
) && ! unsignedp
909 && GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
)
911 if (GET_CODE (op1
) == CONST_INT
912 && (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
))) != INTVAL (op1
))
913 op1
= GEN_INT (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
)));
920 dummy_true_label
= 1;
921 if_true_label
= gen_label_rtx ();
924 emit_cmp_and_jump_insns (op0
, op1
, code
, size
, mode
, unsignedp
,
928 emit_jump (if_false_label
);
929 if (dummy_true_label
)
930 emit_label (if_true_label
);
933 /* Generate code for a comparison expression EXP (including code to compute
934 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
935 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
936 generated code will drop through.
937 SIGNED_CODE should be the rtx operation for this comparison for
938 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
940 We force a stack adjustment unless there are currently
941 things pushed on the stack that aren't yet used. */
944 do_compare_and_jump (exp
, signed_code
, unsigned_code
, if_false_label
,
947 enum rtx_code signed_code
, unsigned_code
;
948 rtx if_false_label
, if_true_label
;
952 enum machine_mode mode
;
956 /* Don't crash if the comparison was erroneous. */
957 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
958 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ERROR_MARK
)
961 op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
, VOIDmode
, 0);
962 if (TREE_CODE (TREE_OPERAND (exp
, 1)) == ERROR_MARK
)
965 type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
966 mode
= TYPE_MODE (type
);
967 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == INTEGER_CST
968 && (TREE_CODE (TREE_OPERAND (exp
, 1)) != INTEGER_CST
969 || (GET_MODE_BITSIZE (mode
)
970 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
,
973 /* op0 might have been replaced by promoted constant, in which
974 case the type of second argument should be used. */
975 type
= TREE_TYPE (TREE_OPERAND (exp
, 1));
976 mode
= TYPE_MODE (type
);
978 unsignedp
= TREE_UNSIGNED (type
);
979 code
= unsignedp
? unsigned_code
: signed_code
;
981 #ifdef HAVE_canonicalize_funcptr_for_compare
982 /* If function pointers need to be "canonicalized" before they can
983 be reliably compared, then canonicalize them. */
984 if (HAVE_canonicalize_funcptr_for_compare
985 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == POINTER_TYPE
986 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))))
989 rtx new_op0
= gen_reg_rtx (mode
);
991 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0
, op0
));
995 if (HAVE_canonicalize_funcptr_for_compare
996 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 1))) == POINTER_TYPE
997 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 1))))
1000 rtx new_op1
= gen_reg_rtx (mode
);
1002 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1
, op1
));
1007 /* Do any postincrements in the expression that was tested. */
1010 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
,
1012 ? expr_size (TREE_OPERAND (exp
, 0)) : NULL_RTX
),
1013 if_false_label
, if_true_label
);