Skip to content

Conversation

@fzi-hielscher
Copy link
Contributor

Should fix #9171.

Currently, the LLVM lowering of hw.array_get will attempt to reuse pointers to array values to avoid rematerializing the array on the stack. This is only legal as long as we can ensure the underlying buffer remains unchanged. It works within the confines of the HWToLLVM lowering, which always allocates a new buffer when modifying an array (see #8774). However, operations of other dialects (e.g., arc.state_write) might still write to the pointed-to buffer between the load and the array_get, causing it to return an incorrect value.

Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

LGTM

@fzi-hielscher fzi-hielscher merged commit 90757b5 into llvm:main Nov 2, 2025
7 checks passed
@fzi-hielscher fzi-hielscher deleted the arc-raw-bug branch November 2, 2025 21:19
TaoBi22 pushed a commit to TaoBi22/circt that referenced this pull request Nov 5, 2025
…m#9172)

Currently, the LLVM lowering of `hw.array_get` will attempt to reuse pointers to array values to avoid rematerializing the array on the stack. This is only legal as long as we can ensure the underlying buffer remains unchanged. It works within the confines of the HWToLLVM lowering, which always allocates a new buffer when modifying an array. However, operations of other dialects (e.g., `arc.state_write`) might still write to the pointed-to buffer between the `load` and the `array_get`, causing it to return an incorrect value.
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.

[Arc] State read-after-write bug.

2 participants