Skip to content

feat(RISCVCombines): add combines to speed-up ChaCha20 - #1344

Open
tobias-rothmann wants to merge 9 commits into
opencompl:mainfrom
tobias-rothmann:tr-zextw-xor-roriw-combine
Open

tobias-rothmann wants to merge 9 commits into
opencompl:mainfrom
tobias-rothmann:tr-zextw-xor-roriw-combine

Conversation

@tobias-rothmann

@tobias-rothmann tobias-rothmann commented Sep 2, 2026

Copy link
Copy Markdown

Adds verified RISC-V combines:

  • roriw (xor (zextw x) (zextw y)), immroriw (xor x y), imm, removing redundant extensions in the ChaCha20 idiom while preserving shared full-width XOR uses.
  • zextw (zextb x)zextb x, including fixed-register retargeting.

Includes correctness proofs and regression tests for matching, negative, shared-use, and fixed-register cases.

@tobias-rothmann tobias-rothmann changed the title feat: add combine to speed-up ChaCha20 feat: add xor combine to speed-up ChaCha20 Sep 2, 2026
@tobias-rothmann tobias-rothmann changed the title feat: add xor combine to speed-up ChaCha20 feat(RISCVCombines): add xor combine to speed-up ChaCha20 Sep 2, 2026
@tobias-rothmann
tobias-rothmann force-pushed the tr-zextw-xor-roriw-combine branch 2 times, most recently from c7f46ad to 897c18b Compare September 3, 2026 13:19
@tobias-rothmann tobias-rothmann changed the title feat(RISCVCombines): add xor combine to speed-up ChaCha20 feat(RISCVCombines): optimize zextw chains Sep 3, 2026
@tobias-rothmann
tobias-rothmann marked this pull request as ready for review September 3, 2026 13:20
@tobias-rothmann
tobias-rothmann force-pushed the tr-zextw-xor-roriw-combine branch from 897c18b to 1eb01e2 Compare September 3, 2026 13:24
@tobias-rothmann tobias-rothmann changed the title feat(RISCVCombines): optimize zextw chains feat(RISCVCombines): optimizations for ChaCha20 Sep 3, 2026
@tobias-rothmann tobias-rothmann changed the title feat(RISCVCombines): optimizations for ChaCha20 feat(RISCVCombines): add combines to speed-up ChaCha20 Sep 3, 2026
@tobias-rothmann
tobias-rothmann marked this pull request as draft September 3, 2026 13:34
@tobias-rothmann
tobias-rothmann force-pushed the tr-zextw-xor-roriw-combine branch 2 times, most recently from f2ee4fc to 9c361d5 Compare September 4, 2026 13:46
@tobias-rothmann
tobias-rothmann force-pushed the tr-zextw-xor-roriw-combine branch from 3155a69 to 55e829f Compare September 4, 2026 14:28
@tobias-rothmann
tobias-rothmann marked this pull request as ready for review September 4, 2026 14:31
@luisacicolini

luisacicolini commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

thanks a lot for the PR, the code looks good to me, I left a couple comments! I will ask a second look by @regehr and @naveen-seth - do you guys think these rewrites will interfere with the legalization work?

Comment thread Veir/Passes/RISCVCombines/Combine.lean Outdated
Comment thread Veir/Passes/RISCVCombines/Combine.lean Outdated
LLVM: `CastInst::isEliminableCastPair` folds a `ZExt` followed by a `ZExt`
to the first cast.
https://github.com/llvm/llvm-project/blob/c536b0aa030474672e293dccdb27b97c36c4e1af/llvm/lib/IR/Instructions.cpp#L2922-L2967 -/
private def zextw_zextb_pattern : Puddle.Pattern OpCode :=

@luisacicolini luisacicolini Sep 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this definition private? (same for all the defs in this file)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I don't think there's a coherent pattern, but it seems like you only want to expose the compiled version for some combines. I've removed the "private" tag from all definitions now.

@naveen-seth

naveen-seth commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Upstream seems to make these optimizations during the legalization step, but I'd prefer landing this and to then move/revert this later once we have gotten further on legalization.
Thanks for tagging me; I'll keep this in PR in mind!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants