Skip unnecessary SLOAD for empty value-type array copy in IR#16575
Closed
tavian-dev wants to merge 2 commits into
Closed
Skip unnecessary SLOAD for empty value-type array copy in IR#16575tavian-dev wants to merge 2 commits into
tavian-dev wants to merge 2 commits into
Conversation
When isoltest updates test expectations for ASTJSON tests, it calls printSource() to rewrite the .sol input file. The function was not outputting the failAfter directive that was parsed and stored in m_expectedFailAfter, causing the directive to be silently dropped. Fixes argotorg#14093
When copying a storage array of value types to another storage location, the generated Yul code unconditionally performs an SLOAD on the source data area before entering the copy loop. For empty arrays (length 0), this SLOAD is wasted since the loop body never executes. Add an early exit after resizeArray when length is zero, avoiding the unnecessary SLOAD as well as the keccak256 data slot computations. Fixes argotorg#16307.
|
Thank you for your contribution to the Solidity compiler! A team member will follow up shortly. If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother. If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix. |
Contributor
|
Closing this as the issuein question has not been triaged, and is thus not ready for development. |
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.
Summary
Fixes #16307.
When copying a storage array of value types to another storage slot, the IR pipeline's
copyValueArrayToStorageFunctionunconditionally performs ansloadon the source data area before entering the copy loop. For empty arrays (length 0), this SLOAD is wasted since the loop never executes.This adds an early exit after
resizeArray(dst, length)whenlengthis zero, avoiding:sloadon the source data areakeccak256data slot computations for both source and destinationfullSlotsdivision and loop overheadGenerated Yul before:
Generated Yul after:
Test plan
array/copying/array_copy_empty_storage_push.solexercising the exact pattern from the issue (array.push() = array.push())