https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125167
Bug ID: 125167
Summary: More select improvements for RISC-V
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: law at gcc dot gnu.org
Target Milestone: ---
In pr124009 selects between 2^n and 0 were improved which had the side effect
of also improving selects between 2^n-1 and -1.
We can think of these selects as occuring in one or two stages. THe first
stage takes the output of an sCC style insn and creates a base select. So for
example 2^n and 0 is slli. 3/0, 5/0 and 9/0 are shNadd. 0xffffffff80000000/0
is slliw. There's probably more. At this stage we have a 2 insn sequence and
these will almost always be profitable.
The second stage takes that base select and expands it to cover related values.
So we could pair slli with addi to select between 2^n+C/C where C is a signed
12 bit immediate. We could pair slli with shadd to select {3,5,9}*2^n,0 and
so-on. We can even drag Zbs into the game by using that to flip on or off a
bit.
Again, the point is to identify additional base steps such as the initial
slli/shNadd/slliw, then pair those up with adjustments to derive other select
cases.
While I have outlined several cases we could cover, I haven't tried to
exhaustively cover either the base step or the refinement step. Nor have I
gone looking to see how often any of these cases occur in practice.