Skip to content

Cranelift: add _imm_s/_imm_u instruction builder helpers#13583

Open
aniasse wants to merge 1 commit into
bytecodealliance:mainfrom
aniasse:cranelift-imm-s-u-builders
Open

Cranelift: add _imm_s/_imm_u instruction builder helpers#13583
aniasse wants to merge 1 commit into
bytecodealliance:mainfrom
aniasse:cranelift-imm-s-u-builders

Conversation

@aniasse
Copy link
Copy Markdown

@aniasse aniasse commented Jun 6, 2026

Fixes #13529. Follow-up to the discussion in #13527.

Today the generated <inst>_imm builder picks sign- vs zero-extension from
a hardcoded list of opcodes in build_imm_const, which is easy to trip on.
This adds explicit <inst>_imm_s (sign-extend) and <inst>_imm_u
(zero-extend) variants instead, and build_imm_const now takes a plain
signed: bool. The extension only matters for i128; below that the masked
immediate is the same either way.

<inst>_imm stays for back-compat but is now #[deprecated] in favor of the
explicit ones. I migrated the ~100 in-tree callers over by their historical
signedness — that part is a no-op (nothing internal uses these on i128),
which is why the diff is big but boring.

Skipped the SImm128/UImm128 newtype idea for now since the _s/_u
names already carry the signedness — can do it as a follow-up if you want.

Tested with the cranelift-codegen/frontend suites and the filetests, plus a
new unit test for the i128 extension behavior.

Replaces the single `_imm` builder method, whose sign/zero-extension was
decided by a hardcoded list of "historical" opcodes, with explicit
`_imm_s` (sign-extend) and `_imm_u` (zero-extend) variants. The bare
`_imm` method stays for back-compat but is now deprecated.

Migrates internal callers to the explicit variants. Fixes bytecodealliance#13529.
@aniasse aniasse requested a review from a team as a code owner June 6, 2026 18:07
@aniasse aniasse requested review from cfallin and removed request for a team June 6, 2026 18:07
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:meta Everything related to the meta-language. labels Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add InstructionBuilder::foo_imm_{u,s} methods and signed/unsigned immediates to CLIF

1 participant