On 6/12/25 2:02 AM, Richard Sandiford wrote:
I meant it should be opposite: the fold should require SHIFT_COUNT_TRUNCATED
(reject !SHIFT_COUNT_TRUNCATED).
SHIFT_COUNT_TRUNCATED guarantees that, for a 32-bit shift, A==32 acts
like A==0. With !SHIFT_COUNT_TRUNCATED, 1<<A might be zero instead.
I realise that doesn't help you though, since RISC-V is !SHIFT_COUNT_TRUNCATED
target.
Right. And to preemptively answer some questions that might pop out.
The RISC-V did define SHIFT_COUNT_TRUNCATED at one time. Jim turned it
off ages ago after stumbling into a combine issue and noting that we've
been somewhat discouraging its use for a while. I don't recall the
precise issue as it's been months since I chased this historical nugget.
So while the RV ISA specifies precisely what we want for
SHIFT_COUNT_TRUNCATED, I'd be hesitant to turn it back on.
So the next natural question is how to fix the missed optimization issue
given we need to gate the generic code on SHIFT_COUNT_TRUNCATED. I
think we go forward with the simplify-rtx.cc change, but also introduce
a risc-v pattern for this case.
Jaiwei, sorry for making more work for you. WRT the new pattern I think
one of the earlier messages had an insn that we want to match with a
define_insn.
Jeff