-
Notifications
You must be signed in to change notification settings - Fork 863
Use deep effects in areConsecutiveInputsEqual #8808
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
Merged
+112
−15
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
| ;; RUN: wasm-opt --generate-global-effects --optimize-instructions -all -S -o - %s | filecheck %s | ||
| ;; RUN: foreach %s %t wasm-opt --generate-global-effects --optimize-instructions -all -S -o - \ | ||
| ;; RUN: | filecheck %s | ||
|
|
||
| (module | ||
| ;; CHECK: (type $struct (shared (struct (field (mut i32))))) | ||
|
|
@@ -91,3 +92,41 @@ | |
| ) | ||
| ) | ||
| ) | ||
|
|
||
| (module | ||
| ;; CHECK: (global $f (mut f32) (f32.const -3)) | ||
| (global $f (mut f32) (f32.const -3)) | ||
|
|
||
| ;; CHECK: (func $potent (type $0) (result f32) | ||
| ;; CHECK-NEXT: (global.set $f | ||
| ;; CHECK-NEXT: (f32.add | ||
| ;; CHECK-NEXT: (global.get $f) | ||
| ;; CHECK-NEXT: (f32.const 2) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (global.get $f) | ||
| ;; CHECK-NEXT: ) | ||
| (func $potent (result f32) | ||
| (global.set $f (f32.add (global.get $f) (f32.const 2))) | ||
| (global.get $f) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $function-effects-interfere (type $0) (result f32) | ||
| ;; CHECK-NEXT: (f32.abs | ||
| ;; CHECK-NEXT: (f32.mul | ||
| ;; CHECK-NEXT: (call $potent) | ||
| ;; CHECK-NEXT: (call $potent) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $function-effects-interfere (result f32) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some comments on why this shouldn't be optimized?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| ;; Even knowing the effects of the call, we should not be able to optimize | ||
| ;; here because the calls will return different values. | ||
| (f32.abs | ||
| (f32.mul | ||
| (call $potent) | ||
| (call $potent) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds a little confusing to me. What does "left-hand parent expression or side effects in the right-hand children" mean? I think what we want to ensure is LHS parent + LHS children should not affect RHS children, right?
Also even though technically LHS and RHS are the same here, it would be nice to comment that, because we just computed RHS effects above and are saying LHS effects here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's not the execution LHS children that causes the RHS to have a different value from the LHS, it's the execution of the RHS children (or possibly the LHS parent expression).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant by the LHS children were the parameters for the LHS function, and LHS parent was the LHS function execution itself. Did you mean that too?
Then, wasn't it the LHS children's execution (which increased the global's value) that causes RHS's parameters (childrens) to have different values? Maybe we are talking about the same thing with a slightly different terms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍
No, because the LHS children execute before the LHS function call, so their side effects are already visible in the final LHS value. It's those same child expressions executing on the RHS before the RHS function call that make the RHS value different from the LHS value.