Skip to content

Fix VM-to-EmitC [1/2]#24554

Open
severin-blip wants to merge 1 commit into
iree-org:mainfrom
severin-blip:pr-alginment-err-fix
Open

Fix VM-to-EmitC [1/2]#24554
severin-blip wants to merge 1 commit into
iree-org:mainfrom
severin-blip:pr-alginment-err-fix

Conversation

@severin-blip

Copy link
Copy Markdown

Summary

Fix VM-to-EmitC static import shim packing for iree_vm_ref_t.

Generated VM-C import shims were using a hard-coded 8-byte alignment for VM ref
arguments. That is incorrect on RV32, where iree_vm_ref_t is two 32-bit words
but only has 4-byte alignment.

Fix

Use the target C ABI alignment for iree_vm_ref_t instead of assuming 8-byte
alignment.

Conceptually, generated code changes from:

iree_host_align(offset, 8)

to:

iree_host_align(offset, iree_alignof(iree_vm_ref_t))

for VM ref packing/unpacking.

Test

Added a regression test under tests/riscv32_static_link.

The test compiles a minimal tensor add program to VM-C for
riscv32-unknown-elf and FileChecks the generated iICrD import shim. It
verifies that the shim uses 4-byte alignment for the iree_vm_ref_t variadic ref slot and for the
actual iree_vm_ref_retain packing path.

@severin-blip severin-blip requested a review from benvanik as a code owner June 1, 2026 07:07
@severin-blip severin-blip changed the title Fix VM-to-EmitC import shim ref alignment Fix VM-to-EmitC import shim ref alignment [1/2] Jun 1, 2026
@severin-blip severin-blip changed the title Fix VM-to-EmitC import shim ref alignment [1/2] Fix VM-to-EmitC [1/2] Jun 1, 2026
@devtbi

devtbi commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Hi @severin-blip, thanks for you contribution :) Please check out the contribution guidelines: https://iree.dev/developers/general/contributing/ . You need to sign your commit.

@devtbi devtbi left a comment

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.

Please check out the contribution guidelines: https://iree.dev/developers/general/contributing/ . You need to sign your commit.

@severin-blip severin-blip force-pushed the pr-alginment-err-fix branch from a922d9b to 9018d2c Compare June 2, 2026 13:29
@AGindinson AGindinson requested a review from devtbi June 2, 2026 14:15
@severin-blip severin-blip force-pushed the pr-alginment-err-fix branch from 9018d2c to 6812c2c Compare June 2, 2026 17:53
Use the target data layout when computing VM ABI buffer alignment in
generated EmitC import shims instead of hard-coding refs to 8-byte
alignment.

On 32-bit targets, iree_vm_ref_t can have 4-byte alignment, so the old
packing logic over-aligned ref fields and produced argument buffers whose
offsets did not match the VM runtime ABI layout. This caused imports with
variadic refs, such as iICrD, to read the ref object/type from the wrong
offsets.

Apply the target-aware alignment consistently when computing argument and
result buffer sizes, packing arguments, releasing packed refs, and
unpacking results.

Signed-off-by: Severin Bochem <severin@Severins-MacBook-Pro.local>
Signed-off-by: Severin Bochem <severin@mosaic-soc.com>
@severin-blip severin-blip force-pushed the pr-alginment-err-fix branch from 6812c2c to 3458e0a Compare June 2, 2026 18:00
@devtbi

devtbi commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@severin-blip looks good in general, once the CI is passing I'll do a full review :)

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.

2 participants