Adaptive QIR emission does not properly handle negative indexing - #3689
Merged
Conversation
This changes updates the `Index` instruction from RIR to generate a sequence of instructions that checks the sign on the index and includes a corresponding offset to ensure that negative indexing works as expected in the emitted QIR. This change also adds a new integration test that validates both the QIR output and the execution time behavior of negative indexing. Fixes #3688
Stefan J. Wernli (swernli)
requested review from
Andrew Casey (amcasey),
Bill Ticehurst (billti) and
Ian Davis (idavis)
as code owners
September 4, 2026 21:16
orpuente-MS
approved these changes
Sep 4, 2026
orpuente-MS
left a comment
Contributor
There was a problem hiding this comment.
The fix makes sense, and we verified it works with run_qir. Thanks!
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.
This changes updates the
Indexinstruction from RIR to generate a sequence of instructions that checks the sign on the index and includes a corresponding offset to ensure that negative indexing works as expected in the emitted QIR. This change also adds a new integration test that validates both the QIR output and the execution time behavior of negative indexing. Fixes #3688