llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

RISCV fold of vscale add on rvv is not optimal

Open kamleshbhalui opened this issue 2 months ago • 8 comments

The fold

(A + vscale(C1)) + vscale(C2) -> A + vscale(C1 + C2)

does not seem to beneficial for riscv when inner add has multiple uses, as it would introduce extra add.

unnecesary add can be optimized from here: https://godbolt.org/z/9xfWc5voc

kamleshbhalui avatar Sep 11 '26 11:09 kamleshbhalui

@llvm/issue-subscribers-backend-risc-v

Author: Kamlesh Kumar (kamleshbhalui)

The fold

(A + vscale(C1)) + vscale(C2) -> A + vscale(C1 + C2)

is not beneficial for riscv when inner add has multiple uses, as it would introduce extra add.

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:

  1. 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.
  2. 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.
  3. 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.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. 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: Kamlesh Kumar (kamleshbhalui)

The fold

(A + vscale(C1)) + vscale(C2) -> A + vscale(C1 + C2)

does not seem to beneficial for riscv when inner add has multiple uses, as it would introduce extra add.

unnecesary add can be optimized from here: https://godbolt.org/z/9xfWc5voc

I'd like to work on this issue!

FoolgryGamer avatar Sep 14 '26 08:09 FoolgryGamer

@FoolgryGamer can I know if you are still working on it ? If not, let me know.

anandkvinu avatar Sep 16 '26 18:09 anandkvinu

@FoolgryGamer can I know if you are still working on it ? If not, let me know.

I happened to have some experience in RISCV backend.

anandkvinu avatar Sep 17 '26 04:09 anandkvinu

I am still working on this issue.

FoolgryGamer avatar Sep 17 '26 06:09 FoolgryGamer

I submitted a PR related to pre-commit to add the relevant tests https://github.com/llvm/llvm-project/pull/224511.

For this performance-related issue, should I submit a pre-commit PR and a corresponding fix PR separately?

Thank you for your reply.

FoolgryGamer avatar Sep 18 '26 05:09 FoolgryGamer