diff options
author | Jan Hubicka <jh@suse.cz> | 2023-08-02 09:25:12 +0200 |
---|---|---|
committer | Jan Hubicka <jh@suse.cz> | 2023-08-02 09:25:12 +0200 |
commit | 2e93b92c1ec5fbbbe10765c6e059c3c90d564245 (patch) | |
tree | 2558f4a90e7cc2573f35a274dc5628097a964479 /gcc/tree-cfg.cc | |
parent | 07b7cd70399d22c113ad8bb1eff5cc2d12973d33 (diff) | |
download | gcc-2e93b92c1ec5fbbbe10765c6e059c3c90d564245.zip gcc-2e93b92c1ec5fbbbe10765c6e059c3c90d564245.tar.gz gcc-2e93b92c1ec5fbbbe10765c6e059c3c90d564245.tar.bz2 |
Fix profile update after cancelled loop distribution
Loop distribution and ifcvt introduces verisons of loops which may be removed
later if vectorization fails. Ifcvt does this by temporarily breaking profile
and producing conditional that has two arms with 100% probability because we
know one of the versions will be removed.
Loop distribution is trickier, since it introduces test for alignment that
either survives to final code if vecotorization suceeds or is turned if it
fails.
Here we need to assign some reasonable probabilities for the case vectorization
goes well, so this code adds logic to scale profile back in case we remove the
call.
This is not perfect since we drop precise BB counts to guessed. It is not big
deal since we do not use much reliablity of bb counts after this point. Other
option would be to apply scale only if vectorization succeeds which however
needs bit more work at tree-loop-distribution side and would need all code in
this patch with small change that fold_loop_internal_call will have to know how
to adjust if conditional stays. I decided to go for easier solution for now.
Bootstrapped/regtested x86_64-linux, committed.
gcc/ChangeLog:
* cfg.cc (scale_strictly_dominated_blocks): New function.
* cfg.h (scale_strictly_dominated_blocks): Declare.
* tree-cfg.cc (fold_loop_internal_call): Fixup CFG profile.
gcc/testsuite/ChangeLog:
* gcc.dg/vect/pr98308.c: Check that profile is consistent.
Diffstat (limited to 'gcc/tree-cfg.cc')
-rw-r--r-- | gcc/tree-cfg.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index c65af8c..c158454 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -7703,6 +7703,44 @@ fold_loop_internal_call (gimple *g, tree value) FOR_EACH_IMM_USE_ON_STMT (use_p, iter) SET_USE (use_p, value); update_stmt (use_stmt); + /* If we turn conditional to constant, scale profile counts. + We know that the conditional was created by loop distribution + and all basic blocks dominated by the taken edge are part of + the loop distributed. */ + if (gimple_code (use_stmt) == GIMPLE_COND) + { + edge true_edge, false_edge; + extract_true_false_edges_from_block (gimple_bb (use_stmt), + &true_edge, &false_edge); + edge taken_edge = NULL, other_edge = NULL; + if (gimple_cond_true_p (as_a <gcond *>(use_stmt))) + { + taken_edge = true_edge; + other_edge = false_edge; + } + else if (gimple_cond_false_p (as_a <gcond *>(use_stmt))) + { + taken_edge = false_edge; + other_edge = true_edge; + } + if (taken_edge + && !(taken_edge->probability == profile_probability::always ())) + { + profile_count old_count = taken_edge->count (); + profile_count new_count = taken_edge->src->count; + taken_edge->probability = profile_probability::always (); + other_edge->probability = profile_probability::never (); + /* If we have multiple predecessors, we can't use the dominance + test. This should not happen as the guarded code should + start with pre-header. */ + gcc_assert (single_pred_edge (taken_edge->dest)); + taken_edge->dest->count + = taken_edge->dest->count.apply_scale (new_count, + old_count); + scale_strictly_dominated_blocks (taken_edge->dest, + new_count, old_count); + } + } } } |