Fix Verilog codegen for narrow array update indices - #4718
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_959354191
branch
from
August 10, 2026 14:12
8cbac68 to
2a76599
Compare
When codegen for Op::kArrayUpdate, target indexes were compared directly
against the 32-bit loop counter (index_expr == induction_var).
When index_expr was narrower than 32 bits, Verilog's context-determined
width rules expanded index_expr to 32 bits before applying the operation
creating the index. For example, if the index_expr is ~1. The 1 is expanded
to 32 bits first and then do ~ evaluated as 32'hFFFFFFFF (4294967295)
instead of 1'b1 zero-extended to 32'd1, causing the index comparison to
fail for all elements and reducing the array update to a no-op in generated
Verilog.
This change explicitly zero-extends narrow index expressions to 32 bits via
concatenation ({ (32 - width)'b0, index_expr }), creating a self-determined
context so unary operations evaluate at their native width before
comparison.
PiperOrigin-RevId: 962249938
copybara-service
Bot
force-pushed
the
test_959354191
branch
from
August 10, 2026 18:01
2a76599 to
9375c2b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Verilog codegen for narrow array update indices
When codegen for Op::kArrayUpdate, target indexes were compared directly
against the 32-bit loop counter (index_expr == induction_var).
When index_expr was narrower than 32 bits, Verilog's context-determined
width rules expanded index_expr to 32 bits before applying the operation
creating the index. For example, if the index_expr is ~1. The 1 is expanded
to 32 bits first and then do ~ evaluated as 32'hFFFFFFFF (4294967295)
instead of 1'b1 zero-extended to 32'd1, causing the index comparison to
fail for all elements and reducing the array update to a no-op in generated
Verilog.
This change explicitly zero-extends narrow index expressions to 32 bits via
concatenation ({ (32 - width)'b0, index_expr }), creating a self-determined
context so unary operations evaluate at their native width before
comparison.