Skip to content

Restrain SROA to prevent memory corruption#3868

Open
atgeller wants to merge 2 commits intoNVIDIA:mainfrom
atgeller:issue_3806
Open

Restrain SROA to prevent memory corruption#3868
atgeller wants to merge 2 commits intoNVIDIA:mainfrom
atgeller:issue_3806

Conversation

@atgeller
Copy link
Collaborator

@atgeller atgeller commented Feb 5, 2026

Description

When an array is passed to llvm.memcpy, it is cast from a !cc.ptr<!cc.array<i8 x 2>> to a !cc.ptr<i8>. However, SROA, when checking if it can scaralize an allocation, does not look past the cast, leading it to improperly scalarize the array, meaning only the first element is properly set when it is passed to llvm.memcpy. This seems to be the cause of #3806.

This PR adds additional checks to ensure that the cast array is only used for loading and storing to prevent improper scalarization.

Signed-off-by: Adam Geller <adgeller@nvidiae.com>
@copy-pr-bot
Copy link

copy-pr-bot bot commented Feb 5, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@atgeller
Copy link
Collaborator Author

atgeller commented Feb 5, 2026

/ok to test eabc065

Command Bot: Processing...

Signed-off-by: Adam Geller <adgeller@nvidiae.com>
@atgeller
Copy link
Collaborator Author

atgeller commented Feb 5, 2026

/ok to test d833bb7

Command Bot: Processing...

Copy link
Collaborator

@khalatepradnya khalatepradnya left a comment

Choose a reason for hiding this comment

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

Thank you @atgeller !

github-actions bot pushed a commit that referenced this pull request Feb 5, 2026
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

}

// CHECK: First result: 0 0 1 0 1 0 1 0
// CHECK: Second result: 0 0 1 0 1 0 1 0 No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add Python test as well? See example here - https://github.com/NVIDIA/cuda-quantum/pull/3807/changes.

if (auto store = dyn_cast<cudaq::cc::StoreOp>(cast_user))
continue;
return failure();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that following are failing in CI -

Failed Tests (2):
  CUDAQ :: Transforms/basic-sroa.qke
  CUDAQ :: Transforms/sroa.qke

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.

[run] Incorrect results on emulated target

2 participants