diff options
author | Richard Biener <rguenther@suse.de> | 2022-05-17 17:39:22 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-05-17 17:39:22 +0200 |
commit | 3a3e129ce081c7936e7470d0a2cb3c0fbdd7490b (patch) | |
tree | 99469bbd74ddc904af1e79120f40472fb4b018aa | |
parent | 0cc1e771238dbd8ea576aba70568e1c530f5f652 (diff) | |
download | gcc-3a3e129ce081c7936e7470d0a2cb3c0fbdd7490b.zip gcc-3a3e129ce081c7936e7470d0a2cb3c0fbdd7490b.tar.gz gcc-3a3e129ce081c7936e7470d0a2cb3c0fbdd7490b.tar.bz2 |
Really use first found predicate. Adjust limit for loop-unswitch-16.c
-rw-r--r-- | gcc/testsuite/gcc.dg/loop-unswitch-16.c | 2 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-unswitch.cc | 60 |
2 files changed, 35 insertions, 27 deletions
diff --git a/gcc/testsuite/gcc.dg/loop-unswitch-16.c b/gcc/testsuite/gcc.dg/loop-unswitch-16.c index 0e530d4..f8eac16 100644 --- a/gcc/testsuite/gcc.dg/loop-unswitch-16.c +++ b/gcc/testsuite/gcc.dg/loop-unswitch-16.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -funswitch-loops -fdump-tree-unswitch-optimized" } */ +/* { dg-options "-O2 -funswitch-loops -fdump-tree-unswitch-optimized --param max-unswitch-insns=100" } */ void bar (int); void foo (int a, int b, int c, int n) diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc index 456be7e..b245885 100644 --- a/gcc/tree-ssa-loop-unswitch.cc +++ b/gcc/tree-ssa-loop-unswitch.cc @@ -247,7 +247,7 @@ init_loop_unswitch_info (class loop *loop) gsi_next (&gsi)) insns += estimate_num_insns (gsi_stmt (gsi), &eni_size_weights); - bbs[i]->aux = (void *)(size_t)insns; + bbs[i]->aux = (void *)(uintptr_t)insns; total_insns += insns; } @@ -812,6 +812,8 @@ evaluate_insns (class loop *loop, basic_block *bbs, ignored_edge_flag, &ignored_edges); + /* ??? We fail to account for removed condition or switch stmts. */ + FOR_EACH_EDGE (e, ei, bb->succs) { basic_block dest = e->dest; @@ -834,7 +836,7 @@ evaluate_insns (class loop *loop, basic_block *bbs, if (bbs[i]->flags & reachable_flag) { bbs[i]->flags &= ~reachable_flag; - size += (size_t)bbs[i]->aux; + size += (uintptr_t)bbs[i]->aux; } } @@ -888,32 +890,38 @@ tree_unswitch_single_loop (class loop *loop, dump_user_location_t loc, bbs = get_loop_body (loop); for (unsigned i = 0; i < loop->num_nodes; i++) - for (auto pred : get_predicates_for_bb (bbs[i])) - { - if (bitmap_bit_p (handled, pred->num)) - continue; + { + for (auto pred : get_predicates_for_bb (bbs[i])) + { + if (bitmap_bit_p (handled, pred->num)) + continue; - evaluate_loop_insns_for_predicate (loop, bbs, predicate_path, - pred, ignored_edge_flag, - &true_size, &false_size); + evaluate_loop_insns_for_predicate (loop, bbs, predicate_path, + pred, ignored_edge_flag, + &true_size, &false_size); + gcc_assert (true_size + false_size >= loop_size); - /* FIXME: right now we select first candidate, but we can choose - the cheapest or hottest one. */ - if (true_size + false_size < budget + loop_size) - { - predicate = pred; - bb = bbs[i]; - /* We get one more simplified loop copy and the original - loop simplified. */ - budget -= (true_size + false_size - loop_size); - break; - } - else if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, loc, - "Not unswitching condition, cost too big " - "(%u insns copied to %u and %u)\n", loop_size, - true_size, false_size); - } + /* FIXME: right now we select first candidate, but we can choose + the cheapest or hottest one. */ + if (true_size + false_size < budget + loop_size) + { + predicate = pred; + bb = bbs[i]; + /* We get one more simplified loop copy and the original + loop simplified. + ??? We fail to account for the versioning condition. */ + budget -= (true_size + false_size - loop_size); + break; + } + else if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, loc, + "Not unswitching condition, cost too big " + "(%u insns copied to %u and %u)\n", loop_size, + true_size, false_size); + } + if (predicate) + break; + } if (predicate != NULL) { |