]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix merging of value predictors
authorJan Hubicka <jh@suse.cz>
Wed, 17 Jan 2024 14:19:32 +0000 (15:19 +0100)
committerJan Hubicka <jh@suse.cz>
Wed, 17 Jan 2024 14:19:32 +0000 (15:19 +0100)
commitb00be6f1576993369522c16dba992bec9adab9b2
tree4f99ebeae11fdd4d04b989476692a65ac773094b
parent9f8ba332e988fb582f6ca32465f6d65283f53b3a
Fix merging of value predictors

expr_expected_value is doing some guesswork when it is merging two or more
independent value predictions either in PHI node or in binary operation.
Since we do not know how the predictions interact with each other, we can
not really merge the values precisely.

The previous logic merged the prediciton and picked the later predictor
(since predict.def is sorted by reliability). This however leads to troubles
with __builtin_expect_with_probability since it is special cased as a predictor
with custom probabilities.  If this predictor is downgraded to something else,
we ICE since we have prediction given by predictor that is not expected
to have customprobability.

This patch fixies it by inventing new predictors PRED_COMBINED_VALUE_PREDICTIONS
and PRED_COMBINED_VALUE_PREDICTIONS_PHI which also allows custom values but
are considered less reliable then __builtin_expect_with_probability (they
are combined by ds theory rather then by first match).  This is less likely
going to lead to very stupid decisions if combining does not work as expected.

I also updated the code to be bit more careful about merging values and do not
downgrade the precision when unnecesary (as tested by new testcases).

Bootstrapped/regtested x86_64-linux, will commit it tomorrow if there are
no complains.

2024-01-17  Jan Hubicka  <jh@suse.cz>
    Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/110852

gcc/ChangeLog:

* predict.cc (expr_expected_value_1): Fix profile merging of PHI and
binary operations
(get_predictor_value): Handle PRED_COMBINED_VALUE_PREDICTIONS and
PRED_COMBINED_VALUE_PREDICTIONS_PHI
* predict.def (PRED_COMBINED_VALUE_PREDICTIONS): New predictor.
(PRED_COMBINED_VALUE_PREDICTIONS_PHI): New predictor.

gcc/testsuite/ChangeLog:

* gcc.dg/predict-18.c: Update template to expect combined value predictor.
* gcc.dg/predict-23.c: New test.
* gcc.dg/tree-ssa/predict-1.c: New test.
* gcc.dg/tree-ssa/predict-2.c: New test.
* gcc.dg/tree-ssa/predict-3.c: New test.
gcc/predict.cc
gcc/predict.def
gcc/testsuite/gcc.dg/predict-18.c
gcc/testsuite/gcc.dg/predict-23.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/predict-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/predict-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/predict-3.c [new file with mode: 0644]