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