[X86] Missed Optimization: Vector 8-bit `rotl(x, 1)` should be lowered as `(x + x) - (x < 0)`
Due to a lack of support, most 8-bit shifts are implemented using a 16-bit shift + AND:
rotl1_src:
movdqa xmm1, xmm0
paddb xmm1, xmm0
psrlw xmm0, 7
pand xmm0, xmmword ptr [rip + .LCPI2_0]
por xmm0, xmm1
ret
The OR and right shift can be replaced with a subtraction by a less-than-zero mask, which acts like a conditional disjoint add by 1. This shortens the dependency chain and avoids the shift, which has worse throughput on some architectures.
rotl1_tgt:
pxor xmm1, xmm1
pcmpgtb xmm1, xmm0
paddb xmm0, xmm0
psubb xmm0, xmm1
ret
https://godbolt.org/z/199KoWhs8
hi i would like to take this issue
@llvm/issue-subscribers-backend-x86
Author: Walter (WalterKruger)
rotl1_src:
movdqa xmm1, xmm0
paddb xmm1, xmm0
psrlw xmm0, 7
pand xmm0, xmmword ptr [rip + .LCPI2_0]
por xmm0, xmm1
ret
The OR and right shift can be replaced with a subtraction by a less-than-zero mask, which acts like a conditional disjoint add by 1. This shortens the dependency chain and avoids the shift, which has worse throughput on some architectures.
rotl1_tgt:
pxor xmm1, xmm1
pcmpgtb xmm1, xmm0
paddb xmm0, xmm0
psubb xmm0, xmm1
ret
https://godbolt.org/z/199KoWhs8
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
- Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally. Be aware that LLVM's AI policy forbids the use of AI tools to fix good first issues since it squanders a learning opportunity. Using LLMs to search and learn is permitted, since the goal is learning.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: Walter (WalterKruger)
rotl1_src:
movdqa xmm1, xmm0
paddb xmm1, xmm0
psrlw xmm0, 7
pand xmm0, xmmword ptr [rip + .LCPI2_0]
por xmm0, xmm1
ret
The OR and right shift can be replaced with a subtraction by a less-than-zero mask, which acts like a conditional disjoint add by 1. This shortens the dependency chain and avoids the shift, which has worse throughput on some architectures.
rotl1_tgt:
pxor xmm1, xmm1
pcmpgtb xmm1, xmm0
paddb xmm0, xmm0
psubb xmm0, xmm1
ret
https://godbolt.org/z/199KoWhs8
Easy enough to implement in LowerRotate
@Ippo47 please begin by creating a alive2 link to demonstrate you understand the task
Hi, if no one is working on this I would like to contribute
Alive2 link: https://alive2.llvm.org/ce/z/teP3my
@Ippo47 is still working on this - please give them time to respond, and maybe find another ticket that doesn't already have an assignee?
@RKSimon @WalterKruger sorry for late reply, here is my Alive2 link https://alive2.llvm.org/ce/z/FrSxNt
@lppo47 any luck? You might want to take a look at #198980 for reference
can i take this issue ??
@Ippo47 is still working on it!! @AnkitDubeycs25
@RKSimon Issue was inactive for over a month with no development, so I took it. Please review.