Stream: git-cranelift

Topic: cranelift / Issue #526 Optimize bitreverse using rotate i...


view this post on Zulip GitHub (Feb 28 2020 at 23:24):

alexcrichton transferred Issue #526:

The bitreverse seqences in lib/codegen/meta-python/base/legalize.py all end with two shifts and a bitwise or that effectively swap the low half of the value and the high half:
https://github.com/CraneStation/cranelift/blob/master/lib/codegen/meta-python/base/legalize.py#L445
https://github.com/CraneStation/cranelift/blob/master/lib/codegen/meta-python/base/legalize.py#L475
and others for the other types

It would be better to replace these trailing sequences with rotl_imm.

That change is the first step, however the catch is that rotl_imm isn't implemented in isel yet so we'll need to implement that too. See the encodings for shifts and non-imm rotates as well as the encodings for imm shifts for some examples.

Of course, in the future Cranelift is expected to have a pattern-matching optimization which would automatically optimize shift+bor sequences into rotates, however it doesn't have one right now, and even when it does, it would make the code simpler to just use rotate, and it's more efficient to just use the instruction we want than to emit sequences of instructions that we know will end up getting replaced.


Last updated: Dec 23 2024 at 14:03 UTC