[PATCH] D89047: [AVR] Optimize logic left/right shift

Ben Shi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 31 22:54:55 PDT 2020


benshi001 added a comment.

> Also, while this is an improvement I wonder whether there is a more systematic way to do this? This optimizes a very specific code pattern but it doesn't seem easy to extend it to other shifts and rotates, such as `((char)x) << 3` for example. The thing I have in mind works like this:

The optimization for shifts are a bit complex, and I would like to do it in smaller sperated patches. This way make that easy to review.

> - 8 bit shifts are all implemented with similar code that uses shifts, `swap`s, and `and`s etc to get the correct shift amount

It is hard for 8-bit shift with shiftAmount = 3.

> - 16 bit shifts can be built on top of that, either shifting two bytes individually and ORing the results together, or for larger (>= 8 bit) shifts swap the bytes and use an all-zero or all-ones byte for the other.

In current patch, I would like to only optimize 8-bit shifts and leave 16-bit shifts in other patches.

> Or perhaps there are better ways to do this.
>
> If you play around with godbolt.org (https://godbolt.org/z/foW7qc) you can see that it manages to produce very short code for nearly all shifts, apparently falling back to loops for hard cases. It even changes its strategy to inlining the entire shift (no loop) when using `-O2`.

For 8-bit shifts, my patch performs the same as avr-gcc, except shiftAmount = 7. I will improve it soon.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89047/new/

https://reviews.llvm.org/D89047



More information about the llvm-commits mailing list