This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 1/3] Come up with selftests for predict.c.
On Thu, 2017-06-08 at 14:30 +0200, Martin Liška wrote:
> On 06/06/2017 12:44 PM, David Malcolm wrote:
> > On Tue, 2017-06-06 at 10:55 +0200, marxin wrote:
> >
> > Some minor nits below.
> >
> > > gcc/ChangeLog:
> > >
> > > 2017-05-26 Martin Liska <mliska@suse.cz>
> > >
> > > * predict.c (struct branch_predictor): New struct.
> > > (test_prediction_value_range): New test.
> > > (predict_tests_c_tests): New function.
> > > * selftest-run-tests.c (selftest::run_tests): Run the function.
> > > * selftest.h: Declare new tests.
> > > ---
> > > gcc/predict.c | 39
> > > +++++++++++++++++++++++++++++++++++++++
> > > gcc/selftest-run-tests.c | 1 +
> > > gcc/selftest.h | 1 +
> > > 3 files changed, 41 insertions(+)
> > >
> > > diff --git a/gcc/predict.c b/gcc/predict.c
> > > index ac35fa41129..ea445e94e46 100644
> > > --- a/gcc/predict.c
> > > +++ b/gcc/predict.c
> > > @@ -57,6 +57,7 @@ along with GCC; see the file COPYING3. If not
> > > see
> > > #include "tree-scalar-evolution.h"
> > > #include "ipa-utils.h"
> > > #include "gimple-pretty-print.h"
> > > +#include "selftest.h"
> > >
> > > /* Enum with reasons why a predictor is ignored. */
> > >
> > > @@ -3803,3 +3804,41 @@ force_edge_cold (edge e, bool impossible)
> > > impossible ? "impossible" : "cold");
> > > }
> > > }
> > > +
> > > +#if CHECKING_P
> > > +
> > > +namespace selftest {
> > > +
> > > +/* Test that value range of predictor values defined in
> > > predict.def
> > > is
> > > + within range [51, 100]. */
> > > +
> > > +struct branch_predictor
> > > +{
> > > + const char *name;
> > > + unsigned probability;
> > > +};
> > > +
> > > +#define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) { NAME,
> > > HITRATE },
> > > +
> > > +static void
> > > +test_prediction_value_range ()
> > > +{
> > > + branch_predictor predictors[] = {
> > > +#include "predict.def"
> > > + {NULL, -1}
> > > + };
> > > +
> > > + for (unsigned i = 0; predictors[i].name != NULL; i++)
> > > + ASSERT_TRUE (100 * predictors[i].probability /
> > > REG_BR_PROB_BASE
> > > > 50);
> >
> > Minor nit: should there be a #undef DEF_PREDICTOR after the
> > #include?
>
> Hello.
>
> Yes, that should be undefined.
>
> >
> > Minor nits: the comment says it verifies that things are in the
> > range
> > 51, 100. Should it be >= 51 rather than > 50? Should there be a
> > test
> > that it's <= 100? (I'm not familiar with the predict code, I just
> > noticed this when reading the comment).
>
> Should be in range (50,100], fixed accordingly.
>
> >
> > > +}
> > > +
> > > +/* Run all of the selfests within this file. */
> > > +
> > > +void
> > > +predict_tests_c_tests ()
> > > +{
> >
> > Minor nit: to follow the pattern used in the other selftests, we've
> > been naming these "run all selftests within this file" functions
> > after
> > the filename. Given this is in predict.c, this should be
> > "predict_c_tests ()" to follow the pattern.
>
> I followed your naming scheme.
>
> Thanks for review,
> Martin
Thanks for fixing these things; looks much better.
Note that I'm not technically a "reviewer" or "maintainer" for this
part of the compiler, so I can't formally approve the patch (I was just
pointing out some things I noticed).
Dave