]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dojump.c
[62/77] Big machine_mode to scalar_int_mode replacement
[thirdparty/gcc.git] / gcc / dojump.c
CommitLineData
1cff8964 1/* Convert tree expression to rtl instructions, for GNU compiler.
cbe34bb5 2 Copyright (C) 1988-2017 Free Software Foundation, Inc.
1cff8964
AE
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
1cff8964
AE
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
1cff8964
AE
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
c7131fb2 23#include "backend.h"
957060b5 24#include "target.h"
1cff8964
AE
25#include "rtl.h"
26#include "tree.h"
957060b5 27#include "predict.h"
4d0cdd0c 28#include "memmodel.h"
957060b5 29#include "tm_p.h"
957060b5
AM
30#include "optabs.h"
31#include "emit-rtl.h"
40e23961 32#include "fold-const.h"
d8a2d370 33#include "stor-layout.h"
1cff8964 34/* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
36566b39
PK
35#include "dojump.h"
36#include "explow.h"
1cff8964 37#include "expr.h"
1cff8964
AE
38#include "langhooks.h"
39
095a2d76 40static bool prefer_and_bit_test (scalar_int_mode, int);
d787ba56 41static void do_jump_by_parts_greater (scalar_int_mode, tree, tree, int,
357067f2
JH
42 rtx_code_label *, rtx_code_label *,
43 profile_probability);
d787ba56
RS
44static void do_jump_by_parts_equality (scalar_int_mode, tree, tree,
45 rtx_code_label *, rtx_code_label *,
46 profile_probability);
1476d1bd 47static void do_compare_and_jump (tree, tree, enum rtx_code, enum rtx_code,
357067f2
JH
48 rtx_code_label *, rtx_code_label *,
49 profile_probability);
1cff8964
AE
50
51/* At the start of a function, record that we have no previously-pushed
52 arguments waiting to be popped. */
53
54void
7080f735 55init_pending_stack_adjust (void)
1cff8964
AE
56{
57 pending_stack_adjust = 0;
58}
59
a494ed43
EB
60/* Discard any pending stack adjustment. This avoid relying on the
61 RTL optimizers to remove useless adjustments when we know the
62 stack pointer value is dead. */
83f676b3
RS
63void
64discard_pending_stack_adjust (void)
a494ed43
EB
65{
66 stack_pointer_delta -= pending_stack_adjust;
67 pending_stack_adjust = 0;
68}
69
1cff8964
AE
70/* When exiting from function, if safe, clear out any pending stack adjust
71 so the adjustment won't get done.
72
73 Note, if the current function calls alloca, then it must have a
74 frame pointer regardless of the value of flag_omit_frame_pointer. */
75
76void
7080f735 77clear_pending_stack_adjust (void)
1cff8964 78{
1cff8964 79 if (optimize > 0
e3b5732b 80 && (! flag_omit_frame_pointer || cfun->calls_alloca)
c37f4ba4 81 && EXIT_IGNORE_STACK)
a494ed43 82 discard_pending_stack_adjust ();
1cff8964
AE
83}
84
85/* Pop any previously-pushed arguments that have not been popped yet. */
86
87void
7080f735 88do_pending_stack_adjust (void)
1cff8964
AE
89{
90 if (inhibit_defer_pop == 0)
91 {
92 if (pending_stack_adjust != 0)
93 adjust_stack (GEN_INT (pending_stack_adjust));
94 pending_stack_adjust = 0;
95 }
96}
7f2f0a01
JJ
97
98/* Remember pending_stack_adjust/stack_pointer_delta.
99 To be used around code that may call do_pending_stack_adjust (),
100 but the generated code could be discarded e.g. using delete_insns_since. */
101
102void
103save_pending_stack_adjust (saved_pending_stack_adjust *save)
104{
105 save->x_pending_stack_adjust = pending_stack_adjust;
106 save->x_stack_pointer_delta = stack_pointer_delta;
107}
108
109/* Restore the saved pending_stack_adjust/stack_pointer_delta. */
110
111void
112restore_pending_stack_adjust (saved_pending_stack_adjust *save)
113{
114 if (inhibit_defer_pop == 0)
115 {
116 pending_stack_adjust = save->x_pending_stack_adjust;
117 stack_pointer_delta = save->x_stack_pointer_delta;
118 }
119}
1cff8964
AE
120\f
121/* Expand conditional expressions. */
122
1476d1bd 123/* Generate code to evaluate EXP and jump to LABEL if the value is zero. */
1cff8964
AE
124
125void
357067f2 126jumpifnot (tree exp, rtx_code_label *label, profile_probability prob)
1cff8964 127{
357067f2 128 do_jump (exp, label, NULL, prob.invert ());
1cff8964
AE
129}
130
4df62c77 131void
1476d1bd 132jumpifnot_1 (enum tree_code code, tree op0, tree op1, rtx_code_label *label,
357067f2 133 profile_probability prob)
4df62c77 134{
357067f2 135 do_jump_1 (code, op0, op1, label, NULL, prob.invert ());
4df62c77
MM
136}
137
1cff8964
AE
138/* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
139
140void
357067f2 141jumpif (tree exp, rtx_code_label *label, profile_probability prob)
1cff8964 142{
1476d1bd 143 do_jump (exp, NULL, label, prob);
1cff8964
AE
144}
145
4df62c77 146void
1476d1bd 147jumpif_1 (enum tree_code code, tree op0, tree op1,
357067f2 148 rtx_code_label *label, profile_probability prob)
4df62c77 149{
1476d1bd 150 do_jump_1 (code, op0, op1, NULL, label, prob);
4df62c77
MM
151}
152
dbf833ee
RS
153/* Used internally by prefer_and_bit_test. */
154
155static GTY(()) rtx and_reg;
156static GTY(()) rtx and_test;
157static GTY(()) rtx shift_test;
158
159/* Compare the relative costs of "(X & (1 << BITNUM))" and "(X >> BITNUM) & 1",
160 where X is an arbitrary register of mode MODE. Return true if the former
161 is preferred. */
162
163static bool
095a2d76 164prefer_and_bit_test (scalar_int_mode mode, int bitnum)
dbf833ee 165{
68f932c4 166 bool speed_p;
807e902e 167 wide_int mask = wi::set_bit_in_zero (bitnum, GET_MODE_PRECISION (mode));
68f932c4 168
dbf833ee
RS
169 if (and_test == 0)
170 {
171 /* Set up rtxes for the two variations. Use NULL as a placeholder
172 for the BITNUM-based constants. */
c3dc5e66 173 and_reg = gen_rtx_REG (mode, LAST_VIRTUAL_REGISTER + 1);
dbf833ee
RS
174 and_test = gen_rtx_AND (mode, and_reg, NULL);
175 shift_test = gen_rtx_AND (mode, gen_rtx_ASHIFTRT (mode, and_reg, NULL),
176 const1_rtx);
177 }
178 else
179 {
180 /* Change the mode of the previously-created rtxes. */
181 PUT_MODE (and_reg, mode);
182 PUT_MODE (and_test, mode);
183 PUT_MODE (shift_test, mode);
184 PUT_MODE (XEXP (shift_test, 0), mode);
185 }
186
187 /* Fill in the integers. */
807e902e 188 XEXP (and_test, 1) = immed_wide_int_const (mask, mode);
dbf833ee
RS
189 XEXP (XEXP (shift_test, 0), 1) = GEN_INT (bitnum);
190
68f932c4 191 speed_p = optimize_insn_for_speed_p ();
e548c9df
AM
192 return (rtx_cost (and_test, mode, IF_THEN_ELSE, 0, speed_p)
193 <= rtx_cost (shift_test, mode, IF_THEN_ELSE, 0, speed_p));
dbf833ee
RS
194}
195
4df62c77 196/* Subroutine of do_jump, dealing with exploded comparisons of the type
40e90eac 197 OP0 CODE OP1 . IF_FALSE_LABEL and IF_TRUE_LABEL like in do_jump.
357067f2 198 PROB is probability of jump to if_true_label. */
4df62c77
MM
199
200void
201do_jump_1 (enum tree_code code, tree op0, tree op1,
1476d1bd 202 rtx_code_label *if_false_label, rtx_code_label *if_true_label,
357067f2 203 profile_probability prob)
4df62c77 204{
ef4bddc2 205 machine_mode mode;
19f8b229 206 rtx_code_label *drop_through_label = 0;
b4206259 207 scalar_int_mode int_mode;
4df62c77
MM
208
209 switch (code)
210 {
211 case EQ_EXPR:
212 {
213 tree inner_type = TREE_TYPE (op0);
214
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);
219
220 if (integer_zerop (op1))
357067f2
JH
221 do_jump (op0, if_true_label, if_false_label,
222 prob.invert ());
b4206259
RS
223 else if (is_int_mode (TYPE_MODE (inner_type), &int_mode)
224 && !can_compare_p (EQ, int_mode, ccp_jump))
d787ba56
RS
225 do_jump_by_parts_equality (int_mode, op0, op1, if_false_label,
226 if_true_label, prob);
4df62c77 227 else
40e90eac
JJ
228 do_compare_and_jump (op0, op1, EQ, EQ, if_false_label, if_true_label,
229 prob);
4df62c77
MM
230 break;
231 }
232
233 case NE_EXPR:
234 {
235 tree inner_type = TREE_TYPE (op0);
236
237 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type))
238 != MODE_COMPLEX_FLOAT);
239 gcc_assert (GET_MODE_CLASS (TYPE_MODE (inner_type))
240 != MODE_COMPLEX_INT);
241
242 if (integer_zerop (op1))
40e90eac 243 do_jump (op0, if_false_label, if_true_label, prob);
b4206259
RS
244 else if (is_int_mode (TYPE_MODE (inner_type), &int_mode)
245 && !can_compare_p (NE, int_mode, ccp_jump))
d787ba56
RS
246 do_jump_by_parts_equality (int_mode, op0, op1, if_true_label,
247 if_false_label, prob.invert ());
4df62c77 248 else
40e90eac
JJ
249 do_compare_and_jump (op0, op1, NE, NE, if_false_label, if_true_label,
250 prob);
4df62c77
MM
251 break;
252 }
253
254 case LT_EXPR:
255 mode = TYPE_MODE (TREE_TYPE (op0));
b4206259
RS
256 if (is_int_mode (mode, &int_mode)
257 && ! can_compare_p (LT, int_mode, ccp_jump))
d787ba56 258 do_jump_by_parts_greater (int_mode, op0, op1, 1, if_false_label,
b4206259 259 if_true_label, prob);
4df62c77 260 else
40e90eac
JJ
261 do_compare_and_jump (op0, op1, LT, LTU, if_false_label, if_true_label,
262 prob);
4df62c77
MM
263 break;
264
265 case LE_EXPR:
266 mode = TYPE_MODE (TREE_TYPE (op0));
b4206259
RS
267 if (is_int_mode (mode, &int_mode)
268 && ! can_compare_p (LE, int_mode, ccp_jump))
d787ba56
RS
269 do_jump_by_parts_greater (int_mode, op0, op1, 0, if_true_label,
270 if_false_label, prob.invert ());
4df62c77 271 else
40e90eac
JJ
272 do_compare_and_jump (op0, op1, LE, LEU, if_false_label, if_true_label,
273 prob);
4df62c77
MM
274 break;
275
276 case GT_EXPR:
277 mode = TYPE_MODE (TREE_TYPE (op0));
b4206259
RS
278 if (is_int_mode (mode, &int_mode)
279 && ! can_compare_p (GT, int_mode, ccp_jump))
d787ba56 280 do_jump_by_parts_greater (int_mode, op0, op1, 0, if_false_label,
b4206259 281 if_true_label, prob);
4df62c77 282 else
40e90eac
JJ
283 do_compare_and_jump (op0, op1, GT, GTU, if_false_label, if_true_label,
284 prob);
4df62c77
MM
285 break;
286
287 case GE_EXPR:
288 mode = TYPE_MODE (TREE_TYPE (op0));
b4206259
RS
289 if (is_int_mode (mode, &int_mode)
290 && ! can_compare_p (GE, int_mode, ccp_jump))
d787ba56
RS
291 do_jump_by_parts_greater (int_mode, op0, op1, 1, if_true_label,
292 if_false_label, prob.invert ());
4df62c77 293 else
40e90eac
JJ
294 do_compare_and_jump (op0, op1, GE, GEU, if_false_label, if_true_label,
295 prob);
4df62c77
MM
296 break;
297
298 case ORDERED_EXPR:
299 do_compare_and_jump (op0, op1, ORDERED, ORDERED,
40e90eac 300 if_false_label, if_true_label, prob);
4df62c77
MM
301 break;
302
303 case UNORDERED_EXPR:
304 do_compare_and_jump (op0, op1, UNORDERED, UNORDERED,
40e90eac 305 if_false_label, if_true_label, prob);
4df62c77
MM
306 break;
307
308 case UNLT_EXPR:
40e90eac
JJ
309 do_compare_and_jump (op0, op1, UNLT, UNLT, if_false_label, if_true_label,
310 prob);
4df62c77
MM
311 break;
312
313 case UNLE_EXPR:
40e90eac
JJ
314 do_compare_and_jump (op0, op1, UNLE, UNLE, if_false_label, if_true_label,
315 prob);
4df62c77
MM
316 break;
317
318 case UNGT_EXPR:
40e90eac
JJ
319 do_compare_and_jump (op0, op1, UNGT, UNGT, if_false_label, if_true_label,
320 prob);
4df62c77
MM
321 break;
322
323 case UNGE_EXPR:
40e90eac
JJ
324 do_compare_and_jump (op0, op1, UNGE, UNGE, if_false_label, if_true_label,
325 prob);
4df62c77
MM
326 break;
327
328 case UNEQ_EXPR:
40e90eac
JJ
329 do_compare_and_jump (op0, op1, UNEQ, UNEQ, if_false_label, if_true_label,
330 prob);
4df62c77
MM
331 break;
332
333 case LTGT_EXPR:
40e90eac
JJ
334 do_compare_and_jump (op0, op1, LTGT, LTGT, if_false_label, if_true_label,
335 prob);
4df62c77
MM
336 break;
337
338 case TRUTH_ANDIF_EXPR:
99206ca9
TJ
339 {
340 /* Spread the probability that the expression is false evenly between
341 the two conditions. So the first condition is false half the total
342 probability of being false. The second condition is false the other
343 half of the total probability of being false, so its jump has a false
344 probability of half the total, relative to the probability we
345 reached it (i.e. the first condition was true). */
357067f2
JH
346 profile_probability op0_prob = profile_probability::uninitialized ();
347 profile_probability op1_prob = profile_probability::uninitialized ();
348 if (prob.initialized_p ())
99206ca9 349 {
357067f2
JH
350 profile_probability false_prob = prob.invert ();
351 profile_probability op0_false_prob = false_prob.apply_scale (1, 2);
352 profile_probability op1_false_prob = false_prob.apply_scale (1, 2)
353 / op0_false_prob.invert ();
99206ca9 354 /* Get the probability that each jump below is true. */
357067f2
JH
355 op0_prob = op0_false_prob.invert ();
356 op1_prob = op1_false_prob.invert ();
99206ca9 357 }
1476d1bd 358 if (if_false_label == NULL)
99206ca9
TJ
359 {
360 drop_through_label = gen_label_rtx ();
1476d1bd
MM
361 do_jump (op0, drop_through_label, NULL, op0_prob);
362 do_jump (op1, NULL, if_true_label, op1_prob);
99206ca9
TJ
363 }
364 else
365 {
1476d1bd 366 do_jump (op0, if_false_label, NULL, op0_prob);
99206ca9
TJ
367 do_jump (op1, if_false_label, if_true_label, op1_prob);
368 }
369 break;
370 }
4df62c77
MM
371
372 case TRUTH_ORIF_EXPR:
99206ca9
TJ
373 {
374 /* Spread the probability evenly between the two conditions. So
375 the first condition has half the total probability of being true.
376 The second condition has the other half of the total probability,
377 so its jump has a probability of half the total, relative to
378 the probability we reached it (i.e. the first condition was false). */
357067f2
JH
379 profile_probability op0_prob = profile_probability::uninitialized ();
380 profile_probability op1_prob = profile_probability::uninitialized ();
381 if (prob.initialized_p ())
99206ca9 382 {
357067f2
JH
383 op0_prob = prob.apply_scale (1, 2);
384 op1_prob = prob.apply_scale (1, 2) / op0_prob.invert ();
1476d1bd
MM
385 }
386 if (if_true_label == NULL)
387 {
388 drop_through_label = gen_label_rtx ();
389 do_jump (op0, NULL, drop_through_label, op0_prob);
390 do_jump (op1, if_false_label, NULL, op1_prob);
391 }
392 else
393 {
394 do_jump (op0, NULL, if_true_label, op0_prob);
395 do_jump (op1, if_false_label, if_true_label, op1_prob);
396 }
99206ca9
TJ
397 break;
398 }
4df62c77
MM
399
400 default:
401 gcc_unreachable ();
402 }
403
404 if (drop_through_label)
405 {
406 do_pending_stack_adjust ();
407 emit_label (drop_through_label);
408 }
409}
410
1cff8964
AE
411/* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
412 the result is zero, or IF_TRUE_LABEL if the result is one.
413 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
414 meaning fall through in that case.
415
416 do_jump always does any pending stack adjust except when it does not
417 actually perform a jump. An example where there is no jump
40e90eac
JJ
418 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
419
357067f2 420 PROB is probability of jump to if_true_label. */
1cff8964
AE
421
422void
1476d1bd 423do_jump (tree exp, rtx_code_label *if_false_label,
357067f2 424 rtx_code_label *if_true_label, profile_probability prob)
1cff8964
AE
425{
426 enum tree_code code = TREE_CODE (exp);
1cff8964
AE
427 rtx temp;
428 int i;
429 tree type;
095a2d76 430 scalar_int_mode mode;
1476d1bd 431 rtx_code_label *drop_through_label = NULL;
1cff8964 432
1cff8964
AE
433 switch (code)
434 {
435 case ERROR_MARK:
436 break;
437
438 case INTEGER_CST:
1476d1bd
MM
439 {
440 rtx_code_label *lab = integer_zerop (exp) ? if_false_label
441 : if_true_label;
442 if (lab)
443 emit_jump (lab);
444 break;
445 }
1cff8964
AE
446
447#if 0
448 /* This is not true with #pragma weak */
449 case ADDR_EXPR:
450 /* The address of something can never be zero. */
451 if (if_true_label)
452 emit_jump (if_true_label);
453 break;
454#endif
455
456 case NOP_EXPR:
457 if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
458 || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
459 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF
460 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_RANGE_REF)
461 goto normal;
191816a3 462 /* FALLTHRU */
1cff8964
AE
463 case CONVERT_EXPR:
464 /* If we are narrowing the operand, we have to do the compare in the
465 narrower mode. */
466 if ((TYPE_PRECISION (TREE_TYPE (exp))
467 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
468 goto normal;
191816a3 469 /* FALLTHRU */
1cff8964 470 case NON_LVALUE_EXPR:
1cff8964
AE
471 case ABS_EXPR:
472 case NEGATE_EXPR:
473 case LROTATE_EXPR:
474 case RROTATE_EXPR:
475 /* These cannot change zero->nonzero or vice versa. */
40e90eac 476 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label, prob);
1cff8964
AE
477 break;
478
1cff8964 479 case TRUTH_NOT_EXPR:
8ac074e8 480 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label,
357067f2 481 prob.invert ());
1cff8964
AE
482 break;
483
8ea9d0c7
PB
484 case COND_EXPR:
485 {
19f8b229 486 rtx_code_label *label1 = gen_label_rtx ();
8ea9d0c7
PB
487 if (!if_true_label || !if_false_label)
488 {
489 drop_through_label = gen_label_rtx ();
490 if (!if_true_label)
491 if_true_label = drop_through_label;
492 if (!if_false_label)
493 if_false_label = drop_through_label;
494 }
495
496 do_pending_stack_adjust ();
357067f2
JH
497 do_jump (TREE_OPERAND (exp, 0), label1, NULL,
498 profile_probability::uninitialized ());
40e90eac 499 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label, prob);
8ea9d0c7 500 emit_label (label1);
40e90eac 501 do_jump (TREE_OPERAND (exp, 2), if_false_label, if_true_label, prob);
8ea9d0c7
PB
502 break;
503 }
504
1cff8964 505 case COMPOUND_EXPR:
7c27e184 506 /* Lowered by gimplify.c. */
ced3f397 507 gcc_unreachable ();
1cff8964 508
0b04d281
DE
509 case MINUS_EXPR:
510 /* Nonzero iff operands of minus differ. */
4df62c77
MM
511 code = NE_EXPR;
512
0b04d281 513 /* FALLTHRU */
4df62c77 514 case EQ_EXPR:
1cff8964 515 case NE_EXPR:
1cff8964 516 case LT_EXPR:
1cff8964 517 case LE_EXPR:
1cff8964 518 case GT_EXPR:
1cff8964 519 case GE_EXPR:
1cff8964 520 case ORDERED_EXPR:
337e5d98 521 case UNORDERED_EXPR:
337e5d98 522 case UNLT_EXPR:
337e5d98 523 case UNLE_EXPR:
337e5d98 524 case UNGT_EXPR:
337e5d98 525 case UNGE_EXPR:
337e5d98 526 case UNEQ_EXPR:
337e5d98 527 case LTGT_EXPR:
4df62c77
MM
528 case TRUTH_ANDIF_EXPR:
529 case TRUTH_ORIF_EXPR:
c3223baf 530 other_code:
4df62c77 531 do_jump_1 (code, TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
40e90eac 532 if_false_label, if_true_label, prob);
1cff8964 533 break;
30821654
PB
534
535 case BIT_AND_EXPR:
536 /* fold_single_bit_test() converts (X & (1 << C)) into (X >> C) & 1.
537 See if the former is preferred for jump tests and restore it
538 if so. */
539 if (integer_onep (TREE_OPERAND (exp, 1)))
540 {
541 tree exp0 = TREE_OPERAND (exp, 0);
1476d1bd 542 rtx_code_label *set_label, *clr_label;
357067f2 543 profile_probability setclr_prob = prob;
30821654
PB
544
545 /* Strip narrowing integral type conversions. */
546 while (CONVERT_EXPR_P (exp0)
547 && TREE_OPERAND (exp0, 0) != error_mark_node
548 && TYPE_PRECISION (TREE_TYPE (exp0))
549 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp0, 0))))
550 exp0 = TREE_OPERAND (exp0, 0);
551
552 /* "exp0 ^ 1" inverts the sense of the single bit test. */
553 if (TREE_CODE (exp0) == BIT_XOR_EXPR
554 && integer_onep (TREE_OPERAND (exp0, 1)))
555 {
556 exp0 = TREE_OPERAND (exp0, 0);
557 clr_label = if_true_label;
558 set_label = if_false_label;
357067f2 559 setclr_prob = prob.invert ();
30821654
PB
560 }
561 else
562 {
563 clr_label = if_false_label;
564 set_label = if_true_label;
565 }
566
567 if (TREE_CODE (exp0) == RSHIFT_EXPR)
568 {
569 tree arg = TREE_OPERAND (exp0, 0);
570 tree shift = TREE_OPERAND (exp0, 1);
571 tree argtype = TREE_TYPE (arg);
572 if (TREE_CODE (shift) == INTEGER_CST
573 && compare_tree_int (shift, 0) >= 0
574 && compare_tree_int (shift, HOST_BITS_PER_WIDE_INT) < 0
7a504f33 575 && prefer_and_bit_test (SCALAR_INT_TYPE_MODE (argtype),
30821654
PB
576 TREE_INT_CST_LOW (shift)))
577 {
472e0df9 578 unsigned HOST_WIDE_INT mask
fecfbfa4 579 = HOST_WIDE_INT_1U << TREE_INT_CST_LOW (shift);
30821654 580 do_jump (build2 (BIT_AND_EXPR, argtype, arg,
1961ffb8 581 build_int_cstu (argtype, mask)),
40e90eac 582 clr_label, set_label, setclr_prob);
30821654
PB
583 break;
584 }
585 }
586 }
587
588 /* If we are AND'ing with a small constant, do this comparison in the
589 smallest type that fits. If the machine doesn't have comparisons
590 that small, it will be converted back to the wider comparison.
591 This helps if we are testing the sign bit of a narrower object.
592 combine can't do this for us because it can't know whether a
593 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
594
595 if (! SLOW_BYTE_ACCESS
596 && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
597 && TYPE_PRECISION (TREE_TYPE (exp)) <= HOST_BITS_PER_WIDE_INT
598 && (i = tree_floor_log2 (TREE_OPERAND (exp, 1))) >= 0
fffbab82 599 && int_mode_for_size (i + 1, 0).exists (&mode)
30821654
PB
600 && (type = lang_hooks.types.type_for_mode (mode, 1)) != 0
601 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
fedc1775 602 && have_insn_for (COMPARE, TYPE_MODE (type)))
30821654 603 {
40e90eac
JJ
604 do_jump (fold_convert (type, exp), if_false_label, if_true_label,
605 prob);
30821654
PB
606 break;
607 }
608
609 if (TYPE_PRECISION (TREE_TYPE (exp)) > 1
610 || TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
611 goto normal;
612
613 /* Boolean comparisons can be compiled as TRUTH_AND_EXPR. */
191816a3 614 /* FALLTHRU */
1cff8964 615
d1f36c51 616 case TRUTH_AND_EXPR:
97191ef9
PB
617 /* High branch cost, expand as the bitwise AND of the conditions.
618 Do the same if the RHS has side effects, because we're effectively
619 turning a TRUTH_AND_EXPR into a TRUTH_ANDIF_EXPR. */
3a4fd356
JH
620 if (BRANCH_COST (optimize_insn_for_speed_p (),
621 false) >= 4
622 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
d1f36c51 623 goto normal;
c3223baf
MM
624 code = TRUTH_ANDIF_EXPR;
625 goto other_code;
d1f36c51 626
30821654 627 case BIT_IOR_EXPR:
d1f36c51 628 case TRUTH_OR_EXPR:
97191ef9
PB
629 /* High branch cost, expand as the bitwise OR of the conditions.
630 Do the same if the RHS has side effects, because we're effectively
631 turning a TRUTH_OR_EXPR into a TRUTH_ORIF_EXPR. */
40e90eac 632 if (BRANCH_COST (optimize_insn_for_speed_p (), false) >= 4
3a4fd356 633 || TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
d1f36c51 634 goto normal;
c3223baf
MM
635 code = TRUTH_ORIF_EXPR;
636 goto other_code;
d1f36c51 637
938d968e 638 /* Fall through and generate the normal code. */
1cff8964
AE
639 default:
640 normal:
84217346 641 temp = expand_normal (exp);
1cff8964 642 do_pending_stack_adjust ();
feb04780
RS
643 /* The RTL optimizers prefer comparisons against pseudos. */
644 if (GET_CODE (temp) == SUBREG)
9311f3f6 645 {
feb04780
RS
646 /* Compare promoted variables in their promoted mode. */
647 if (SUBREG_PROMOTED_VAR_P (temp)
648 && REG_P (XEXP (temp, 0)))
649 temp = XEXP (temp, 0);
650 else
651 temp = copy_to_reg (temp);
9311f3f6 652 }
feb04780
RS
653 do_compare_rtx_and_jump (temp, CONST0_RTX (GET_MODE (temp)),
654 NE, TYPE_UNSIGNED (TREE_TYPE (exp)),
655 GET_MODE (temp), NULL_RTX,
40e90eac 656 if_false_label, if_true_label, prob);
1cff8964 657 }
8ea9d0c7
PB
658
659 if (drop_through_label)
660 {
661 do_pending_stack_adjust ();
662 emit_label (drop_through_label);
663 }
1cff8964
AE
664}
665\f
1cff8964
AE
666/* Compare OP0 with OP1, word at a time, in mode MODE.
667 UNSIGNEDP says to do unsigned comparison.
668 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
669
3bf78d3b 670static void
d787ba56 671do_jump_by_parts_greater_rtx (scalar_int_mode mode, int unsignedp, rtx op0,
1476d1bd
MM
672 rtx op1, rtx_code_label *if_false_label,
673 rtx_code_label *if_true_label,
357067f2 674 profile_probability prob)
1cff8964
AE
675{
676 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
1476d1bd 677 rtx_code_label *drop_through_label = 0;
c8679567
EB
678 bool drop_through_if_true = false, drop_through_if_false = false;
679 enum rtx_code code = GT;
1cff8964
AE
680 int i;
681
682 if (! if_true_label || ! if_false_label)
683 drop_through_label = gen_label_rtx ();
684 if (! if_true_label)
c8679567
EB
685 {
686 if_true_label = drop_through_label;
687 drop_through_if_true = true;
688 }
1cff8964 689 if (! if_false_label)
c8679567
EB
690 {
691 if_false_label = drop_through_label;
692 drop_through_if_false = true;
693 }
694
695 /* Deal with the special case 0 > x: only one comparison is necessary and
696 we reverse it to avoid jumping to the drop-through label. */
697 if (op0 == const0_rtx && drop_through_if_true && !drop_through_if_false)
698 {
699 code = LE;
700 if_true_label = if_false_label;
701 if_false_label = drop_through_label;
702 drop_through_if_true = false;
703 drop_through_if_false = true;
357067f2 704 prob = prob.invert ();
c8679567 705 }
1cff8964
AE
706
707 /* Compare a word at a time, high order first. */
708 for (i = 0; i < nwords; i++)
709 {
710 rtx op0_word, op1_word;
711
712 if (WORDS_BIG_ENDIAN)
713 {
714 op0_word = operand_subword_force (op0, i, mode);
715 op1_word = operand_subword_force (op1, i, mode);
716 }
717 else
718 {
719 op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
720 op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
721 }
722
723 /* All but high-order word must be compared as unsigned. */
c8679567 724 do_compare_rtx_and_jump (op0_word, op1_word, code, (unsignedp || i > 0),
1476d1bd 725 word_mode, NULL_RTX, NULL, if_true_label,
c8679567
EB
726 prob);
727
728 /* Emit only one comparison for 0. Do not emit the last cond jump. */
729 if (op0 == const0_rtx || i == nwords - 1)
730 break;
1cff8964
AE
731
732 /* Consider lower words only if these are equal. */
733 do_compare_rtx_and_jump (op0_word, op1_word, NE, unsignedp, word_mode,
357067f2
JH
734 NULL_RTX, NULL, if_false_label,
735 prob.invert ());
1cff8964
AE
736 }
737
c8679567 738 if (!drop_through_if_false)
1cff8964
AE
739 emit_jump (if_false_label);
740 if (drop_through_label)
741 emit_label (drop_through_label);
742}
3bf78d3b
RS
743
744/* Given a comparison expression EXP for values too wide to be compared
745 with one insn, test the comparison and jump to the appropriate label.
746 The code of EXP is ignored; we always test GT if SWAP is 0,
d787ba56 747 and LT if SWAP is 1. MODE is the mode of the two operands. */
3bf78d3b
RS
748
749static void
d787ba56
RS
750do_jump_by_parts_greater (scalar_int_mode mode, tree treeop0, tree treeop1,
751 int swap, rtx_code_label *if_false_label,
357067f2
JH
752 rtx_code_label *if_true_label,
753 profile_probability prob)
3bf78d3b 754{
4df62c77
MM
755 rtx op0 = expand_normal (swap ? treeop1 : treeop0);
756 rtx op1 = expand_normal (swap ? treeop0 : treeop1);
4df62c77 757 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (treeop0));
3bf78d3b
RS
758
759 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label,
40e90eac 760 if_true_label, prob);
3bf78d3b 761}
1cff8964 762\f
feb04780
RS
763/* Jump according to whether OP0 is 0. We assume that OP0 has an integer
764 mode, MODE, that is too wide for the available compare insns. Either
1476d1bd 765 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL
feb04780 766 to indicate drop through. */
1cff8964 767
feb04780 768static void
d787ba56 769do_jump_by_parts_zero_rtx (scalar_int_mode mode, rtx op0,
1476d1bd 770 rtx_code_label *if_false_label,
357067f2
JH
771 rtx_code_label *if_true_label,
772 profile_probability prob)
1cff8964 773{
feb04780 774 int nwords = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
1cff8964
AE
775 rtx part;
776 int i;
1476d1bd 777 rtx_code_label *drop_through_label = NULL;
1cff8964
AE
778
779 /* The fastest way of doing this comparison on almost any machine is to
780 "or" all the words and compare the result. If all have to be loaded
781 from memory and this is a very wide item, it's possible this may
782 be slower, but that's highly unlikely. */
783
784 part = gen_reg_rtx (word_mode);
0a49e5c2 785 emit_move_insn (part, operand_subword_force (op0, 0, mode));
1cff8964
AE
786 for (i = 1; i < nwords && part != 0; i++)
787 part = expand_binop (word_mode, ior_optab, part,
0a49e5c2 788 operand_subword_force (op0, i, mode),
1cff8964
AE
789 part, 1, OPTAB_WIDEN);
790
791 if (part != 0)
792 {
793 do_compare_rtx_and_jump (part, const0_rtx, EQ, 1, word_mode,
40e90eac 794 NULL_RTX, if_false_label, if_true_label, prob);
1cff8964
AE
795 return;
796 }
797
798 /* If we couldn't do the "or" simply, do this with a series of compares. */
799 if (! if_false_label)
1476d1bd 800 if_false_label = drop_through_label = gen_label_rtx ();
1cff8964
AE
801
802 for (i = 0; i < nwords; i++)
0a49e5c2 803 do_compare_rtx_and_jump (operand_subword_force (op0, i, mode),
1cff8964 804 const0_rtx, EQ, 1, word_mode, NULL_RTX,
1476d1bd 805 if_false_label, NULL, prob);
1cff8964
AE
806
807 if (if_true_label)
808 emit_jump (if_true_label);
809
810 if (drop_through_label)
811 emit_label (drop_through_label);
812}
feb04780
RS
813
814/* Test for the equality of two RTX expressions OP0 and OP1 in mode MODE,
815 where MODE is an integer mode too wide to be compared with one insn.
816 Either (but not both) of IF_TRUE_LABEL and IF_FALSE_LABEL may be NULL_RTX
817 to indicate drop through. */
818
819static void
d787ba56 820do_jump_by_parts_equality_rtx (scalar_int_mode mode, rtx op0, rtx op1,
1476d1bd 821 rtx_code_label *if_false_label,
357067f2
JH
822 rtx_code_label *if_true_label,
823 profile_probability prob)
feb04780
RS
824{
825 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
1476d1bd 826 rtx_code_label *drop_through_label = NULL;
feb04780
RS
827 int i;
828
829 if (op1 == const0_rtx)
830 {
40e90eac
JJ
831 do_jump_by_parts_zero_rtx (mode, op0, if_false_label, if_true_label,
832 prob);
feb04780
RS
833 return;
834 }
835 else if (op0 == const0_rtx)
836 {
40e90eac
JJ
837 do_jump_by_parts_zero_rtx (mode, op1, if_false_label, if_true_label,
838 prob);
feb04780
RS
839 return;
840 }
841
842 if (! if_false_label)
843 drop_through_label = if_false_label = gen_label_rtx ();
844
845 for (i = 0; i < nwords; i++)
846 do_compare_rtx_and_jump (operand_subword_force (op0, i, mode),
847 operand_subword_force (op1, i, mode),
848 EQ, 0, word_mode, NULL_RTX,
1476d1bd 849 if_false_label, NULL, prob);
feb04780
RS
850
851 if (if_true_label)
852 emit_jump (if_true_label);
853 if (drop_through_label)
854 emit_label (drop_through_label);
855}
856
857/* Given an EQ_EXPR expression EXP for values too wide to be compared
d787ba56
RS
858 with one insn, test the comparison and jump to the appropriate label.
859 MODE is the mode of the two operands. */
feb04780
RS
860
861static void
d787ba56 862do_jump_by_parts_equality (scalar_int_mode mode, tree treeop0, tree treeop1,
1476d1bd 863 rtx_code_label *if_false_label,
357067f2
JH
864 rtx_code_label *if_true_label,
865 profile_probability prob)
feb04780 866{
4df62c77
MM
867 rtx op0 = expand_normal (treeop0);
868 rtx op1 = expand_normal (treeop1);
feb04780 869 do_jump_by_parts_equality_rtx (mode, op0, op1, if_false_label,
40e90eac 870 if_true_label, prob);
feb04780 871}
1cff8964 872\f
337e5d98
PB
873/* Split a comparison into two others, the second of which has the other
874 "orderedness". The first is always ORDERED or UNORDERED if MODE
875 does not honor NaNs (which means that it can be skipped in that case;
876 see do_compare_rtx_and_jump).
877
878 The two conditions are written in *CODE1 and *CODE2. Return true if
879 the conditions must be ANDed, false if they must be ORed. */
880
881bool
ef4bddc2 882split_comparison (enum rtx_code code, machine_mode mode,
337e5d98
PB
883 enum rtx_code *code1, enum rtx_code *code2)
884{
885 switch (code)
886 {
887 case LT:
888 *code1 = ORDERED;
889 *code2 = UNLT;
890 return true;
891 case LE:
892 *code1 = ORDERED;
893 *code2 = UNLE;
894 return true;
895 case GT:
896 *code1 = ORDERED;
897 *code2 = UNGT;
898 return true;
899 case GE:
900 *code1 = ORDERED;
901 *code2 = UNGE;
902 return true;
903 case EQ:
904 *code1 = ORDERED;
905 *code2 = UNEQ;
906 return true;
907 case NE:
908 *code1 = UNORDERED;
909 *code2 = LTGT;
910 return false;
911 case UNLT:
912 *code1 = UNORDERED;
913 *code2 = LT;
914 return false;
915 case UNLE:
916 *code1 = UNORDERED;
917 *code2 = LE;
918 return false;
919 case UNGT:
920 *code1 = UNORDERED;
921 *code2 = GT;
922 return false;
923 case UNGE:
924 *code1 = UNORDERED;
925 *code2 = GE;
926 return false;
927 case UNEQ:
928 *code1 = UNORDERED;
929 *code2 = EQ;
930 return false;
931 case LTGT:
932 /* Do not turn a trapping comparison into a non-trapping one. */
933 if (HONOR_SNANS (mode))
934 {
935 *code1 = LT;
936 *code2 = GT;
937 return false;
938 }
939 else
940 {
941 *code1 = ORDERED;
942 *code2 = NE;
943 return true;
944 }
945 default:
946 gcc_unreachable ();
947 }
948}
949
950
1cff8964
AE
951/* Like do_compare_and_jump but expects the values to compare as two rtx's.
952 The decision as to signed or unsigned comparison must be made by the caller.
953
954 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
955 compared. */
956
957void
7080f735 958do_compare_rtx_and_jump (rtx op0, rtx op1, enum rtx_code code, int unsignedp,
1476d1bd
MM
959 machine_mode mode, rtx size,
960 rtx_code_label *if_false_label,
357067f2
JH
961 rtx_code_label *if_true_label,
962 profile_probability prob)
1cff8964 963{
1cff8964 964 rtx tem;
1476d1bd 965 rtx_code_label *dummy_label = NULL;
1cff8964
AE
966
967 /* Reverse the comparison if that is safe and we want to jump if it is
337e5d98
PB
968 false. Also convert to the reverse comparison if the target can
969 implement it. */
970 if ((! if_true_label
971 || ! can_compare_p (code, mode, ccp_jump))
972 && (! FLOAT_MODE_P (mode)
973 || code == ORDERED || code == UNORDERED
974 || (! HONOR_NANS (mode) && (code == LTGT || code == UNEQ))
975 || (! HONOR_SNANS (mode) && (code == EQ || code == NE))))
1cff8964 976 {
337e5d98
PB
977 enum rtx_code rcode;
978 if (FLOAT_MODE_P (mode))
979 rcode = reverse_condition_maybe_unordered (code);
980 else
981 rcode = reverse_condition (code);
982
983 /* Canonicalize to UNORDERED for the libcall. */
984 if (can_compare_p (rcode, mode, ccp_jump)
985 || (code == ORDERED && ! can_compare_p (ORDERED, mode, ccp_jump)))
986 {
00c1cf38 987 std::swap (if_true_label, if_false_label);
337e5d98 988 code = rcode;
357067f2 989 prob = prob.invert ();
337e5d98 990 }
1cff8964
AE
991 }
992
993 /* If one operand is constant, make it the second one. Only do this
994 if the other operand is not constant as well. */
995
996 if (swap_commutative_operands_p (op0, op1))
997 {
00c1cf38 998 std::swap (op0, op1);
1cff8964
AE
999 code = swap_condition (code);
1000 }
1001
1cff8964
AE
1002 do_pending_stack_adjust ();
1003
c6fb08ad
PB
1004 code = unsignedp ? unsigned_condition (code) : code;
1005 if (0 != (tem = simplify_relational_operation (code, mode, VOIDmode,
1006 op0, op1)))
1cff8964 1007 {
c6fb08ad
PB
1008 if (CONSTANT_P (tem))
1009 {
1476d1bd
MM
1010 rtx_code_label *label = (tem == const0_rtx
1011 || tem == CONST0_RTX (mode))
1012 ? if_false_label : if_true_label;
c6fb08ad
PB
1013 if (label)
1014 emit_jump (label);
1015 return;
1016 }
1cff8964 1017
c6fb08ad
PB
1018 code = GET_CODE (tem);
1019 mode = GET_MODE (tem);
1020 op0 = XEXP (tem, 0);
1021 op1 = XEXP (tem, 1);
1022 unsignedp = (code == GTU || code == LTU || code == GEU || code == LEU);
1cff8964 1023 }
1cff8964
AE
1024
1025 if (! if_true_label)
337e5d98 1026 dummy_label = if_true_label = gen_label_rtx ();
1cff8964 1027
b4206259
RS
1028 scalar_int_mode int_mode;
1029 if (is_int_mode (mode, &int_mode)
1030 && ! can_compare_p (code, int_mode, ccp_jump))
feb04780
RS
1031 {
1032 switch (code)
1033 {
1034 case LTU:
b4206259 1035 do_jump_by_parts_greater_rtx (int_mode, 1, op1, op0,
40e90eac 1036 if_false_label, if_true_label, prob);
feb04780
RS
1037 break;
1038
1039 case LEU:
b4206259 1040 do_jump_by_parts_greater_rtx (int_mode, 1, op0, op1,
40e90eac 1041 if_true_label, if_false_label,
357067f2 1042 prob.invert ());
feb04780
RS
1043 break;
1044
fb9c6d49 1045 case GTU:
b4206259 1046 do_jump_by_parts_greater_rtx (int_mode, 1, op0, op1,
40e90eac 1047 if_false_label, if_true_label, prob);
fb9c6d49
RS
1048 break;
1049
1050 case GEU:
b4206259 1051 do_jump_by_parts_greater_rtx (int_mode, 1, op1, op0,
40e90eac 1052 if_true_label, if_false_label,
357067f2 1053 prob.invert ());
fb9c6d49
RS
1054 break;
1055
feb04780 1056 case LT:
b4206259 1057 do_jump_by_parts_greater_rtx (int_mode, 0, op1, op0,
40e90eac 1058 if_false_label, if_true_label, prob);
feb04780
RS
1059 break;
1060
1dc5d842 1061 case LE:
b4206259 1062 do_jump_by_parts_greater_rtx (int_mode, 0, op0, op1,
40e90eac 1063 if_true_label, if_false_label,
357067f2 1064 prob.invert ());
1dc5d842
RS
1065 break;
1066
feb04780 1067 case GT:
b4206259 1068 do_jump_by_parts_greater_rtx (int_mode, 0, op0, op1,
40e90eac 1069 if_false_label, if_true_label, prob);
feb04780
RS
1070 break;
1071
1072 case GE:
b4206259 1073 do_jump_by_parts_greater_rtx (int_mode, 0, op1, op0,
40e90eac 1074 if_true_label, if_false_label,
357067f2 1075 prob.invert ());
feb04780
RS
1076 break;
1077
1078 case EQ:
b4206259 1079 do_jump_by_parts_equality_rtx (int_mode, op0, op1, if_false_label,
40e90eac 1080 if_true_label, prob);
feb04780
RS
1081 break;
1082
1083 case NE:
b4206259 1084 do_jump_by_parts_equality_rtx (int_mode, op0, op1, if_true_label,
357067f2
JH
1085 if_false_label,
1086 prob.invert ());
feb04780
RS
1087 break;
1088
1089 default:
1090 gcc_unreachable ();
1091 }
1092 }
1093 else
337e5d98 1094 {
16e0be9b 1095 if (SCALAR_FLOAT_MODE_P (mode)
337e5d98 1096 && ! can_compare_p (code, mode, ccp_jump)
45475a3f
PB
1097 && can_compare_p (swap_condition (code), mode, ccp_jump))
1098 {
45475a3f 1099 code = swap_condition (code);
fab27f52 1100 std::swap (op0, op1);
45475a3f 1101 }
16e0be9b 1102 else if (SCALAR_FLOAT_MODE_P (mode)
45475a3f 1103 && ! can_compare_p (code, mode, ccp_jump)
2225b9f2
RH
1104 /* Never split ORDERED and UNORDERED.
1105 These must be implemented. */
45475a3f 1106 && (code != ORDERED && code != UNORDERED)
2225b9f2
RH
1107 /* Split a floating-point comparison if
1108 we can jump on other conditions... */
45475a3f 1109 && (have_insn_for (COMPARE, mode)
45475a3f 1110 /* ... or if there is no libcall for it. */
19b5fafb 1111 || code_to_optab (code) == unknown_optab))
337e5d98
PB
1112 {
1113 enum rtx_code first_code;
1114 bool and_them = split_comparison (code, mode, &first_code, &code);
1115
1116 /* If there are no NaNs, the first comparison should always fall
1117 through. */
1118 if (!HONOR_NANS (mode))
1119 gcc_assert (first_code == (and_them ? ORDERED : UNORDERED));
1120
1121 else
1122 {
357067f2 1123 profile_probability first_prob = prob;
a0dbf285 1124 if (first_code == UNORDERED)
357067f2
JH
1125 first_prob = profile_probability::guessed_always ().apply_scale
1126 (1, 100);
a0dbf285 1127 else if (first_code == ORDERED)
357067f2
JH
1128 first_prob = profile_probability::guessed_always ().apply_scale
1129 (99, 100);
337e5d98
PB
1130 if (and_them)
1131 {
1476d1bd 1132 rtx_code_label *dest_label;
337e5d98
PB
1133 /* If we only jump if true, just bypass the second jump. */
1134 if (! if_false_label)
1135 {
1136 if (! dummy_label)
1137 dummy_label = gen_label_rtx ();
1138 dest_label = dummy_label;
1139 }
1140 else
1141 dest_label = if_false_label;
1142 do_compare_rtx_and_jump (op0, op1, first_code, unsignedp, mode,
1476d1bd 1143 size, dest_label, NULL, first_prob);
337e5d98
PB
1144 }
1145 else
1146 do_compare_rtx_and_jump (op0, op1, first_code, unsignedp, mode,
1476d1bd 1147 size, NULL, if_true_label, first_prob);
337e5d98
PB
1148 }
1149 }
1150
1151 emit_cmp_and_jump_insns (op0, op1, code, size, mode, unsignedp,
a4da41e1 1152 if_true_label, prob);
337e5d98 1153 }
1cff8964
AE
1154
1155 if (if_false_label)
1156 emit_jump (if_false_label);
337e5d98
PB
1157 if (dummy_label)
1158 emit_label (dummy_label);
1cff8964
AE
1159}
1160
1161/* Generate code for a comparison expression EXP (including code to compute
1162 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
1163 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
1164 generated code will drop through.
1165 SIGNED_CODE should be the rtx operation for this comparison for
1166 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
1167
1168 We force a stack adjustment unless there are currently
1169 things pushed on the stack that aren't yet used. */
1170
1171static void
4df62c77 1172do_compare_and_jump (tree treeop0, tree treeop1, enum rtx_code signed_code,
1476d1bd
MM
1173 enum rtx_code unsigned_code,
1174 rtx_code_label *if_false_label,
357067f2 1175 rtx_code_label *if_true_label, profile_probability prob)
1cff8964
AE
1176{
1177 rtx op0, op1;
1178 tree type;
ef4bddc2 1179 machine_mode mode;
1cff8964
AE
1180 int unsignedp;
1181 enum rtx_code code;
1182
1183 /* Don't crash if the comparison was erroneous. */
4df62c77
MM
1184 op0 = expand_normal (treeop0);
1185 if (TREE_CODE (treeop0) == ERROR_MARK)
1cff8964
AE
1186 return;
1187
4df62c77
MM
1188 op1 = expand_normal (treeop1);
1189 if (TREE_CODE (treeop1) == ERROR_MARK)
1cff8964
AE
1190 return;
1191
4df62c77 1192 type = TREE_TYPE (treeop0);
4df62c77
MM
1193 if (TREE_CODE (treeop0) == INTEGER_CST
1194 && (TREE_CODE (treeop1) != INTEGER_CST
7a504f33
RS
1195 || (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (type))
1196 > GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (treeop1))))))
1197 /* op0 might have been replaced by promoted constant, in which
1198 case the type of second argument should be used. */
1199 type = TREE_TYPE (treeop1);
1200 mode = TYPE_MODE (type);
8df83eae 1201 unsignedp = TYPE_UNSIGNED (type);
1cff8964
AE
1202 code = unsignedp ? unsigned_code : signed_code;
1203
1cff8964 1204 /* If function pointers need to be "canonicalized" before they can
b8c26d70
NN
1205 be reliably compared, then canonicalize them.
1206 Only do this if *both* sides of the comparison are function pointers.
1207 If one side isn't, we want a noncanonicalized comparison. See PR
6c6cfbfd 1208 middle-end/17564. */
582554e3 1209 if (targetm.have_canonicalize_funcptr_for_compare ()
a89905fd
JDA
1210 && POINTER_TYPE_P (TREE_TYPE (treeop0))
1211 && POINTER_TYPE_P (TREE_TYPE (treeop1))
1212 && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))
1213 && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (treeop1))))
1cff8964
AE
1214 {
1215 rtx new_op0 = gen_reg_rtx (mode);
b8c26d70 1216 rtx new_op1 = gen_reg_rtx (mode);
1cff8964 1217
582554e3 1218 emit_insn (targetm.gen_canonicalize_funcptr_for_compare (new_op0, op0));
1cff8964 1219 op0 = new_op0;
1cff8964 1220
582554e3 1221 emit_insn (targetm.gen_canonicalize_funcptr_for_compare (new_op1, op1));
1cff8964
AE
1222 op1 = new_op1;
1223 }
1cff8964 1224
1cff8964
AE
1225 do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode,
1226 ((mode == BLKmode)
4df62c77 1227 ? expr_size (treeop0) : NULL_RTX),
40e90eac 1228 if_false_label, if_true_label, prob);
1cff8964 1229}
dbf833ee
RS
1230
1231#include "gt-dojump.h"