8000 Array slice optimizations. by psivaraj · Pull Request #2539 · google/xls · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Array slice optimizations. #2539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

psivaraj
Copy link
@psivaraj psivaraj commented Jul 5, 2025

Addresses #453.

Extends ArraySimplificationPass to add array_slice optimizations, including:

Nested slice flattening:

array_slice(array_slice(A, start1, width1), start2, width2) 
    → array_slice(A, start1 + start2, width2)

Identity optimization:

array_slice(array, start=0, width=full_size) 
    → array (works with any array-typed node)

Constant start optimization:

array_slice(array(a,b,c,d), start=1, width=2) 
    → array(b,c) (extracts operands directly)

Select transformation to reduce mux width:

array_slice(select(p, [A0, A1]), start, width) 
    → select(p, [array_slice(A0, start, width), array_slice(A1, start, width)])

Added tests to cover all cases, and tried to consolidate shared logic with array_index optimizations.

I've also tried to preserve XLS array clamping behavior (out-of-bounds access returns the last element) throughout these optimizations, but would appreciate feedback on whether this is implemented correctly.


aside: It might very well be worth exploring the idea in #453 where we just convert array slices into array index operations, but I'm leaving that for the future. This should at least be a steady improvement.

Copy link
google-cla bot commented Jul 5, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@psivaraj psivaraj force-pushed the psivaraj/06-29-25-array-simpl branch 2 times, most recently from 8382b67 to 0374402 Compare July 6, 2025 20:51
- Flatten sequential array slices.
- Reduce mux width optimization.
- Optimize known slice widths
@psivaraj psivaraj force-pushed the psivaraj/06-29-25-array-simpl branch from 0374402 to c801ed6 Compare July 6, 2025 20:53 5D8C
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.

1 participant
0