> >>> +/* Implement TARGET_CASE_VALUES_THRESHOLD. A jump table needs a bounds
> >>> + check, a table lookup and an indirect jump. Prefer branches for small
> >>> + switches when optimizing for speed. */
> >>> +
> >>> +static unsigned int
> >>> +riscv_case_values_threshold (void)
> >>> +{
> >>> + return optimize_size ? default_case_values_threshold () : 11;
> >> Looking at what aarch64 does, it allows the tuning cpu to also
> >> override this at -O3 (still using 11 at -O2; 8 at -Os). I wonder if
> >> you think there might be a tmicro-arch that might benefit from a
> >> higher value?
> > If I understand correctly, you're asking whether it's worth letting
> > -mtune select a different jump-table threshold at -O3 for some RISC-V
> > cores. I think that could help. For example, on a core where indirect
> > jumps are expensive, conditional branches may be faster even for
> > switches with more cases.
> >
> > Of the thresholds I tried, 11 gave the best overall results across the
> > CPUs I tested. I haven't seen a clear regression at the suite level.
> > It's an empirical choice, and the best value may depend on the
> > microarchitecture, ISA extensions, and workload. I don't yet have
> > measurements that would justify a different threshold for a particular
> > core.
> >
> > I'd use 11 as the default in the RISC-V hook for now. We can add an
> > override if measurements show that a particular core benefits from a
> > different value. If you'd prefer to support per-core thresholds in this
> > patch, I'm happy to send a v2 with the threshold in the RISC-V tuning
> > data.
> I would fully expect optimal to vary across designs. So, yea, I think
> this belongs in the per-core tuning structure.
>
> I'd go ahead with 11 for the C9501 and K3. I suspect there's likely a
> better value for the K3, but 11 seems to be meaningfully better for the
> K3 than whatever the generic default value is, so let's use 11 for that
> design as well. Obviously the spacemit guys can do their own
> investigative work and adjust the value for their cores.
>
Thanks, that makes sense. I'll move the jump-table threshold into the
RISC-V per-core tuning structure and use 11 for both the C9501 and the
K3. I'll send v2 once I've finished testing.
> For the record, while this patch arrived after stage1 close, we
> explicitly allow cost model adjustments for the RISC-V port even after
> stage1 close.
>
> Jeff
By the way, since you mentioned RISC-V cost model changes after Stage 1,
I'd appreciate your advice on when to post some other patches.
While looking at the RISC-V code GCC generates for SPEC CPU2017 and
PyBench, I found a few ways to improve how GCC inlines memset, memcpy
and memcmp. I have about ten small optimization patches and a few fixes
for bugs I found along the way.
For example, in my SPEC CPU2017 tests with the memcmp series,
500.perlbench_r ran 0.4% to 0.5% faster and 520.omnetpp_r ran 1.5% to
2.0% faster. PyBench's CompareStrings and CompareUnicode both ran about
33% faster.
Unfortunately, I didn't have the optimization patches ready to post
before GCC 17 entered Stage 3. Would it make sense to post them for
review now and see whether any are suitable for GCC 17?
BR,
Jin