Lines Matching +full:test2 +full:. +full:zeros
1 /* If-conversion support.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
9 any later version.
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "backend.h"
24 #include "target.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "cfghooks.h"
28 #include "df.h"
29 #include "memmodel.h"
30 #include "tm_p.h"
31 #include "expmed.h"
32 #include "optabs.h"
33 #include "regs.h"
34 #include "emit-rtl.h"
35 #include "recog.h"
37 #include "cfgrtl.h"
38 #include "cfganal.h"
39 #include "cfgcleanup.h"
40 #include "expr.h"
41 #include "output.h"
42 #include "cfgloop.h"
43 #include "tree-pass.h"
44 #include "dbgcnt.h"
45 #include "shrink-wrap.h"
46 #include "rtl-iter.h"
47 #include "ifcvt.h"
48 #include "params.h"
60 /* True if after combine pass. */
63 /* True if the target has the cbranchcc4 optab. */
70 execution. */
73 /* # of changes made. */
76 /* Whether conditional execution changes were made. */
79 /* Forward references. */
103 /* Count the number of non-jump active insns in BB. */
125 basic block BB is less than MAX_COST. This function returns
126 false if the cost of any instruction could not be estimated.
129 as those insns are being speculated. MAX_COST is scaled with SCALE
130 plus a small fudge factor. */
139 int scale = prob.initialized_p () ? prob.to_reg_br_prob_base () in cheap_bb_rtx_cost_p()
143 applied to insn_cost when optimizing for size. Only do in cheap_bb_rtx_cost_p()
145 passes before combine. in cheap_bb_rtx_cost_p()
149 basic blocks in one if-conversion transformation. */ in cheap_bb_rtx_cost_p()
154 secondary benefits. So we fudge the scale factor to make speculating in cheap_bb_rtx_cost_p()
155 appear a little more profitable when optimizing for performance. */ in cheap_bb_rtx_cost_p()
174 register stack. Unfortunately, correctly recognizing and in cheap_bb_rtx_cost_p()
176 now we simply prohibit such speculative execution. */ in cheap_bb_rtx_cost_p()
200 /* Return the first non-jump active insn in the basic block. */
227 /* Return the last non-jump active (non-jump) insn in the basic block. */
253 /* Return the active insn before INSN inside basic block CURR_BB. */
266 /* No other active insn all the way to the start of the basic block. */ in find_active_insn_before()
274 /* Return the active insn after INSN inside basic block CURR_BB. */
287 /* No other active insn all the way to the end of the basic block. */ in find_active_insn_after()
295 /* Return the basic block reached by falling though the basic block BB. */
305 /* Return true if RTXs A and B can be safely interchanged. */
317 reference is not. Interchanging a dead type-unsafe memory reference with in rtx_interchangeable_p()
319 words, it makes the program illegal. in rtx_interchangeable_p()
321 memory attributes. */ in rtx_interchangeable_p()
328 execution format if possible. Return TRUE if all of the non-note
329 insns were processed. */
338 /* probability of branch taken. */int mod_ok) in cond_exec_process_insns()
350 /* dwarf2out can't cope with conditional prologues. */ in cond_exec_process_insns()
359 /* dwarf2out can't cope with conditional unwind info. */ in cond_exec_process_insns()
363 /* Remove USE insns that get in the way. */ in cond_exec_process_insns()
366 /* ??? Ug. Actually unlinking the thing is problematic, in cond_exec_process_insns()
367 given what we'd have to coordinate with our callers. */ in cond_exec_process_insns()
383 /* Now build the conditional form of the instruction. */ in cond_exec_process_insns()
388 two conditions. */ in cond_exec_process_insns()
403 register, do so here. */ in cond_exec_process_insns()
412 if (CALL_P (insn) && prob_val.initialized_p ()) in cond_exec_process_insns()
415 prob_val.to_reg_br_prob_note (), in cond_exec_process_insns()
426 /* Return the condition for a jump. Do not do any special processing. */
440 reverse the condition. */ in cond_exec_get_condition()
456 to conditional execution. Return TRUE if we were successful at
457 converting the block. */
471 int max; /* max # of insns to convert. */ in cond_exec_process_if_block()
487 && elements without an ELSE block. */ in cond_exec_process_if_block()
500 the test. */ in cond_exec_process_if_block()
506 then we can not do conditional execution conversion on this block. */ in cond_exec_process_if_block()
511 and notes at the beginning and end of the block. Then count the total in cond_exec_process_if_block()
512 number of insns and see if it is small enough to convert. */ in cond_exec_process_if_block()
530 and limit the range of insns to be converted if possible. */ in cond_exec_process_if_block()
567 to make sure that they don't clobber the condition. */ in cond_exec_process_if_block()
597 the conditionally executed code. */ in cond_exec_process_if_block()
610 conditional execution register from a comparison, it can do so here. */ in cond_exec_process_if_block()
613 /* See if the conversion failed. */ in cond_exec_process_if_block()
622 false_prob_val = true_prob_val.invert (); in cond_exec_process_if_block()
630 /* If we have && or || tests, do them here. These tests are in the adjacent in cond_exec_process_if_block()
631 blocks after the first block containing the test. */ in cond_exec_process_if_block()
655 we can not do conditional execution conversion on this block. */ in cond_exec_process_if_block()
659 /* Find the conditional jump and isolate the test. */ in cond_exec_process_if_block()
682 do so here. */ in cond_exec_process_if_block()
686 /* See if the conversion failed. */ in cond_exec_process_if_block()
698 on then THEN block. */ in cond_exec_process_if_block()
702 to conditional execution. */ in cond_exec_process_if_block()
716 /* If we cannot apply the changes, fail. Do not go through the normal fail in cond_exec_process_if_block()
717 processing, since apply_change_group will call cancel_changes. */ in cond_exec_process_if_block()
721 /* Cancel any machine dependent changes. */ in cond_exec_process_if_block()
728 /* Do any machine dependent final modifications. */ in cond_exec_process_if_block()
732 /* Conversion succeeded. */ in cond_exec_process_if_block()
734 fprintf (dump_file, "%d insn%s converted to conditional execution.\n", in cond_exec_process_if_block()
741 that the remaining one is executed first for both branches. */ in cond_exec_process_if_block()
758 /* Cancel any machine dependent changes. */ in cond_exec_process_if_block()
783 or UNKNOWN if reversing the condition is not possible. */
794 if-convertible sequence described in IF_INFO.
796 through a target hook. */
804 /* Cost up the new sequence. */ in default_noce_conversion_profitable_p()
811 at the size growth. When compiling for speed, use the maximum. */ in default_noce_conversion_profitable_p()
815 /* Helper function for noce_try_store_flag*. */
829 build the store_flag insn directly. */ in noce_emit_store_flag()
879 /* Don't even try if the comparison operands or the mode of X are weird. */ in noce_emit_store_flag()
889 /* Emit instruction to move an rtx, possibly into STRICT_LOW_PART.
890 X is the destination/target and Y is the value to copy. */
907 otherwise construct a suitable SET pattern ourselves. */ in noce_emit_move_insn()
924 BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN. In order to be able to in noce_emit_move_insn()
926 value from the first call. */ in noce_emit_move_insn()
997 /* Return the CC reg if it is used in COND. */
1009 /* Return sequence of instructions generated by if conversion. This
1011 that the instructions are unshared, recognizable non-jump insns.
1012 On failure, this function returns a NULL_RTX. */
1033 and that we haven't introduced a new jump instruction. in end_ifcvt_sequence()
1035 allows proper placement of required clobbers. */ in end_ifcvt_sequence()
1039 /* Make sure new generated code does not clobber CC. */ in end_ifcvt_sequence()
1047 consist of a single simple set instruction. */
1062 "if (a == b) x = a; else x = b" into "x = b". */
1079 or a signed zero. */ in noce_try_move()
1085 either order. */ in noce_try_move()
1096 /* Avoid generating the move if the source is the destination. */ in noce_try_move()
1115 through simplify_rtx. Sometimes that can eliminate the IF_THEN_ELSE.
1116 If that is the case, emit the result into x. */
1147 /* Convert "if (test) x = 1; else x = 0".
1149 Only try 0 and STORE_FLAG_VALUE here. Other combinations will be
1151 a go at the conversion. */
1202 conditional negate form of this cheaply.
1205 between them. If the target has a conditional negate or
1207 expensive constant synthesis. */
1277 /* Convert "if (test) x = a; else x = b", for A and B constant.
1279 and B. */
1296 /* Handle cases like x := test ? y + 3 : y + 4. */ in noce_try_store_flag_constants()
1303 registers where we handle overlap below. */ in noce_try_store_flag_constants()
1324 /* Make sure we can represent the difference between the two values. */ in noce_try_store_flag_constants()
1338 explicitly. */ in noce_try_store_flag_constants()
1341 => 4 + (test != 0). */ in noce_try_store_flag_constants()
1346 !can_reverse | 3 - (test != 0). */ in noce_try_store_flag_constants()
1353 here. */ in noce_try_store_flag_constants()
1359 !can_reverse | 4 - (test != 0). */ in noce_try_store_flag_constants()
1366 here. */ in noce_try_store_flag_constants()
1371 => 4 + (test != 0). */ in noce_try_store_flag_constants()
1411 x out of the way while we store flags. */ in noce_try_store_flag_constants()
1429 /* Add the common part now. This may allow combine to merge this in noce_try_store_flag_constants()
1431 increment/decrement if the target allows it. */ in noce_try_store_flag_constants()
1437 /* Always use ifalse here. It should have been swapped with itrue in noce_try_store_flag_constants()
1438 when appropriate when reversep is true. */ in noce_try_store_flag_constants()
1444 expressions. */ in noce_try_store_flag_constants()
1483 if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) in noce_try_store_flag_constants()
1497 similarly for "foo--". */
1524 /* First try to use addcc pattern. */ in noce_try_addcc()
1544 if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) in noce_try_addcc()
1557 setcc. We're changing a branch and an increment to a comparison and in noce_try_addcc()
1558 an ADD/SUB. */ in noce_try_addcc()
1586 if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) in noce_try_addcc()
1637 if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) in noce_try_store_flag_mask()
1653 /* Helper function for noce_try_cmove and noce_try_cmove_arith. */
1662 /* If earliest == jump, try to build the cmove insn directly. in noce_emit_cmove()
1665 through the normal interface. */ in noce_emit_cmove()
1690 except that the target supports cbranchcc4. */ in noce_emit_cmove()
1717 the result. in noce_emit_cmove()
1719 If we can't create new pseudos, though, don't bother. */ in noce_emit_cmove()
1744 /* Nope, couldn't do it in that mode either. */ in noce_emit_cmove()
1758 /* Try only simple constants and registers here. More complex cases
1760 has had a go at it. */
1789 if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) in noce_try_cmove()
1801 Try this only if the target-specific expansion above has failed. in noce_try_cmove()
1804 approach. */ in noce_try_cmove()
1805 else if (!targetm.have_conditional_execution () in noce_try_cmove()
1820 between the two values. */ in noce_try_cmove()
1842 if (!seq || !targetm.noce_conversion_profitable_p (seq, if_info)) in noce_try_cmove()
1863 /* Return true if X contains a conditional code mode rtx. */
1876 /* Helper for bb_valid_for_noce_process_p. Validate that
1879 if-conversion. */
1891 /* Currently support only simple single sets in test_bb. */ in insn_valid_noce_process_p()
1903 used in BB_B. If TO_RENAME is non-NULL then it is a location that will be
1905 in this function. */
1928 /* Record all registers that BB_A sets. */ in bbs_ok_for_cmove_arith()
1950 of ZERO_EXTRACT or SUBREG or other dangerous stuff. in bbs_ok_for_cmove_arith()
1952 basic blocks performing an operation of the form [addr] = c ? a : b. in bbs_ok_for_cmove_arith()
1954 the only stores present. In that case [addr] should be the location in bbs_ok_for_cmove_arith()
1955 to be renamed. Assert that the callers set this up properly. */ in bbs_ok_for_cmove_arith()
1964 /* If the insn uses a reg set in BB_A return false. */ in bbs_ok_for_cmove_arith()
1980 /* Emit copies of all the active instructions in BB except the last.
1981 This is a helper for noce_try_cmove_arith. */
1999 /* Helper for noce_try_cmove_arith. Emit the pattern TO_EMIT and return
2000 the resulting insn or NULL if it's not a valid insn. */
2014 /* Helper for noce_try_cmove_arith. Emit a copy of the insns up to
2016 (as indicated by SIMPLE). Then emit LAST_INSN as the last
2017 insn in the block. The reason for that is that LAST_INSN may
2018 have been modified by the preparation in noce_try_cmove_arith. */
2032 /* Try more complex cases involving conditional_move. */
2053 conditional on their addresses followed by a load. Don't do this in noce_try_cmove_arith()
2054 early because it'll screw alias analysis. Note that we've in noce_try_cmove_arith()
2055 already checked for no side effects. */ in noce_try_cmove_arith()
2069 not trap or fault. This is also true if we've already loaded in noce_try_cmove_arith()
2070 from the address along the path from ENTRY. */ in noce_try_cmove_arith()
2090 /* Possibly rearrange operands to make things come out more natural. */ in noce_try_cmove_arith()
2123 came from the test block. The non-empty complex block that we will in noce_try_cmove_arith()
2125 first. */ in noce_try_cmove_arith()
2144 /* If either operand is complex, load it into a register first. in noce_try_cmove_arith()
2145 The best way to do this is to copy the original insn. In this in noce_try_cmove_arith()
2146 way we preserve any clobbers etc that the insn may have had. in noce_try_cmove_arith()
2147 This is of course not possible in the IS_MEM case. */ in noce_try_cmove_arith()
2209 /* Don't check inside insn_a. We will have changed it to emit_a in noce_try_cmove_arith()
2210 with a destination that doesn't conflict. */ in noce_try_cmove_arith()
2224 /* Don't check inside insn_b. We will have changed it to emit_b in noce_try_cmove_arith()
2225 with a destination that doesn't conflict. */ in noce_try_cmove_arith()
2235 swap insn that sets up A with the one that sets up B. If even in noce_try_cmove_arith()
2236 that doesn't help, punt. */ in noce_try_cmove_arith()
2262 /* If we're handling a memory for above, emit the load now. */ in noce_try_cmove_arith()
2267 /* Copy over flags as appropriate. */ in noce_try_cmove_arith()
2284 if (!ifcvt_seq || !targetm.noce_conversion_profitable_p (ifcvt_seq, if_info)) in noce_try_cmove_arith()
2298 choice, but this is not the case for the min/max/abs transforms.
2299 For these we wish to know that it is A or B in the condition. */
2309 /* If target is already mentioned in the known condition, return it. */ in noce_get_alt_condition()
2325 have that constant in it. There are two reasons why it may in noce_get_alt_condition()
2328 1. GCC may have needed to put the constant in a register, because in noce_get_alt_condition()
2329 the target can't compare directly against that constant. For in noce_get_alt_condition()
2331 that puts a constant in that register. in noce_get_alt_condition()
2333 2. GCC may have canonicalized the conditional, for example in noce_get_alt_condition()
2334 replacing "if x < 4" with "if x <= 3". We can undo that (or in noce_get_alt_condition()
2336 if they're off by one in the right direction. */ in noce_get_alt_condition()
2345 /* First, look to see if we put a constant in a register. */ in noce_get_alt_condition()
2372 adjusting the conditional. */ in noce_get_alt_condition()
2419 constants in it. */ in noce_get_alt_condition()
2435 /* We almost certainly searched back to a different place. in noce_get_alt_condition()
2436 Need to re-verify correct lifetimes. */ in noce_get_alt_condition()
2438 /* X may not be mentioned in the range (cond_earliest, jump]. */ in noce_get_alt_condition()
2443 /* A and B may not be modified in the range [cond_earliest, jump). */ in noce_get_alt_condition()
2453 /* Convert "if (a < b) x = a; else x = b;" to "x = min(a, b);", etc. */
2466 /* ??? Reject modes with NaNs or signed zeros since we don't know how in noce_try_minmax()
2467 they will be resolved with an SMIN/SMAX. It wouldn't be too hard in noce_try_minmax()
2468 to get the target to tell us... */ in noce_try_minmax()
2478 the comparison code. */ in noce_try_minmax()
2494 /* Determine what sort of operation this is. Note that the code is for in noce_try_minmax()
2495 a taken branch, so the code->operation mapping appears backwards. */ in noce_try_minmax()
2554 etc. */
2567 /* Reject modes with signed zeros. */ in noce_try_abs()
2571 /* Recognize A and B as constituting an ABS or NABS. The canonical in noce_try_abs()
2573 first operand of a comparison against 0 that evaluates to true. */ in noce_try_abs()
2601 /* Verify the condition is of the form we expect. */ in noce_try_abs()
2612 /* Verify that C is zero. Search one step backward for a in noce_try_abs()
2613 REG_EQUAL note or a simple source if necessary. */ in noce_try_abs()
2637 /* Work around funny ideas get_condition has wrt canonicalization. in noce_try_abs()
2639 therefore imply integer comparisons. in noce_try_abs()
2643 but not other cases (x > -1 is equivalent of x >= 0). */ in noce_try_abs()
2661 /* Determine what sort of operation this is. */ in noce_try_abs()
2687 for integers. Perhaps combine will clean things up. */ in noce_try_abs()
2720 /* Convert "if (m < 0) x = b; else x = 0;" to "x = (m >> C) & b;". */
2756 /* We currently don't handle different modes. */ in noce_try_sign_mask()
2762 original insn sequence or T is cheap. The former happens if B is the in noce_try_sign_mask()
2764 INSN_B which can happen for e.g. conditional stores to memory. For the in noce_try_sign_mask()
2766 after the transformation. */ in noce_try_sign_mask()
2778 "(signed) m >> 31" directly. This benefits targets with specialized in noce_try_sign_mask()
2779 insns to obtain the signmask, but still uses ashr_optab otherwise. */ in noce_try_sign_mask()
2804 transformations. */
2819 /* Check for an integer operation. */ in noce_try_bitop()
2826 /* Check for no else condition. */ in noce_try_bitop()
2830 /* Check for a suitable condition. */ in noce_try_bitop()
2837 /* ??? We could also handle AND here. */ in noce_try_bitop()
2856 /* Check for "if (X & C) x = x op C". */ in noce_try_bitop()
2863 /* if ((x & C) == 0) x |= C; is transformed to x |= C. */ in noce_try_bitop()
2864 /* if ((x & C) != 0) x |= C; is transformed to nothing. */ in noce_try_bitop()
2869 /* if ((x & C) == 0) x ^= C; is transformed to x |= C. */ in noce_try_bitop()
2875 /* if ((x & C) != 0) x ^= C; is transformed to x &= ~C. */ in noce_try_bitop()
2882 /* Check for "if (X & C) x &= ~C". */ in noce_try_bitop()
2889 /* if ((x & C) == 0) x &= ~C; is transformed to nothing. */ in noce_try_bitop()
2890 /* if ((x & C) != 0) x &= ~C; is transformed to x &= ~C. */ in noce_try_bitop()
2913 valid at JUMP, instead of at EARLIEST.
2916 THEN block of the caller, and we have to reverse the condition. */
2930 reverse the condition. */ in noce_get_condition()
2935 i.e. the THEN block isn't the fallthrough block for the TEST block in noce_get_condition()
2936 (see find_if_header). */ in noce_get_condition()
2940 /* If the condition variable is a register and is MODE_INT, accept it. */ in noce_get_condition()
2946 || !targetm.small_register_classes_for_mode_p (BImode))) in noce_get_condition()
2957 work of manipulating MODE_CC values and COMPARE rtx codes. */ in noce_get_condition()
2962 REG_INC notes and making sure no duplicate conditions are emitted. */ in noce_get_condition()
2969 /* Return true if OP is ok for if-then-else processing. */
2978 no address side effects. */ in noce_operand_ok()
2985 /* Return true iff basic block TEST_BB is valid for noce if-conversion.
2986 The condition used in this if-conversion is in COND.
2989 in TEST_BB don't produce any values that are live after TEST_BB.
2991 to compute a value for x. Add the rtx cost of the insns
2992 in TEST_BB to COST. Record whether TEST_BB is a single simple
2993 set instruction in SIMPLE_P. */
3018 /* We have a single simple set, that's okay. */ in bb_valid_for_noce_process_p()
3031 /* For now, disallow setting x multiple times in test_bb. */ in bb_valid_for_noce_process_p()
3037 /* The regs that are live out of test_bb. */ in bb_valid_for_noce_process_p()
3066 then fail. */ in bb_valid_for_noce_process_p()
3094 Subsequent passes are expected to clean up the extra moves.
3098 similar.
3115 through it for an overlap with Y. If we find one, we rewire the
3116 conditional set to use the temporary we introduced earlier.
3119 jump instructions. */
3133 /* Decompose the condition attached to the jump. */ in noce_convert_multiple_sets()
3139 /* The true targets for a conditional move. */ in noce_convert_multiple_sets()
3142 overlap. */ in noce_convert_multiple_sets()
3144 /* The insns we've emitted. */ in noce_convert_multiple_sets()
3150 /* Skip over non-insns. */ in noce_convert_multiple_sets()
3163 we've changed the register allocation. Rewire the read. While in noce_convert_multiple_sets()
3164 we are looking, also try to catch a swap idiom. */ in noce_convert_multiple_sets()
3168 /* Catch a "swap" style idiom. */ in noce_convert_multiple_sets()
3171 here. As the condition codes match, we can propagate in noce_convert_multiple_sets()
3172 the set to here. */ in noce_convert_multiple_sets()
3179 /* If we had a non-canonical conditional jump (i.e. one where in noce_convert_multiple_sets()
3181 the conditional select. */ in noce_convert_multiple_sets()
3187 bb_ok_for_noce_convert_multiple_sets. Be careful when processing in noce_convert_multiple_sets()
3194 we'll end up trying to emit r4:HI = cond ? (r1:SI) : (r3:HI). in noce_convert_multiple_sets()
3196 that. */ in noce_convert_multiple_sets()
3220 /* Actually emit the conditional move. */ in noce_convert_multiple_sets()
3225 try to continue. */ in noce_convert_multiple_sets()
3232 /* Bookkeeping. */ in noce_convert_multiple_sets()
3234 targets.safe_push (target); in noce_convert_multiple_sets()
3235 temporaries.safe_push (temp_dest); in noce_convert_multiple_sets()
3236 unmodified_insns.safe_push (insn); in noce_convert_multiple_sets()
3240 given an empty BB to convert, and we can't handle that. */ in noce_convert_multiple_sets()
3241 gcc_assert (!unmodified_insns.is_empty ()); in noce_convert_multiple_sets()
3243 /* Now fixup the assignments. */ in noce_convert_multiple_sets()
3247 /* Actually emit the sequence if it isn't too expensive. */ in noce_convert_multiple_sets()
3250 if (!targetm.noce_conversion_profitable_p (seq, if_info)) in noce_convert_multiple_sets()
3259 /* Mark all our temporaries and targets as used. */ in noce_convert_multiple_sets()
3282 INSN_LOCATION (unmodified_insns.last ())); in noce_convert_multiple_sets()
3284 /* Clean up THEN_BB and the edges in and out of it. */ in noce_convert_multiple_sets()
3291 /* Maybe merge blocks now the jump is simple enough. */ in noce_convert_multiple_sets()
3305 of conditional moves. Also check that we have more than one set
3307 fewer than PARAM_MAX_RTL_IF_CONVERSION_INSNS sets. */
3318 /* Skip over notes etc. */ in bb_ok_for_noce_convert_multiple_sets()
3322 /* We only handle SET insns. */ in bb_ok_for_noce_convert_multiple_sets()
3331 (including subreg) moves. This avoids any issues that might come in bb_ok_for_noce_convert_multiple_sets()
3333 guarantees. */ in bb_ok_for_noce_convert_multiple_sets()
3342 /* Destination must be appropriate for a conditional write. */ in bb_ok_for_noce_convert_multiple_sets()
3346 /* We must be able to conditionally move in this mode. */ in bb_ok_for_noce_convert_multiple_sets()
3354 this pass tries are better optimized and will be more appropriate. in bb_ok_for_noce_convert_multiple_sets()
3357 that. */ in bb_ok_for_noce_convert_multiple_sets()
3362 it without using conditional execution. Return TRUE if we were successful
3363 at converting the block. */
3380 (1) if (...) x = a; else x = b; in noce_process_if_block()
3381 (2) x = b; if (...) x = a; in noce_process_if_block()
3382 (3) if (...) x = a; // as if with an initial x = x. in noce_process_if_block()
3383 (4) if (...) { x = a; y = b; z = c; } // Like 3, for multiple SETS. in noce_process_if_block()
3384 The later patterns require jumps to be more expensive. in noce_process_if_block()
3385 For the if (...) x = a; else x = b; case we allow multiple insns in noce_process_if_block()
3387 to calculate a value for x. in noce_process_if_block()
3388 ??? For future expansion, further expand the "multiple X" rules. */ in noce_process_if_block()
3390 /* First look for multiple SETS. */ in noce_process_if_block()
3430 /* Look for the other potential set. Make sure we've got equivalent in noce_process_if_block()
3431 destinations. */ in noce_process_if_block()
3432 /* ??? This is overconservative. Storing to two different mems is in noce_process_if_block()
3433 as easy as conditionally computing the address. Storing to a in noce_process_if_block()
3436 stack pointer is available for this. */ in noce_process_if_block()
3458 COND_EARLIEST to JUMP. Make sure the relevant data is still in noce_process_if_block()
3459 intact. */ in noce_process_if_block()
3469 register class machines. */ in noce_process_if_block()
3472 && targetm.small_register_classes_for_mode_p in noce_process_if_block()
3474 /* Likewise with X. In particular this can happen when in noce_process_if_block()
3476 stream than one might expect. */ in noce_process_if_block()
3487 convert. But even in that case we would need to restore any notes in noce_process_if_block()
3488 (such as REG_INC) at then end. That can be tricky if in noce_process_if_block()
3490 optimization entirely for now if there are side effects. */ in noce_process_if_block()
3497 the lifetime of hard registers on small register class machines. */ in noce_process_if_block()
3502 && targetm.small_register_classes_for_mode_p (GET_MODE (x)))) in noce_process_if_block()
3516 /* Don't operate on sources that may trap or are volatile. */ in noce_process_if_block()
3521 /* Set up the info block for our subroutines. */ in noce_process_if_block()
3528 /* Try optimizations in some approximation of a useful order. */ in noce_process_if_block()
3529 /* ??? Should first look to see if X is live incoming at all. If it in noce_process_if_block()
3530 isn't, we don't need anything but an unconditional set. */ in noce_process_if_block()
3532 /* Look and see if A and B are really the same. Avoid creating silly in noce_process_if_block()
3533 cmove constructs that no one will fix up later. */ in noce_process_if_block()
3537 /* If we have an INSN_B, we don't have to create any new rtl. Just in noce_process_if_block()
3538 move the instruction that we already have. If we don't have an in noce_process_if_block()
3539 INSN_B, that means that A == X, and we've got a noop move. In in noce_process_if_block()
3540 that case don't do anything and let the code below delete INSN_A. */ in noce_process_if_block()
3550 true due to this insn being after a jump. */ in noce_process_if_block()
3556 /* If we have "x = b; if (...) x = a;", and x has side-effects, then in noce_process_if_block()
3557 x must be executed twice. */ in noce_process_if_block()
3570 which do a good enough job these days. */ in noce_process_if_block()
3587 if (!targetm.have_conditional_execution () in noce_process_if_block()
3593 if (! targetm.have_conditional_execution ()) in noce_process_if_block()
3621 /* If we used a temporary, fix it up now. */ in noce_process_if_block()
3636 /* The original THEN and ELSE blocks may now be removed. The test block in noce_process_if_block()
3637 must now jump to the join block. If the test block and the join block in noce_process_if_block()
3638 can be merged, do so. */ in noce_process_if_block()
3662 /* Check whether a block is suitable for conditional move conversion.
3664 register. For each assignment, store the value in the pointer map
3666 pointer in REGS. COND is the condition we will test. */
3677 /* We can only handle simple jumps at the end of the basic block. in check_cond_move_block()
3678 It is almost impossible to update the CFG otherwise. */ in check_cond_move_block()
3697 && targetm.small_register_classes_for_mode_p (GET_MODE (dest)))) in check_cond_move_block()
3710 modified earlier in the block. */ in check_cond_move_block()
3718 modified earlier in the block. */ in check_cond_move_block()
3723 destination register. */ in check_cond_move_block()
3728 later in the block. */ in check_cond_move_block()
3733 /* Skip it if the instruction to be moved might clobber CC. */ in check_cond_move_block()
3748 conditional moves. If ELSE_BLOCK is true, THEN_BB was already
3749 processed. The caller has started a sequence for the conversion.
3750 Return true if successful, false if something goes wrong. */
3787 handled this case there. */ in cond_move_convert_if_block()
3813 it using only conditional moves. Return TRUE if we were successful at
3814 converting the block. */
3835 register. */ in cond_move_process_if_block()
3839 /* Make sure the blocks are suitable. */ in cond_move_process_if_block()
3845 /* Make sure the blocks can be used together. If the same register in cond_move_process_if_block()
3847 cases, then both blocks must set it to the same register. We in cond_move_process_if_block()
3849 source register does not change after the assignment. Also count in cond_move_process_if_block()
3850 the number of registers set in only one of the blocks. */ in cond_move_process_if_block()
3854 rtx *then_slot = then_vals.get (reg); in cond_move_process_if_block()
3855 rtx *else_slot = else_vals.get (reg); in cond_move_process_if_block()
3870 /* Finish off c for MAX_CONDITIONAL_EXECUTE. */ in cond_move_process_if_block()
3873 gcc_checking_assert (else_vals.get (reg)); in cond_move_process_if_block()
3874 if (!then_vals.get (reg)) in cond_move_process_if_block()
3878 /* Make sure it is reasonable to convert this block. What matters in cond_move_process_if_block()
3881 them. */ in cond_move_process_if_block()
3886 /* Try to emit the conditional moves. First do the then block, in cond_move_process_if_block()
3887 then do anything left in the else blocks. */ in cond_move_process_if_block()
3933 then_regs.release (); in cond_move_process_if_block()
3934 else_regs.release (); in cond_move_process_if_block()
3940 IF-THEN-ELSE-JOIN block.
3943 using only transformations that do not require conditional execution.
3945 Return TRUE if we were successful at converting the block. */
3959 /* We only ever should get here before reload. */ in noce_find_if_block()
3962 /* Recognize an IF-THEN-ELSE-JOIN block. */ in noce_find_if_block()
3973 /* Recognize an IF-THEN-JOIN block. */ in noce_find_if_block()
3982 /* Recognize an IF-ELSE-JOIN block. We can have those because the order in noce_find_if_block()
3985 cfgrtl mode). */ in noce_find_if_block()
3990 /* The noce transformations do not apply to IF-ELSE-JOIN blocks. in noce_find_if_block()
3992 and reverse the jump condition. */ in noce_find_if_block()
3999 /* Not a form we can handle. */ in noce_find_if_block()
4002 /* The edges of the THEN and ELSE blocks cannot have complex edges. */ in noce_find_if_block()
4025 jump, then we can not do if-conversion on this block. */ in noce_find_if_block()
4030 /* If this is not a standard conditional jump, we can't parse it. */ in noce_find_if_block()
4035 /* We must be comparing objects whose modes imply the size. */ in noce_find_if_block()
4039 /* Initialize an IF_INFO struct to pass around. */ in noce_find_if_block()
4041 if_info.test_bb = test_bb; in noce_find_if_block()
4042 if_info.then_bb = then_bb; in noce_find_if_block()
4043 if_info.else_bb = else_bb; in noce_find_if_block()
4044 if_info.join_bb = join_bb; in noce_find_if_block()
4045 if_info.cond = cond; in noce_find_if_block()
4047 if_info.rev_cond = noce_get_condition (jump, &rev_cond_earliest, in noce_find_if_block()
4049 gcc_assert (if_info.rev_cond == NULL_RTX in noce_find_if_block()
4051 if_info.cond_earliest = cond_earliest; in noce_find_if_block()
4052 if_info.jump = jump; in noce_find_if_block()
4053 if_info.then_else_reversed = then_else_reversed; in noce_find_if_block()
4054 if_info.speed_p = speed_p; in noce_find_if_block()
4055 if_info.max_seq_cost in noce_find_if_block()
4056 = targetm.max_noce_ifcvt_seq_cost (then_edge); in noce_find_if_block()
4058 that they are valid to transform. We can't easily get back to the insn in noce_find_if_block()
4061 both instructions as having cost COSTS_N_INSNS (1). */ in noce_find_if_block()
4062 if_info.original_cost = COSTS_N_INSNS (2); in noce_find_if_block()
4065 /* Do the real work. */ in noce_find_if_block()
4078 /* Merge the blocks and mark for local life update. */
4089 /* All block merging is done into the lower block numbers. */ in merge_if_block()
4094 /* Merge any basic blocks to handle && and || subtests. Each of in merge_if_block()
4095 the blocks are on the fallthru path from the predecessor block. */ in merge_if_block()
4112 /* Merge TEST block into THEN block. Normally the THEN block won't have a in merge_if_block()
4113 label, but it might if there were || tests. That label's count should be in merge_if_block()
4114 zero, and it normally should be removed. */ in merge_if_block()
4118 /* If THEN_BB has no successors, then there's a BARRIER after it. in merge_if_block()
4121 the insn stream. */ in merge_if_block()
4136 /* The ELSE block, if it existed, had a label. That label count in merge_if_block()
4138 get their addresses taken. */ in merge_if_block()
4141 /* If ELSE_BB has no successors, then there's a BARRIER after it. in merge_if_block()
4144 the insn stream. */ in merge_if_block()
4160 to the others, and so we cannot merge them. */ in merge_if_block()
4167 be correct. Verify this. */ in merge_if_block()
4177 blocks taking us to our final destination. */ in merge_if_block()
4187 /* The JOIN block may have had quite a number of other predecessors too. in merge_if_block()
4189 have only one remaining edge from our if-then-else diamond. If there in merge_if_block()
4190 is more than one remaining edge, it must come from elsewhere. There in merge_if_block()
4192 back up (as with a call to a non-return function). */ in merge_if_block()
4197 again on this pass.*/ in merge_if_block()
4203 /* We cannot merge the JOIN. */ in merge_if_block()
4206 be correct. Verify this. */ in merge_if_block()
4210 /* Remove the jump and cruft from the end of the COMBO block. */ in merge_if_block()
4219 in some way. When converting a multi-block condition, put the new code
4220 in the first such block and delete the rest. Return a pointer to this
4221 first block if some transformation was done. Return NULL otherwise. */
4230 /* The kind of block we're looking for has exactly two successors. */ in find_if_header()
4242 /* Neither edge should be abnormal. */ in find_if_header()
4247 /* Nor exit the loop. */ in find_if_header()
4252 /* The THEN edge is canonically the one that falls through. */ in find_if_header()
4258 /* Otherwise this must be a multiway branch of some sort. */ in find_if_header()
4262 ce_info.test_bb = test_bb; in find_if_header()
4263 ce_info.then_bb = then_edge->dest; in find_if_header()
4264 ce_info.else_bb = else_edge->dest; in find_if_header()
4265 ce_info.pass = pass; in find_if_header()
4276 && targetm.have_conditional_execution () in find_if_header()
4280 if (targetm.have_trap () in find_if_header()
4286 && (reload_completed || !targetm.have_conditional_execution ())) in find_if_header()
4298 fprintf (dump_file, "Conversion succeeded on pass %d.\n", pass); in find_if_header()
4299 /* Set this so we continue looking. */ in find_if_header()
4301 return ce_info.test_bb; in find_if_header()
4306 block is part of an && test or an || test. Returns either -1 or the number
4307 of non-note, non-jump, non-USE/CLOBBER insns in the block. */
4323 /* If no edges, obviously it doesn't jump or fallthru. */ in block_jumps_and_fallthru_p()
4330 /* Anything complex isn't what we want. */ in block_jumps_and_fallthru_p()
4347 together for conditional execution support. ??? we should support in block_jumps_and_fallthru_p()
4349 for now it makes the code simpler. */ in block_jumps_and_fallthru_p()
4375 block. If so, we'll try to convert the insns to not require the branch.
4376 Return TRUE if we were successful at converting the block. */
4392 and if we have conditional execution. */ in cond_exec_find_if_block()
4393 gcc_assert (reload_completed && targetm.have_conditional_execution ()); in cond_exec_find_if_block()
4397 the then block). */ in cond_exec_find_if_block()
4406 /* Determine if the preceding block is an && or || block. */ in cond_exec_find_if_block()
4427 /* Found at least one && or || block, look for more. */ in cond_exec_find_if_block()
4453 other than any || blocks which jump to the THEN block. */ in cond_exec_find_if_block()
4457 /* The edges of the THEN and ELSE blocks cannot have complex edges. */ in cond_exec_find_if_block()
4470 /* The THEN block of an IF-THEN combo must have zero or one successors. */ in cond_exec_find_if_block()
4479 make a conditional call. Don't do this unless the ELSE block has in cond_exec_find_if_block()
4480 only one incoming edge -- the CFG manipulation is too ugly otherwise. in cond_exec_find_if_block()
4483 code processing. ??? we should fix this in the future. */ in cond_exec_find_if_block()
4508 then we have an IF-THEN combo without an ELSE. */ in cond_exec_find_if_block()
4517 is not complex, then we have an IF-THEN-ELSE combo. */ in cond_exec_find_if_block()
4526 /* Otherwise it is not an IF-THEN or IF-THEN-ELSE combination. */ in cond_exec_find_if_block()
4566 /* Make sure IF, THEN, and ELSE, blocks are adjacent. Actually, we get the in cond_exec_find_if_block()
4568 fallthru edge from IF to THEN. Likewise for the && and || blocks, since in cond_exec_find_if_block()
4570 block. */ in cond_exec_find_if_block()
4571 /* ??? As an enhancement, move the ELSE block. Have to deal with in cond_exec_find_if_block()
4573 exist. Sticky enough I don't want to think about it now. */ in cond_exec_find_if_block()
4586 /* Do the real work. */ in cond_exec_find_if_block()
4594 was no ELSE block. */ in cond_exec_find_if_block()
4610 to a trap, into a conditional trap. */
4622 /* Locate the block with the trap instruction. */ in find_cond_trap()
4624 EH successors. Need to fix merge_if_block for that to work. */ in find_cond_trap()
4638 /* If this is not a standard conditional jump, we can't parse it. */ in find_cond_trap()
4645 we can not do if-conversion on this block. Give up for returnjump_p, in find_cond_trap()
4648 beneficial and harder to handle. */ in find_cond_trap()
4652 /* We must be comparing objects whose modes imply the size. */ in find_cond_trap()
4656 /* Attempt to generate the conditional trap. */ in find_cond_trap()
4663 /* If that results in an invalid insn, back out. */ in find_cond_trap()
4668 /* Emit the new insns before cond_earliest. */ in find_cond_trap()
4671 /* Delete the trap block if possible. */ in find_cond_trap()
4683 /* Wire together the blocks again. */ in find_cond_trap()
4689 rtx_insn *seq = targetm.gen_jump (lab); in find_cond_trap()
4708 return it. */
4715 /* We're not the exit block. */ in block_has_only_trap()
4719 /* The block must have no successors. */ in block_has_only_trap()
4723 /* The only instruction in the THEN block must be the trap. */ in block_has_only_trap()
4734 transformable, but not necessarily the other. There need be no
4735 JOIN block.
4737 Return TRUE if we were successful at converting the block.
4768 // multiway branching, e.g. IA-64 BBB bundles. For other targets
4770 // does not sit well with predictors.
4774 if (test2) goto F;
4775 ...
4784 if (test2) goto F;
4789 eliminating. Do it anyway if we can eliminate a branch; this requires
4791 side of the if.
4798 if (test2) goto F;
4799 ...
4802 Again, this is most useful if J postdominates.
4804 (C) CE substitutes for helpful life information.
4806 (D) These heuristics need a lot of work. */
4808 /* Tests for case 1 above. */
4822 and cold sections. in find_if_case_1()
4827 partition boundaries). See the comments at the top of in find_if_case_1()
4828 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */ in find_if_case_1()
4841 /* THEN has one successor. */ in find_if_case_1()
4845 /* THEN does not fall through, but is not strange either. */ in find_if_case_1()
4849 /* THEN has one predecessor. */ in find_if_case_1()
4853 /* THEN must do something. */ in find_if_case_1()
4863 then_prob = then_edge->probability.invert (); in find_if_case_1()
4866 of speculation is within reason. */ in find_if_case_1()
4879 /* Registers set are dead, or are predicable. */ in find_if_case_1()
4885 jump. Adjust the CFG to match. */ in find_if_case_1()
4888 followed by else_bb, i.e. deleting then_bb allows test_bb to fall in find_if_case_1()
4889 through to else_bb. */ in find_if_case_1()
4912 block we removed. */ in find_if_case_1()
4917 (possibly called from redirect_edge_and_branch_force). */ in find_if_case_1()
4926 /* Test for case 2 above. */
4936 /* We do not want to speculate (empty) loop latches. */ in find_if_case_2()
4943 and cold sections. in find_if_case_2()
4948 partition boundaries). See the comments at the top of in find_if_case_2()
4949 bb-reorder.c:partition_hot_cold_basic_blocks for complete details. */ in find_if_case_2()
4962 /* ELSE has one successor. */ in find_if_case_2()
4968 /* ELSE outgoing edge is not complex. */ in find_if_case_2()
4972 /* ELSE has one predecessor. */ in find_if_case_2()
4976 /* THEN is not EXIT. */ in find_if_case_2()
4981 then_prob = else_prob.invert (); in find_if_case_2()
4983 /* ELSE is predicted or SUCC(ELSE) postdominates THEN. */ in find_if_case_2()
5000 of speculation is within reason. */ in find_if_case_2()
5006 /* Registers set are dead, or are predicable. */ in find_if_case_2()
5011 jump. Adjust the CFG to match. */ in find_if_case_2()
5021 block. Rerun cleanup_cfg? Examine things manually? Wait? */ in find_if_case_2()
5026 /* Used by the code above to perform the actual rtl transformations.
5027 Return TRUE if successful.
5029 TEST_BB is the block containing the conditional branch. MERGE_BB
5030 is the block containing the code to manipulate. DEST_EDGE is an
5032 TEST_BB should be branching to its destination.
5033 REVERSEP is true if the sense of the branch should be reversed. */
5044 /* Number of pending changes. */ in dead_or_predicable()
5050 /* Find the extent of the real code in the merge block. */ in dead_or_predicable()
5060 get an unresolved reference to the jumptable. */ in dead_or_predicable()
5094 /* Don't move frame-related insn across the conditional branch. This in dead_or_predicable()
5095 can lead to one of the paths of the branch having wrong unwind info. */ in dead_or_predicable()
5110 to do anything funny with the tests, etc. */ in dead_or_predicable()
5112 if (targetm.have_conditional_execution ()) in dead_or_predicable()
5114 /* In the conditional execution case, we have things easy. We know in dead_or_predicable()
5115 the condition is reversible. We don't have to check life info in dead_or_predicable()
5116 because we're going to conditionally execute the code anyway. in dead_or_predicable()
5118 be predicated. */ in dead_or_predicable()
5138 prob_val = prob_val.invert (); in dead_or_predicable()
5151 /* If we allocated new pseudos (e.g. in the conditional move in dead_or_predicable()
5153 array first. */ in dead_or_predicable()
5157 /* Try the NCE path if the CE path did not result in any changes. */ in dead_or_predicable()
5167 that any registers modified are dead at the branch site. */ in dead_or_predicable()
5172 /* Find the extent of the conditional. */ in dead_or_predicable()
5186 /* Collect the set of registers set in MERGE_BB. */ in dead_or_predicable()
5194 the first basic block and merge_bb exits. The idea is to not in dead_or_predicable()
5197 saved in caller-saved regs. A caller-saved reg requires the in dead_or_predicable()
5198 prologue, killing a shrink-wrap opportunity. */ in dead_or_predicable()
5211 params and regs used to return values. */ in dead_or_predicable()
5214 && targetm.calls.function_value_regno_p (i)) in dead_or_predicable()
5229 reg uses to the set of regs we're interested in. */ in dead_or_predicable()
5250 we don't want to delete_insn called. Also, we want to do our own in dead_or_predicable()
5251 change group management. */ in dead_or_predicable()
5292 /* Move the insns out of MERGE_BB to before the branch. */ in dead_or_predicable()
5301 notes being moved might become invalid. */ in dead_or_predicable()
5316 notes referring to the registers being set might become invalid. */ in dead_or_predicable()
5331 /* Remove the jump and edge if we can. */ in dead_or_predicable()
5336 /* ??? Can't merge blocks here, as then_bb is still in use. in dead_or_predicable()
5337 At minimum, the merge will get done just before bb-reorder. */ in dead_or_predicable()
5351 /* Main entry point for all if-conversion. AFTER_COMBINE is true if
5352 we are after combine pass. */
5366 /* Record whether we are after combine pass. */ in if_convert()
5379 /* Compute postdominators. */ in if_convert()
5384 /* Go through each of the basic blocks looking for things to convert. If we in if_convert()
5386 IF-THEN{-ELSE} blocks within other IF-THEN{-ELSE} blocks. */ in if_convert()
5391 /* Only need to do dce on the first pass. */ in if_convert()
5428 /* If we allocated new pseudos, we must resize the array for sched1. */ in if_convert()
5432 /* Write the final stats. */ in if_convert()
5436 "\n%d possible IF blocks searched.\n", in if_convert()
5439 "%d IF blocks converted.\n", in if_convert()
5442 "%d true changes made.\n\n\n", in if_convert()
5449 /* Some non-cold blocks may now be only reachable from cold blocks. in if_convert()
5450 Fix that up. */ in if_convert()
5456 /* If-conversion and CFG cleanup. */
5520 to now meet sequence length restrictions. */