-
Notifications
You must be signed in to change notification settings - Fork 860
LICM: Migrate from invalidates to orderedBefore #8743
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
| ;; RUN: foreach %s %t wasm-opt -all --licm -S -o - | filecheck %s | ||
|
|
||
| (module | ||
| ;; CHECK: (type $struct (shared (struct (field (mut i32))))) | ||
| (type $struct (shared (struct (field (mut i32))))) | ||
|
|
||
| ;; CHECK: (memory $mem 1 1 shared) | ||
| (memory $mem 1 1 shared) | ||
|
|
||
| ;; Test 1: Allowed reordering (GC read moved before Wasm release store) | ||
| ;; CHECK: (func $allowed (type $1) (param $x (ref $struct)) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (struct.get $struct 0 | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (loop $loop | ||
| ;; CHECK-NEXT: (i32.atomic.store acqrel | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: (i32.const 42) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: (br $loop) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $allowed (param $x (ref $struct)) | ||
| (loop $loop | ||
| ;; X: release store (Wasm memory) | ||
| (i32.atomic.store acqrel (i32.const 0) (i32.const 42)) | ||
| ;; E: memory access (shared GC read) | ||
| (drop | ||
| (struct.get $struct 0 (local.get $x)) | ||
| ) | ||
|
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. In both of these tests, should we also test the the memory/GC instructions reordered? Here, with the struct.get before the i32 store?
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. We already have very thorough tests of all the interactions considered by |
||
| (br $loop) | ||
| ) | ||
| ) | ||
|
|
||
| ;; Test 2: Disallowed reordering (GC read moved before Wasm acquire load) | ||
| ;; CHECK: (func $disallowed (type $1) (param $x (ref $struct)) | ||
| ;; CHECK-NEXT: (loop $loop | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.atomic.load acqrel | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (struct.get $struct 0 | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (br $loop) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $disallowed (param $x (ref $struct)) | ||
| (loop $loop | ||
| ;; X: acquire load (Wasm memory) | ||
| (drop | ||
| (i32.atomic.load acqrel (i32.const 0)) | ||
| ) | ||
| ;; E: memory access (shared GC read) | ||
| (drop | ||
| (struct.get $struct 0 (local.get $x)) | ||
| ) | ||
| (br $loop) | ||
| ) | ||
| ) | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,13 @@ | |
|
|
||
| ;; CHECK: (type $0 (func (param i32))) | ||
|
|
||
| ;; CHECK: (type $1 (func)) | ||
| ;; CHECK: (type $1 (func (param i32) (result i32))) | ||
|
|
||
| ;; CHECK: (type $2 (func)) | ||
|
|
||
| ;; CHECK: (memory $0 10 20) | ||
|
|
||
| ;; CHECK: (func $unreachable-get (type $1) | ||
| ;; CHECK: (func $unreachable-get (type $2) | ||
| ;; CHECK-NEXT: (local $x i32) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (local.get $x) | ||
|
|
@@ -104,4 +106,80 @@ | |
| (br $loop) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $bug-inversion (type $1) (param $z i32) (result i32) | ||
| ;; CHECK-NEXT: (local $x i32) | ||
| ;; CHECK-NEXT: (local $y i32) | ||
| ;; CHECK-NEXT: (local.set $y | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.set $x | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (loop $loop | ||
| ;; CHECK-NEXT: (local.set $y | ||
| ;; CHECK-NEXT: (i32.const 2) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.set $x | ||
| ;; CHECK-NEXT: (i32.add | ||
| ;; CHECK-NEXT: (local.get $y) | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (br_if $loop | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: ) | ||
| (func $bug-inversion (param $z i32) (result i32) | ||
| (local $x i32) | ||
| (local $y i32) | ||
| (local.set $y (i32.const 0)) | ||
| (local.set $x (i32.const 0)) | ||
| (loop $loop | ||
| (local.set $y (i32.const 2)) | ||
| (local.set $x (i32.add (local.get $y) (i32.const 1))) | ||
| (br_if $loop (i32.const 0)) | ||
| ) | ||
| (local.get $x) | ||
| ) | ||
|
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. What is being tested by these? (and how does it relate to this PR?)
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. When I first tried to make simplifications based on your suggestion to clear the local effects outside the loop, I went overboard and produced something incorrect. But the test suite still passed. These are regression tests for that incorrect simplification. |
||
|
|
||
| ;; CHECK: (func $bug-cross-statement-dependency (type $1) (param $z i32) (result i32) | ||
| ;; CHECK-NEXT: (local $x i32) | ||
| ;; CHECK-NEXT: (local $y i32) | ||
| ;; CHECK-NEXT: (local.set $x | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.set $y | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (loop $loop | ||
| ;; CHECK-NEXT: (local.set $y | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.set $x | ||
| ;; CHECK-NEXT: (i32.add | ||
| ;; CHECK-NEXT: (local.get $z) | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (br_if $loop | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (local.get $y) | ||
| ;; CHECK-NEXT: ) | ||
| (func $bug-cross-statement-dependency (param $z i32) (result i32) | ||
| (local $x i32) | ||
| (local $y i32) | ||
| (local.set $x (i32.const 0)) | ||
| (local.set $y (i32.const 0)) | ||
| (loop $loop | ||
| (local.set $y (local.get $x)) | ||
| (local.set $x (i32.add (local.get $z) (i32.const 1))) | ||
| (br_if $loop (i32.const 0)) | ||
| ) | ||
| (local.get $y) | ||
| ) | ||
| ) | ||
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.
effectsSoFar.orderedBefore(effects)makes sense to me. But forloopEffects.orderedBefore(effects), as you said they execute before, during, and after - why is it enough to only check one?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.
(last question I promise!)
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.
Because we're only trying to move the execution of
curr(whose effects areeffects) before the loop, i.e. back past all the previous executions of the loop body. If we were trying to sinkcurrdown past the loop, we would have to check the other direction.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.
I see, thanks. Yes, that's the right way to look at this.