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 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
165 TREE_OPERAND (exp
, 0)
166 = (*lang_hooks
.unsave_expr_now
) (TREE_OPERAND (exp
, 0));
170 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == COMPONENT_REF
171 || TREE_CODE (TREE_OPERAND (exp
, 0)) == BIT_FIELD_REF
172 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_REF
173 || TREE_CODE (TREE_OPERAND (exp
, 0)) == ARRAY_RANGE_REF
)
176 /* If we are narrowing the operand, we have to do the compare in the
178 if ((TYPE_PRECISION (TREE_TYPE (exp
))
179 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
181 case NON_LVALUE_EXPR
:
187 /* These cannot change zero->nonzero or vice versa. */
188 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
191 case WITH_RECORD_EXPR
:
192 /* Put the object on the placeholder list, recurse through our first
193 operand, and pop the list. */
194 placeholder_list
= tree_cons (TREE_OPERAND (exp
, 1), NULL_TREE
,
196 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
197 placeholder_list
= TREE_CHAIN (placeholder_list
);
201 /* This is never less insns than evaluating the PLUS_EXPR followed by
202 a test and can be longer if the test is eliminated. */
204 /* Reduce to minus. */
205 exp
= build (MINUS_EXPR
, TREE_TYPE (exp
),
206 TREE_OPERAND (exp
, 0),
207 fold (build1 (NEGATE_EXPR
, TREE_TYPE (TREE_OPERAND (exp
, 1)),
208 TREE_OPERAND (exp
, 1))));
209 /* Process as MINUS. */
213 /* Nonzero iff operands of minus differ. */
214 do_compare_and_jump (build (NE_EXPR
, TREE_TYPE (exp
),
215 TREE_OPERAND (exp
, 0),
216 TREE_OPERAND (exp
, 1)),
217 NE
, NE
, if_false_label
, if_true_label
);
221 /* If we are AND'ing with a small constant, do this comparison in the
222 smallest type that fits. If the machine doesn't have comparisons
223 that small, it will be converted back to the wider comparison.
224 This helps if we are testing the sign bit of a narrower object.
225 combine can't do this for us because it can't know whether a
226 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
228 if (! SLOW_BYTE_ACCESS
229 && TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
230 && TYPE_PRECISION (TREE_TYPE (exp
)) <= HOST_BITS_PER_WIDE_INT
231 && (i
= tree_floor_log2 (TREE_OPERAND (exp
, 1))) >= 0
232 && (mode
= mode_for_size (i
+ 1, MODE_INT
, 0)) != BLKmode
233 && (type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 1)) != 0
234 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
235 && (cmp_optab
->handlers
[(int) TYPE_MODE (type
)].insn_code
236 != CODE_FOR_nothing
))
238 do_jump (convert (type
, exp
), if_false_label
, if_true_label
);
244 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
247 case TRUTH_ANDIF_EXPR
:
248 if (if_false_label
== 0)
249 if_false_label
= drop_through_label
= gen_label_rtx ();
250 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, NULL_RTX
);
251 start_cleanup_deferral ();
252 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
253 end_cleanup_deferral ();
256 case TRUTH_ORIF_EXPR
:
257 if (if_true_label
== 0)
258 if_true_label
= drop_through_label
= gen_label_rtx ();
259 do_jump (TREE_OPERAND (exp
, 0), NULL_RTX
, if_true_label
);
260 start_cleanup_deferral ();
261 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
262 end_cleanup_deferral ();
267 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
, 0);
268 preserve_temp_slots (NULL_RTX
);
272 do_pending_stack_adjust ();
273 do_jump (TREE_OPERAND (exp
, 1), if_false_label
, if_true_label
);
279 case ARRAY_RANGE_REF
:
281 HOST_WIDE_INT bitsize
, bitpos
;
283 enum machine_mode mode
;
288 /* Get description of this reference. We don't actually care
289 about the underlying object here. */
290 get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode
,
291 &unsignedp
, &volatilep
);
293 type
= (*lang_hooks
.types
.type_for_size
) (bitsize
, unsignedp
);
294 if (! SLOW_BYTE_ACCESS
295 && type
!= 0 && bitsize
>= 0
296 && TYPE_PRECISION (type
) < TYPE_PRECISION (TREE_TYPE (exp
))
297 && (cmp_optab
->handlers
[(int) TYPE_MODE (type
)].insn_code
298 != CODE_FOR_nothing
))
300 do_jump (convert (type
, exp
), if_false_label
, if_true_label
);
307 /* Do (a ? 1 : 0) and (a ? 0 : 1) as special cases. */
308 if (integer_onep (TREE_OPERAND (exp
, 1))
309 && integer_zerop (TREE_OPERAND (exp
, 2)))
310 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
312 else if (integer_zerop (TREE_OPERAND (exp
, 1))
313 && integer_onep (TREE_OPERAND (exp
, 2)))
314 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
318 rtx label1
= gen_label_rtx ();
319 drop_through_label
= gen_label_rtx ();
321 do_jump (TREE_OPERAND (exp
, 0), label1
, NULL_RTX
);
323 start_cleanup_deferral ();
324 /* Now the THEN-expression. */
325 do_jump (TREE_OPERAND (exp
, 1),
326 if_false_label
? if_false_label
: drop_through_label
,
327 if_true_label
? if_true_label
: drop_through_label
);
328 /* In case the do_jump just above never jumps. */
329 do_pending_stack_adjust ();
332 /* Now the ELSE-expression. */
333 do_jump (TREE_OPERAND (exp
, 2),
334 if_false_label
? if_false_label
: drop_through_label
,
335 if_true_label
? if_true_label
: drop_through_label
);
336 end_cleanup_deferral ();
342 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
344 if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_FLOAT
345 || GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_INT
)
347 tree exp0
= save_expr (TREE_OPERAND (exp
, 0));
348 tree exp1
= save_expr (TREE_OPERAND (exp
, 1));
351 (build (TRUTH_ANDIF_EXPR
, TREE_TYPE (exp
),
352 fold (build (EQ_EXPR
, TREE_TYPE (exp
),
353 fold (build1 (REALPART_EXPR
,
354 TREE_TYPE (inner_type
),
356 fold (build1 (REALPART_EXPR
,
357 TREE_TYPE (inner_type
),
359 fold (build (EQ_EXPR
, TREE_TYPE (exp
),
360 fold (build1 (IMAGPART_EXPR
,
361 TREE_TYPE (inner_type
),
363 fold (build1 (IMAGPART_EXPR
,
364 TREE_TYPE (inner_type
),
366 if_false_label
, if_true_label
);
369 else if (integer_zerop (TREE_OPERAND (exp
, 1)))
370 do_jump (TREE_OPERAND (exp
, 0), if_true_label
, if_false_label
);
372 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
373 && !can_compare_p (EQ
, TYPE_MODE (inner_type
), ccp_jump
))
374 do_jump_by_parts_equality (exp
, if_false_label
, if_true_label
);
376 do_compare_and_jump (exp
, EQ
, EQ
, if_false_label
, if_true_label
);
382 tree inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
384 if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_FLOAT
385 || GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_COMPLEX_INT
)
387 tree exp0
= save_expr (TREE_OPERAND (exp
, 0));
388 tree exp1
= save_expr (TREE_OPERAND (exp
, 1));
391 (build (TRUTH_ORIF_EXPR
, TREE_TYPE (exp
),
392 fold (build (NE_EXPR
, TREE_TYPE (exp
),
393 fold (build1 (REALPART_EXPR
,
394 TREE_TYPE (inner_type
),
396 fold (build1 (REALPART_EXPR
,
397 TREE_TYPE (inner_type
),
399 fold (build (NE_EXPR
, TREE_TYPE (exp
),
400 fold (build1 (IMAGPART_EXPR
,
401 TREE_TYPE (inner_type
),
403 fold (build1 (IMAGPART_EXPR
,
404 TREE_TYPE (inner_type
),
406 if_false_label
, if_true_label
);
409 else if (integer_zerop (TREE_OPERAND (exp
, 1)))
410 do_jump (TREE_OPERAND (exp
, 0), if_false_label
, if_true_label
);
412 else if (GET_MODE_CLASS (TYPE_MODE (inner_type
)) == MODE_INT
413 && !can_compare_p (NE
, TYPE_MODE (inner_type
), ccp_jump
))
414 do_jump_by_parts_equality (exp
, if_true_label
, if_false_label
);
416 do_compare_and_jump (exp
, NE
, NE
, if_false_label
, if_true_label
);
421 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
422 if (GET_MODE_CLASS (mode
) == MODE_INT
423 && ! can_compare_p (LT
, mode
, ccp_jump
))
424 do_jump_by_parts_greater (exp
, 1, if_false_label
, if_true_label
);
426 do_compare_and_jump (exp
, LT
, LTU
, if_false_label
, if_true_label
);
430 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
431 if (GET_MODE_CLASS (mode
) == MODE_INT
432 && ! can_compare_p (LE
, mode
, ccp_jump
))
433 do_jump_by_parts_greater (exp
, 0, if_true_label
, if_false_label
);
435 do_compare_and_jump (exp
, LE
, LEU
, if_false_label
, if_true_label
);
439 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
440 if (GET_MODE_CLASS (mode
) == MODE_INT
441 && ! can_compare_p (GT
, mode
, ccp_jump
))
442 do_jump_by_parts_greater (exp
, 0, if_false_label
, if_true_label
);
444 do_compare_and_jump (exp
, GT
, GTU
, if_false_label
, if_true_label
);
448 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
449 if (GET_MODE_CLASS (mode
) == MODE_INT
450 && ! can_compare_p (GE
, mode
, ccp_jump
))
451 do_jump_by_parts_greater (exp
, 1, if_true_label
, if_false_label
);
453 do_compare_and_jump (exp
, GE
, GEU
, if_false_label
, if_true_label
);
459 enum rtx_code cmp
, rcmp
;
462 if (code
== UNORDERED_EXPR
)
463 cmp
= UNORDERED
, rcmp
= ORDERED
;
465 cmp
= ORDERED
, rcmp
= UNORDERED
;
466 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
469 if (! can_compare_p (cmp
, mode
, ccp_jump
)
470 && (can_compare_p (rcmp
, mode
, ccp_jump
)
471 /* If the target doesn't provide either UNORDERED or ORDERED
472 comparisons, canonicalize on UNORDERED for the library. */
473 || rcmp
== UNORDERED
))
477 do_compare_and_jump (exp
, cmp
, cmp
, if_false_label
, if_true_label
);
479 do_compare_and_jump (exp
, rcmp
, rcmp
, if_true_label
, if_false_label
);
484 enum rtx_code rcode1
;
485 enum tree_code tcode2
;
509 mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
510 if (can_compare_p (rcode1
, mode
, ccp_jump
))
511 do_compare_and_jump (exp
, rcode1
, rcode1
, if_false_label
,
515 tree op0
= save_expr (TREE_OPERAND (exp
, 0));
516 tree op1
= save_expr (TREE_OPERAND (exp
, 1));
519 /* If the target doesn't support combined unordered
520 compares, decompose into UNORDERED + comparison. */
521 cmp0
= fold (build (UNORDERED_EXPR
, TREE_TYPE (exp
), op0
, op1
));
522 cmp1
= fold (build (tcode2
, TREE_TYPE (exp
), op0
, op1
));
523 exp
= build (TRUTH_ORIF_EXPR
, TREE_TYPE (exp
), cmp0
, cmp1
);
524 do_jump (exp
, if_false_label
, if_true_label
);
530 __builtin_expect (<test>, 0) and
531 __builtin_expect (<test>, 1)
533 We need to do this here, so that <test> is not converted to a SCC
534 operation on machines that use condition code registers and COMPARE
535 like the PowerPC, and then the jump is done based on whether the SCC
536 operation produced a 1 or 0. */
538 /* Check for a built-in function. */
539 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
541 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
542 tree arglist
= TREE_OPERAND (exp
, 1);
544 if (TREE_CODE (fndecl
) == FUNCTION_DECL
545 && DECL_BUILT_IN (fndecl
)
546 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_EXPECT
547 && arglist
!= NULL_TREE
548 && TREE_CHAIN (arglist
) != NULL_TREE
)
550 rtx seq
= expand_builtin_expect_jump (exp
, if_false_label
,
560 /* fall through and generate the normal code. */
564 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, 0);
566 /* This is not needed any more and causes poor code since it causes
567 comparisons and tests from non-SI objects to have different code
569 /* Copy to register to avoid generating bad insns by cse
570 from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
571 if (!cse_not_expected
&& GET_CODE (temp
) == MEM
)
572 temp
= copy_to_reg (temp
);
574 do_pending_stack_adjust ();
575 /* Do any postincrements in the expression that was tested. */
578 if (GET_CODE (temp
) == CONST_INT
579 || (GET_CODE (temp
) == CONST_DOUBLE
&& GET_MODE (temp
) == VOIDmode
)
580 || GET_CODE (temp
) == LABEL_REF
)
582 rtx target
= temp
== const0_rtx
? if_false_label
: if_true_label
;
586 else if (GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
587 && ! can_compare_p (NE
, GET_MODE (temp
), ccp_jump
))
588 /* Note swapping the labels gives us not-equal. */
589 do_jump_by_parts_equality_rtx (temp
, if_true_label
, if_false_label
);
590 else if (GET_MODE (temp
) != VOIDmode
)
592 /* The RTL optimizers prefer comparisons against pseudos. */
593 if (GET_CODE (temp
) == SUBREG
)
594 temp
= copy_to_reg (temp
);
595 do_compare_rtx_and_jump (temp
, CONST0_RTX (GET_MODE (temp
)),
596 NE
, TREE_UNSIGNED (TREE_TYPE (exp
)),
597 GET_MODE (temp
), NULL_RTX
,
598 if_false_label
, if_true_label
);
604 if (drop_through_label
)
606 /* If do_jump produces code that might be jumped around,
607 do any stack adjusts from that code, before the place
608 where control merges in. */
609 do_pending_stack_adjust ();
610 emit_label (drop_through_label
);
614 /* Given a comparison expression EXP for values too wide to be compared
615 with one insn, test the comparison and jump to the appropriate label.
616 The code of EXP is ignored; we always test GT if SWAP is 0,
617 and LT if SWAP is 1. */
620 do_jump_by_parts_greater (exp
, swap
, if_false_label
, if_true_label
)
623 rtx if_false_label
, if_true_label
;
625 rtx op0
= expand_expr (TREE_OPERAND (exp
, swap
), NULL_RTX
, VOIDmode
, 0);
626 rtx op1
= expand_expr (TREE_OPERAND (exp
, !swap
), NULL_RTX
, VOIDmode
, 0);
627 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
628 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0)));
630 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
, if_true_label
);
633 /* Compare OP0 with OP1, word at a time, in mode MODE.
634 UNSIGNEDP says to do unsigned comparison.
635 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
638 do_jump_by_parts_greater_rtx (mode
, unsignedp
, op0
, op1
, if_false_label
, if_true_label
)
639 enum machine_mode mode
;
642 rtx if_false_label
, if_true_label
;
644 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
645 rtx drop_through_label
= 0;
648 if (! if_true_label
|| ! if_false_label
)
649 drop_through_label
= gen_label_rtx ();
651 if_true_label
= drop_through_label
;
652 if (! if_false_label
)
653 if_false_label
= drop_through_label
;
655 /* Compare a word at a time, high order first. */
656 for (i
= 0; i
< nwords
; i
++)
658 rtx op0_word
, op1_word
;
660 if (WORDS_BIG_ENDIAN
)
662 op0_word
= operand_subword_force (op0
, i
, mode
);
663 op1_word
= operand_subword_force (op1
, i
, mode
);
667 op0_word
= operand_subword_force (op0
, nwords
- 1 - i
, mode
);
668 op1_word
= operand_subword_force (op1
, nwords
- 1 - i
, mode
);
671 /* All but high-order word must be compared as unsigned. */
672 do_compare_rtx_and_jump (op0_word
, op1_word
, GT
,
673 (unsignedp
|| i
> 0), word_mode
, NULL_RTX
,
674 NULL_RTX
, if_true_label
);
676 /* Consider lower words only if these are equal. */
677 do_compare_rtx_and_jump (op0_word
, op1_word
, NE
, unsignedp
, word_mode
,
678 NULL_RTX
, NULL_RTX
, if_false_label
);
682 emit_jump (if_false_label
);
683 if (drop_through_label
)
684 emit_label (drop_through_label
);
687 /* Given an EQ_EXPR expression EXP for values too wide to be compared
688 with one insn, test the comparison and jump to the appropriate label. */
691 do_jump_by_parts_equality (exp
, if_false_label
, if_true_label
)
693 rtx if_false_label
, if_true_label
;
695 rtx op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
696 rtx op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
, VOIDmode
, 0);
697 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
698 int nwords
= (GET_MODE_SIZE (mode
) / UNITS_PER_WORD
);
700 rtx drop_through_label
= 0;
702 if (! if_false_label
)
703 drop_through_label
= if_false_label
= gen_label_rtx ();
705 for (i
= 0; i
< nwords
; i
++)
706 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, mode
),
707 operand_subword_force (op1
, i
, mode
),
708 EQ
, TREE_UNSIGNED (TREE_TYPE (exp
)),
709 word_mode
, NULL_RTX
, if_false_label
, NULL_RTX
);
712 emit_jump (if_true_label
);
713 if (drop_through_label
)
714 emit_label (drop_through_label
);
717 /* Jump according to whether OP0 is 0.
718 We assume that OP0 has an integer mode that is too wide
719 for the available compare insns. */
722 do_jump_by_parts_equality_rtx (op0
, if_false_label
, if_true_label
)
724 rtx if_false_label
, if_true_label
;
726 int nwords
= GET_MODE_SIZE (GET_MODE (op0
)) / UNITS_PER_WORD
;
729 rtx drop_through_label
= 0;
731 /* The fastest way of doing this comparison on almost any machine is to
732 "or" all the words and compare the result. If all have to be loaded
733 from memory and this is a very wide item, it's possible this may
734 be slower, but that's highly unlikely. */
736 part
= gen_reg_rtx (word_mode
);
737 emit_move_insn (part
, operand_subword_force (op0
, 0, GET_MODE (op0
)));
738 for (i
= 1; i
< nwords
&& part
!= 0; i
++)
739 part
= expand_binop (word_mode
, ior_optab
, part
,
740 operand_subword_force (op0
, i
, GET_MODE (op0
)),
741 part
, 1, OPTAB_WIDEN
);
745 do_compare_rtx_and_jump (part
, const0_rtx
, EQ
, 1, word_mode
,
746 NULL_RTX
, if_false_label
, if_true_label
);
751 /* If we couldn't do the "or" simply, do this with a series of compares. */
752 if (! if_false_label
)
753 drop_through_label
= if_false_label
= gen_label_rtx ();
755 for (i
= 0; i
< nwords
; i
++)
756 do_compare_rtx_and_jump (operand_subword_force (op0
, i
, GET_MODE (op0
)),
757 const0_rtx
, EQ
, 1, word_mode
, NULL_RTX
,
758 if_false_label
, NULL_RTX
);
761 emit_jump (if_true_label
);
763 if (drop_through_label
)
764 emit_label (drop_through_label
);
767 /* Generate code for a comparison of OP0 and OP1 with rtx code CODE.
768 (including code to compute the values to be compared)
769 and set (CC0) according to the result.
770 The decision as to signed or unsigned comparison must be made by the caller.
772 We force a stack adjustment unless there are currently
773 things pushed on the stack that aren't yet used.
775 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
779 compare_from_rtx (op0
, op1
, code
, unsignedp
, mode
, size
)
783 enum machine_mode mode
;
789 /* If one operand is constant, make it the second one. Only do this
790 if the other operand is not constant as well. */
792 if (swap_commutative_operands_p (op0
, op1
))
797 code
= swap_condition (code
);
802 op0
= force_not_mem (op0
);
803 op1
= force_not_mem (op1
);
806 do_pending_stack_adjust ();
808 ucode
= unsignedp
? unsigned_condition (code
) : code
;
809 if ((tem
= simplify_relational_operation (ucode
, mode
, op0
, op1
)) != 0)
813 /* There's no need to do this now that combine.c can eliminate lots of
814 sign extensions. This can be less efficient in certain cases on other
817 /* If this is a signed equality comparison, we can do it as an
818 unsigned comparison since zero-extension is cheaper than sign
819 extension and comparisons with zero are done as unsigned. This is
820 the case even on machines that can do fast sign extension, since
821 zero-extension is easier to combine with other operations than
822 sign-extension is. If we are comparing against a constant, we must
823 convert it to what it would look like unsigned. */
824 if ((code
== EQ
|| code
== NE
) && ! unsignedp
825 && GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
)
827 if (GET_CODE (op1
) == CONST_INT
828 && (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
))) != INTVAL (op1
))
829 op1
= GEN_INT (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
)));
834 emit_cmp_insn (op0
, op1
, code
, size
, mode
, unsignedp
);
837 return gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
839 return gen_rtx_fmt_ee (code
, VOIDmode
, op0
, op1
);
843 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
844 The decision as to signed or unsigned comparison must be made by the caller.
846 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
850 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
, size
,
851 if_false_label
, if_true_label
)
855 enum machine_mode mode
;
857 rtx if_false_label
, if_true_label
;
861 int dummy_true_label
= 0;
863 /* Reverse the comparison if that is safe and we want to jump if it is
865 if (! if_true_label
&& ! FLOAT_MODE_P (mode
))
867 if_true_label
= if_false_label
;
869 code
= reverse_condition (code
);
872 /* If one operand is constant, make it the second one. Only do this
873 if the other operand is not constant as well. */
875 if (swap_commutative_operands_p (op0
, op1
))
880 code
= swap_condition (code
);
885 op0
= force_not_mem (op0
);
886 op1
= force_not_mem (op1
);
889 do_pending_stack_adjust ();
891 ucode
= unsignedp
? unsigned_condition (code
) : code
;
892 if ((tem
= simplify_relational_operation (ucode
, mode
, op0
, op1
)) != 0)
894 if (tem
== const_true_rtx
)
897 emit_jump (if_true_label
);
902 emit_jump (if_false_label
);
908 /* There's no need to do this now that combine.c can eliminate lots of
909 sign extensions. This can be less efficient in certain cases on other
912 /* If this is a signed equality comparison, we can do it as an
913 unsigned comparison since zero-extension is cheaper than sign
914 extension and comparisons with zero are done as unsigned. This is
915 the case even on machines that can do fast sign extension, since
916 zero-extension is easier to combine with other operations than
917 sign-extension is. If we are comparing against a constant, we must
918 convert it to what it would look like unsigned. */
919 if ((code
== EQ
|| code
== NE
) && ! unsignedp
920 && GET_MODE_BITSIZE (GET_MODE (op0
)) <= HOST_BITS_PER_WIDE_INT
)
922 if (GET_CODE (op1
) == CONST_INT
923 && (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
))) != INTVAL (op1
))
924 op1
= GEN_INT (INTVAL (op1
) & GET_MODE_MASK (GET_MODE (op0
)));
931 dummy_true_label
= 1;
932 if_true_label
= gen_label_rtx ();
935 emit_cmp_and_jump_insns (op0
, op1
, code
, size
, mode
, unsignedp
,
939 emit_jump (if_false_label
);
940 if (dummy_true_label
)
941 emit_label (if_true_label
);
944 /* Generate code for a comparison expression EXP (including code to compute
945 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
946 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
947 generated code will drop through.
948 SIGNED_CODE should be the rtx operation for this comparison for
949 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
951 We force a stack adjustment unless there are currently
952 things pushed on the stack that aren't yet used. */
955 do_compare_and_jump (exp
, signed_code
, unsigned_code
, if_false_label
,
958 enum rtx_code signed_code
, unsigned_code
;
959 rtx if_false_label
, if_true_label
;
963 enum machine_mode mode
;
967 /* Don't crash if the comparison was erroneous. */
968 op0
= expand_expr (TREE_OPERAND (exp
, 0), NULL_RTX
, VOIDmode
, 0);
969 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ERROR_MARK
)
972 op1
= expand_expr (TREE_OPERAND (exp
, 1), NULL_RTX
, VOIDmode
, 0);
973 if (TREE_CODE (TREE_OPERAND (exp
, 1)) == ERROR_MARK
)
976 type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
977 mode
= TYPE_MODE (type
);
978 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == INTEGER_CST
979 && (TREE_CODE (TREE_OPERAND (exp
, 1)) != INTEGER_CST
980 || (GET_MODE_BITSIZE (mode
)
981 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
,
984 /* op0 might have been replaced by promoted constant, in which
985 case the type of second argument should be used. */
986 type
= TREE_TYPE (TREE_OPERAND (exp
, 1));
987 mode
= TYPE_MODE (type
);
989 unsignedp
= TREE_UNSIGNED (type
);
990 code
= unsignedp
? unsigned_code
: signed_code
;
992 #ifdef HAVE_canonicalize_funcptr_for_compare
993 /* If function pointers need to be "canonicalized" before they can
994 be reliably compared, then canonicalize them. */
995 if (HAVE_canonicalize_funcptr_for_compare
996 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == POINTER_TYPE
997 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))))
1000 rtx new_op0
= gen_reg_rtx (mode
);
1002 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0
, op0
));
1006 if (HAVE_canonicalize_funcptr_for_compare
1007 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 1))) == POINTER_TYPE
1008 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 1))))
1011 rtx new_op1
= gen_reg_rtx (mode
);
1013 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1
, op1
));
1018 /* Do any postincrements in the expression that was tested. */
1021 do_compare_rtx_and_jump (op0
, op1
, code
, unsignedp
, mode
,
1023 ? expr_size (TREE_OPERAND (exp
, 0)) : NULL_RTX
),
1024 if_false_label
, if_true_label
);