comparison gcc/ifcvt.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* If-conversion support. 1 /* If-conversion support.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc. 2 Copyright (C) 2000-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it 6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by 7 under the terms of the GNU General Public License as published by
43 #include "tree-pass.h" 43 #include "tree-pass.h"
44 #include "dbgcnt.h" 44 #include "dbgcnt.h"
45 #include "shrink-wrap.h" 45 #include "shrink-wrap.h"
46 #include "rtl-iter.h" 46 #include "rtl-iter.h"
47 #include "ifcvt.h" 47 #include "ifcvt.h"
48 #include "params.h"
49 48
50 #ifndef MAX_CONDITIONAL_EXECUTE 49 #ifndef MAX_CONDITIONAL_EXECUTE
51 #define MAX_CONDITIONAL_EXECUTE \ 50 #define MAX_CONDITIONAL_EXECUTE \
52 (BRANCH_COST (optimize_function_for_speed_p (cfun), false) \ 51 (BRANCH_COST (optimize_function_for_speed_p (cfun), false) \
53 + 1) 52 + 1)
501 test_expr = cond_exec_get_condition (BB_END (test_bb)); 500 test_expr = cond_exec_get_condition (BB_END (test_bb));
502 if (! test_expr) 501 if (! test_expr)
503 return FALSE; 502 return FALSE;
504 503
505 /* If the conditional jump is more than just a conditional jump, 504 /* If the conditional jump is more than just a conditional jump,
506 then we can not do conditional execution conversion on this block. */ 505 then we cannot do conditional execution conversion on this block. */
507 if (! onlyjump_p (BB_END (test_bb))) 506 if (! onlyjump_p (BB_END (test_bb)))
508 return FALSE; 507 return FALSE;
509 508
510 /* Collect the bounds of where we're to search, skipping any labels, jumps 509 /* Collect the bounds of where we're to search, skipping any labels, jumps
511 and notes at the beginning and end of the block. Then count the total 510 and notes at the beginning and end of the block. Then count the total
650 && ! cond_exec_process_insns (ce_info, start, end, false_expr, 649 && ! cond_exec_process_insns (ce_info, start, end, false_expr,
651 false_prob_val, FALSE)) 650 false_prob_val, FALSE))
652 goto fail; 651 goto fail;
653 652
654 /* If the conditional jump is more than just a conditional jump, then 653 /* If the conditional jump is more than just a conditional jump, then
655 we can not do conditional execution conversion on this block. */ 654 we cannot do conditional execution conversion on this block. */
656 if (! onlyjump_p (BB_END (bb))) 655 if (! onlyjump_p (BB_END (bb)))
657 goto fail; 656 goto fail;
658 657
659 /* Find the conditional jump and isolate the test. */ 658 /* Find the conditional jump and isolate the test. */
660 t = cond_exec_get_condition (BB_END (bb)); 659 t = cond_exec_get_condition (BB_END (bb));
3309 static bool 3308 static bool
3310 bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) 3309 bb_ok_for_noce_convert_multiple_sets (basic_block test_bb)
3311 { 3310 {
3312 rtx_insn *insn; 3311 rtx_insn *insn;
3313 unsigned count = 0; 3312 unsigned count = 0;
3314 unsigned param = PARAM_VALUE (PARAM_MAX_RTL_IF_CONVERSION_INSNS); 3313 unsigned param = param_max_rtl_if_conversion_insns;
3315 3314
3316 FOR_BB_INSNS (test_bb, insn) 3315 FOR_BB_INSNS (test_bb, insn)
3317 { 3316 {
3318 /* Skip over notes etc. */ 3317 /* Skip over notes etc. */
3319 if (!active_insn_p (insn)) 3318 if (!active_insn_p (insn))
3354 this pass tries are better optimized and will be more appropriate. 3353 this pass tries are better optimized and will be more appropriate.
3355 Some targets want to strictly limit the number of conditional moves 3354 Some targets want to strictly limit the number of conditional moves
3356 that are emitted, they set this through PARAM, we need to respect 3355 that are emitted, they set this through PARAM, we need to respect
3357 that. */ 3356 that. */
3358 return count > 1 && count <= param; 3357 return count > 1 && count <= param;
3358 }
3359
3360 /* Compute average of two given costs weighted by relative probabilities
3361 of respective basic blocks in an IF-THEN-ELSE. E is the IF-THEN edge.
3362 With P as the probability to take the IF-THEN branch, return
3363 P * THEN_COST + (1 - P) * ELSE_COST. */
3364 static unsigned
3365 average_cost (unsigned then_cost, unsigned else_cost, edge e)
3366 {
3367 return else_cost + e->probability.apply ((signed) (then_cost - else_cost));
3359 } 3368 }
3360 3369
3361 /* Given a simple IF-THEN-JOIN or IF-THEN-ELSE-JOIN block, attempt to convert 3370 /* Given a simple IF-THEN-JOIN or IF-THEN-ELSE-JOIN block, attempt to convert
3362 it without using conditional execution. Return TRUE if we were successful 3371 it without using conditional execution. Return TRUE if we were successful
3363 at converting the block. */ 3372 at converting the block. */
3411 if (else_bb 3420 if (else_bb
3412 && !bb_valid_for_noce_process_p (else_bb, cond, &else_cost, 3421 && !bb_valid_for_noce_process_p (else_bb, cond, &else_cost,
3413 &if_info->else_simple)) 3422 &if_info->else_simple))
3414 return false; 3423 return false;
3415 3424
3416 if (else_bb == NULL) 3425 if (speed_p)
3417 if_info->original_cost += then_cost; 3426 if_info->original_cost += average_cost (then_cost, else_cost,
3418 else if (speed_p) 3427 find_edge (test_bb, then_bb));
3419 if_info->original_cost += MIN (then_cost, else_cost);
3420 else 3428 else
3421 if_info->original_cost += then_cost + else_cost; 3429 if_info->original_cost += then_cost + else_cost;
3422 3430
3423 insn_a = last_active_insn (then_bb, FALSE); 3431 insn_a = last_active_insn (then_bb, FALSE);
3424 set_a = single_set (insn_a); 3432 set_a = single_set (insn_a);
3827 int c; 3835 int c;
3828 vec<rtx> then_regs = vNULL; 3836 vec<rtx> then_regs = vNULL;
3829 vec<rtx> else_regs = vNULL; 3837 vec<rtx> else_regs = vNULL;
3830 unsigned int i; 3838 unsigned int i;
3831 int success_p = FALSE; 3839 int success_p = FALSE;
3832 int limit = PARAM_VALUE (PARAM_MAX_RTL_IF_CONVERSION_INSNS); 3840 int limit = param_max_rtl_if_conversion_insns;
3833 3841
3834 /* Build a mapping for each block to the value used for each 3842 /* Build a mapping for each block to the value used for each
3835 register. */ 3843 register. */
3836 hash_map<rtx, rtx> then_vals; 3844 hash_map<rtx, rtx> then_vals;
3837 hash_map<rtx, rtx> else_vals; 3845 hash_map<rtx, rtx> else_vals;
4020 4028
4021 fprintf (dump_file, ", join %d\n", join_bb->index); 4029 fprintf (dump_file, ", join %d\n", join_bb->index);
4022 } 4030 }
4023 4031
4024 /* If the conditional jump is more than just a conditional 4032 /* If the conditional jump is more than just a conditional
4025 jump, then we can not do if-conversion on this block. */ 4033 jump, then we cannot do if-conversion on this block. */
4026 jump = BB_END (test_bb); 4034 jump = BB_END (test_bb);
4027 if (! onlyjump_p (jump)) 4035 if (! onlyjump_p (jump))
4028 return FALSE; 4036 return FALSE;
4029 4037
4030 /* If this is not a standard conditional jump, we can't parse it. */ 4038 /* If this is not a standard conditional jump, we can't parse it. */
4640 cond = noce_get_condition (jump, &cond_earliest, then_bb == trap_bb); 4648 cond = noce_get_condition (jump, &cond_earliest, then_bb == trap_bb);
4641 if (! cond) 4649 if (! cond)
4642 return FALSE; 4650 return FALSE;
4643 4651
4644 /* If the conditional jump is more than just a conditional jump, then 4652 /* If the conditional jump is more than just a conditional jump, then
4645 we can not do if-conversion on this block. Give up for returnjump_p, 4653 we cannot do if-conversion on this block. Give up for returnjump_p,
4646 changing a conditional return followed by unconditional trap for 4654 changing a conditional return followed by unconditional trap for
4647 conditional trap followed by unconditional return is likely not 4655 conditional trap followed by unconditional return is likely not
4648 beneficial and harder to handle. */ 4656 beneficial and harder to handle. */
4649 if (! onlyjump_p (jump) || returnjump_p (jump)) 4657 if (! onlyjump_p (jump) || returnjump_p (jump))
4650 return FALSE; 4658 return FALSE;
5455 5463
5456 /* If-conversion and CFG cleanup. */ 5464 /* If-conversion and CFG cleanup. */
5457 static unsigned int 5465 static unsigned int
5458 rest_of_handle_if_conversion (void) 5466 rest_of_handle_if_conversion (void)
5459 { 5467 {
5468 int flags = 0;
5469
5460 if (flag_if_conversion) 5470 if (flag_if_conversion)
5461 { 5471 {
5462 if (dump_file) 5472 if (dump_file)
5463 { 5473 {
5464 dump_reg_info (dump_file); 5474 dump_reg_info (dump_file);
5465 dump_flow_info (dump_file, dump_flags); 5475 dump_flow_info (dump_file, dump_flags);
5466 } 5476 }
5467 cleanup_cfg (CLEANUP_EXPENSIVE); 5477 cleanup_cfg (CLEANUP_EXPENSIVE);
5468 if_convert (false); 5478 if_convert (false);
5469 } 5479 if (num_updated_if_blocks)
5470 5480 /* Get rid of any dead CC-related instructions. */
5471 cleanup_cfg (0); 5481 flags |= CLEANUP_FORCE_FAST_DCE;
5482 }
5483
5484 cleanup_cfg (flags);
5472 return 0; 5485 return 0;
5473 } 5486 }
5474 5487
5475 namespace { 5488 namespace {
5476 5489