diff options
author | Alexander Monakov <amonakov@ispras.ru> | 2019-10-02 18:37:12 +0300 |
---|---|---|
committer | Alexander Monakov <amonakov@gcc.gnu.org> | 2019-10-02 18:37:12 +0300 |
commit | 1764d63bd98c6c08e993f5c39dfa0247985b1642 (patch) | |
tree | 8afecb03e7053f721f894c1ca4ab7fa0bc95928e /gcc/ifcvt.c | |
parent | a264ea9a5bbbbf78ea8c53b675584d1f218e20db (diff) | |
download | gcc-1764d63bd98c6c08e993f5c39dfa0247985b1642.zip gcc-1764d63bd98c6c08e993f5c39dfa0247985b1642.tar.gz gcc-1764d63bd98c6c08e993f5c39dfa0247985b1642.tar.bz2 |
ifcvt: improve cost estimation (PR 87047)
PR rtl-optimization/87047
* ifcvt.c (average_cost): New static function. Use it...
(noce_process_if_block): ... here.
testsuite/
* gcc.dg/pr87047.c: New test.
From-SVN: r276466
Diffstat (limited to 'gcc/ifcvt.c')
-rw-r--r-- | gcc/ifcvt.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index e0c9522..8bc6f53 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3358,6 +3358,16 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb) return count > 1 && count <= param; } +/* Compute average of two given costs weighted by relative probabilities + of respective basic blocks in an IF-THEN-ELSE. E is the IF-THEN edge. + With P as the probability to take the IF-THEN branch, return + P * THEN_COST + (1 - P) * ELSE_COST. */ +static unsigned +average_cost (unsigned then_cost, unsigned else_cost, edge e) +{ + return else_cost + e->probability.apply ((signed) (then_cost - else_cost)); +} + /* Given a simple IF-THEN-JOIN or IF-THEN-ELSE-JOIN block, attempt to convert it without using conditional execution. Return TRUE if we were successful at converting the block. */ @@ -3413,10 +3423,9 @@ noce_process_if_block (struct noce_if_info *if_info) &if_info->else_simple)) return false; - if (else_bb == NULL) - if_info->original_cost += then_cost; - else if (speed_p) - if_info->original_cost += MIN (then_cost, else_cost); + if (speed_p) + if_info->original_cost += average_cost (then_cost, else_cost, + find_edge (test_bb, then_bb)); else if_info->original_cost += then_cost + else_cost; |