Use array comprehension for large byte_extract lowering#8840
Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
Open
Use array comprehension for large byte_extract lowering#8840tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes lower_byte_extract_array_vector to avoid element-by-element expansion for large constant-sized arrays by switching to an array_comprehension_exprt representation once the array exceeds MAX_FLATTENED_ARRAY_SIZE, reducing expression blow-up and improving lowering performance.
Changes:
- Include
magic.hto accessMAX_FLATTENED_ARRAY_SIZE. - Route large constant-sized array byte-extract lowering through
array_comprehension_exprtinstead of generating N lowered sub-expressions. - Add comments documenting the O(N²) behavior and rationale for the comprehension-based lowering.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lower_byte_extract_array_vector expands byte_extract of an array type into an element-by-element array_exprt. For large arrays (e.g., char[100000] in a union), this creates N sub-expressions that are each recursively lowered and simplified, resulting in O(N^2) behavior. When the array size exceeds MAX_FLATTENED_ARRAY_SIZE (1000), use array_comprehension_exprt instead. This path already exists for arrays with non-constant size; now it is also used for large constant-size arrays. This reduces the lowering from O(N) expressions to O(1). Performance on union_large_array (char[100000] in a union): Before: >120s with --arrays-uf-always After: 2.3s with --arrays-uf-always Remove thorough-arrays-uf-always tag from union_large_array.desc since the test now completes in 2 seconds. Co-authored-by: Kiro
5952edd to
a31877d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8840 +/- ##
========================================
Coverage 80.00% 80.01%
========================================
Files 1700 1700
Lines 188252 188254 +2
Branches 73 73
========================================
+ Hits 150613 150629 +16
+ Misses 37639 37625 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
lower_byte_extract_array_vector expands byte_extract of an array type into an element-by-element array_exprt. For large arrays (e.g., char[100000] in a union), this creates N sub-expressions that are each recursively lowered and simplified, resulting in O(N^2) behavior.
When the array size exceeds MAX_FLATTENED_ARRAY_SIZE (1000), use array_comprehension_exprt instead. This path already exists for arrays with non-constant size; now it is also used for large constant-size arrays. This reduces the lowering from O(N) expressions to O(1).
Performance on union_large_array (char[100000] in a union):
Before: >120s with --arrays-uf-always
After: 2.3s with --arrays-uf-always
Co-authored-by: Kiro