Skip to content

feat(legalizer): widen block arguments - #2008

Merged
naveen-seth merged 2 commits into
mainfrom
widen-block-args
Nov 7, 2026
Merged

naveen-seth merged 2 commits into
mainfrom
widen-block-args

Conversation

@naveen-seth

@naveen-seth naveen-seth commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Our gMIR dialect has MLIR block arguments instead of G_PHI. This PR implements the widening legalization of it.
By implementing widening legalization for block arguments, this saves one zext in every block, which strongly improves our
benchmarks which are dependent on small loops (about -7.5%).

Unlike in LLVM, s32 is not legal for RISC-V block arguments. LLVM makes it legal for the legalization of float values. Integers still end up in 64 bit registers.
(Unlike for us, this is not done during legalization, but by storing the narrow LLT in a wider integer, which leaves the upper bits undefined just as g_anyext does.)
llvm/llvm-project@ab0dc29

This follows #2005, #2006 and is the final part of a series to support widening legalization of block arguments.

Assisted by AI

Our gMIR dialect has MLIR block arguments instead of G_PHI. This PR implements
the widening legalization of it.
By implementing widening legalization for block arguments, this saves one `zext`
in every block, which strongly improves our loop-heavy benchmarks (about -7.5%).

Unlike in LLVM, `s32` is not legal for RISC-V block arguments.
LLVM makes it legal for the legalization of float values. Integers still end up
in 64 bit registers.
(Unlike for us, this is not done during legalization, but by storing the narrow
LLT in a wider integer, which leaves the upper bits undefined just as `g_anyext`
does.)
llvm/llvm-project@ab0dc29

This follows #2005, #2006 and is the final part of a series to support widening
legalization of block arguments.

Assisted by AI

@regehr regehr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this LGTM!

@luisacicolini

Copy link
Copy Markdown
Contributor

let's clarify the comment @regehr asked about and then merge

@naveen-seth
naveen-seth enabled auto-merge November 7, 2026 17:09
@naveen-seth
naveen-seth added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 6c4c5c5 Nov 7, 2026
4 of 5 checks passed
@naveen-seth
naveen-seth deleted the widen-block-args branch November 7, 2026 17:16
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