This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] ISel (and (shift X, C1), C2)) to shift pair in more cases
ClosedPublic

Authored by craig.topper on Mar 29 2022, 8:07 PM.

Details

Summary

Previously, these isel optimizations were disabled if the AND could
be selected as a ANDI instruction. This patch disables the optimizations
only if the immediate is valid for C.ANDI. If we can't use C.ANDI,
we might be able to compress the shift instructions instead.

I'm not checking the C extension since we have relatively poor test
coverage of the C extension. Without C extension the code size
should be equal. My only concern would be if the shift+andi had
better latency/throughput on a particular CPU.

I did have to add a peephole to match SRLIW if the input is zexti32
to prevent a regression in rv64zbp.ll.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 29 2022, 8:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 8:07 PM
craig.topper requested review of this revision.Mar 29 2022, 8:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 8:07 PM
luismarques accepted this revision.Mar 30 2022, 10:26 AM

LGTM.

I'm not checking the C extension since we have relatively poor test coverage of the C extension.

Note that in a TODO?

My only concern would be if the shift+andi had better latency/throughput on a particular CPU.

If someone can list CPUs where that's true please chime in. The only one I'm aware of is (depending on configuration) the PicoRV32, so this seems like a good tradeoff.

This revision is now accepted and ready to land.Mar 30 2022, 10:26 AM
This revision was landed with ongoing or failed builds.Mar 30 2022, 11:49 AM
This revision was automatically updated to reflect the committed changes.