Message ID | ZOXM6mIc0hZbwWeB@kam.mff.cuni.cz |
---|---|
State | New |
Headers | show |
Series | Fix profile update in tree-ssa-reassoc | expand |
> Date: Wed, 23 Aug 2023 11:10:02 +0200 > From: Jan Hubicka via Gcc-patches <gcc-patches@gcc.gnu.org> > Hi, > this patch adds missing profile update to maybe_optimize_range_tests. [...] > Jakub, it seems that the code is originally yours. Any idea why those are not turned to > constant true or false conditionals? > > Bootstrapped/regtested x86_64-linux, does it seem to make sense? > > gcc/ChangeLog: > > PR tree-optimization/110628 > * tree-ssa-reassoc.cc (maybe_optimize_range_tests): Add profile update. Hi. Feeling somewhat guilty for not noticing that you had posted a patch before me xfailing it, I went ahead and tested this patch for cris-elf against r14-3431-g7e05cd632fab, but unfortunately it regresses a few tests, and it appears it's not just testcase (dumps) that need tweaking. Four test-cases regress (counting multiple runs as just one): Running /x/gcc/gcc/testsuite/gcc.c-torture/execute/execute.exp ... FAIL: gcc.c-torture/execute/pr95731.c -O1 execution test FAIL: gcc.c-torture/execute/pr95731.c -O2 execution test FAIL: gcc.c-torture/execute/pr95731.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test FAIL: gcc.c-torture/execute/pr95731.c -O3 -g execution test FAIL: gcc.c-torture/execute/pr95731.c -Os execution test FAIL: gcc.c-torture/execute/pr95731.c -O2 -flto -fno-use-linker-plugin -flto-partition=none execution test FAIL: gcc.c-torture/execute/pr95731.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects execution test ... Running /x/gcc/gcc/testsuite/gcc.dg/dg.exp ... FAIL: gcc.dg/pr46309-2.c scan-tree-dump-times reassoc2 "Optimizing range tests [^\r\n]*_[0-9]* -.0, 0. and -.128, 128.[\n\r]* into" 1 ... Running /x/gcc/gcc/testsuite/gcc.dg/torture/dg-torture.exp ... FAIL: gcc.dg/torture/pr63464.c -Os execution test ... Running /x/gcc/gcc/testsuite/gcc.dg/tree-ssa/tree-ssa.exp ... ... FAIL: gcc.dg/tree-ssa/pr95731.c scan-tree-dump-times optimized " >= 0| < 0" 6 brgds, H-P
diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index eda03bf98a6..a718a0f41f1 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -5091,6 +5091,8 @@ maybe_optimize_range_tests (gimple *stmt) if (bb == first_bb) break; } + profile_probability extra_other_prob = profile_probability::never (); + auto_vec<basic_block, 8> bbs; for (bb = last_bb, idx = 0; ; bb = single_pred (bb), idx++) { if (bbinfo[idx].first_idx < bbinfo[idx].last_idx @@ -5098,6 +5100,8 @@ maybe_optimize_range_tests (gimple *stmt) && ops[bbinfo[idx].first_idx]->op != NULL_TREE) { gcond *cond_stmt = as_a <gcond *> (*gsi_last_bb (bb)); + edge true_e, false_e; + extract_true_false_edges_from_block (bb, &true_e, &false_e); if (idx > max_idx) max_idx = idx; @@ -5108,25 +5112,50 @@ maybe_optimize_range_tests (gimple *stmt) { gimple_cond_make_false (cond_stmt); cfg_cleanup_needed = true; + if (true_e->dest == other_bb) + extra_other_prob += true_e->probability; + false_e->probability = profile_probability::always (); + true_e->probability = profile_probability::never (); } else if (integer_onep (ops[bbinfo[idx].first_idx]->op)) { gimple_cond_make_true (cond_stmt); cfg_cleanup_needed = true; + if (false_e->dest == other_bb) + extra_other_prob += false_e->probability; + true_e->probability = profile_probability::always (); + false_e->probability = profile_probability::never (); } else { + gcc_assert (bb = first_bb); gimple_cond_set_code (cond_stmt, NE_EXPR); gimple_cond_set_lhs (cond_stmt, ops[bbinfo[idx].first_idx]->op); gimple_cond_set_rhs (cond_stmt, boolean_false_node); + if (bb->count.initialized_p () && bb->count.nonzero_p ()) + { + edge e_to_other = true_e->dest == other_bb + ? true_e : false_e; + edge e_to_tests = true_e->dest == other_bb + ? false_e : true_e; + e_to_other->probability += extra_other_prob; + e_to_tests->probability + = e_to_other->probability.invert (); + } } update_stmt (cond_stmt); } if (bb == first_bb) break; + bbs.safe_push (bb); + extra_other_prob *= single_pred_edge (bb)->probability; } + /* Finaly update counts of basic blocks in the chain. */ + for (basic_block bb : bbs) + bb->count = single_pred_edge (bb)->count (); + /* The above changes could result in basic blocks after the first modified one, up to and including last_bb, to be executed even if they would not be in the original program. If the value ranges of