summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/fuzz_opt.py4
-rw-r--r--src/passes/SSAify.cpp13
-rw-r--r--test/passes/ssa.txt8
-rw-r--r--test/passes/ssa_fuzz-exec.txt34
4 files changed, 32 insertions, 27 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 3330000c9..595ee933e 100644
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -127,6 +127,10 @@ def test_one(infile, opts):
compare(before[i], after[i], 'comparing between builds at ' + str(i))
# fuzz binaryen interpreter itself. separate invocation so result is easily fuzzable
run(['bin/wasm-opt', 'a.wasm', '--fuzz-exec', '--fuzz-binary'] + opts)
+ # check for determinism
+ run(['bin/wasm-opt', 'a.wasm', '-o', 'b.wasm'] + opts)
+ run(['bin/wasm-opt', 'a.wasm', '-o', 'c.wasm'] + opts)
+ assert open('b.wasm').read() == open('c.wasm').read()
return bytes
diff --git a/src/passes/SSAify.cpp b/src/passes/SSAify.cpp
index 35432d9eb..1e6668638 100644
--- a/src/passes/SSAify.cpp
+++ b/src/passes/SSAify.cpp
@@ -34,6 +34,7 @@
#include "pass.h"
#include "wasm-builder.h"
#include "support/permutations.h"
+#include "ir/find_all.h"
#include "ir/literal-utils.h"
#include "ir/local-graph.h"
@@ -59,19 +60,17 @@ struct SSAify : public Pass {
func = func_;
LocalGraph graph(func);
// create new local indexes, one for each set
- createNewIndexes(graph);
+ createNewIndexes();
// we now know the sets for each get, and can compute get indexes and handle phis
computeGetsAndPhis(graph);
// add prepends to function
addPrepends();
}
- void createNewIndexes(LocalGraph& graph) {
- for (auto& pair : graph.locations) {
- auto* curr = pair.first;
- if (auto* set = curr->dynCast<SetLocal>()) {
- set->index = addLocal(func->getLocalType(set->index));
- }
+ void createNewIndexes() {
+ FindAll<SetLocal> sets(func->body);
+ for (auto* set : sets.list) {
+ set->index = addLocal(func->getLocalType(set->index));
}
}
diff --git a/test/passes/ssa.txt b/test/passes/ssa.txt
index e6883c0f8..102ad1288 100644
--- a/test/passes/ssa.txt
+++ b/test/passes/ssa.txt
@@ -746,9 +746,9 @@
(local $6 i32)
(local $7 i32)
(local $8 i32)
- (set_local $2
+ (set_local $3
(tee_local $8
- (tee_local $3
+ (tee_local $2
(tee_local $7
(i32.const 0)
)
@@ -783,9 +783,9 @@
)
(br_if $label$1
(i32.eqz
- (tee_local $5
+ (tee_local $6
(tee_local $8
- (tee_local $6
+ (tee_local $5
(tee_local $7
(get_local $8)
)
diff --git a/test/passes/ssa_fuzz-exec.txt b/test/passes/ssa_fuzz-exec.txt
index 7c9c26350..23f1d2600 100644
--- a/test/passes/ssa_fuzz-exec.txt
+++ b/test/passes/ssa_fuzz-exec.txt
@@ -16,9 +16,11 @@
(local $6 i32)
(local $7 i32)
(local $8 i32)
- (local $9 f64)
+ (local $9 i32)
(local $10 i32)
- (local $11 i32)
+ (local $11 f64)
+ (local $12 i32)
+ (local $13 i32)
(block $label$1 (result i32)
(if (result i32)
(i32.const 0)
@@ -27,13 +29,13 @@
(loop $label$5
(block $label$6
(block $label$7
- (set_local $4
+ (set_local $10
(if (result i32)
- (get_local $10)
+ (get_local $12)
(select
(loop $label$9 (result i32)
(if (result i32)
- (tee_local $5
+ (tee_local $4
(i32.const 16384)
)
(i32.const 1)
@@ -42,8 +44,8 @@
)
(br_if $label$4
(i32.const 0)
- (tee_local $var$1
- (tee_local $var$2
+ (tee_local $6
+ (tee_local $5
(block $label$12 (result i32)
(br_if $label$5
(br $label$6)
@@ -60,13 +62,13 @@
(if
(i32.const 0)
(return
- (get_local $11)
+ (get_local $13)
)
)
(if
- (tee_local $6
+ (tee_local $8
(tee_local $7
- (tee_local $11
+ (tee_local $13
(i32.const 0)
)
)
@@ -79,9 +81,9 @@
)
(br_if $label$15
(i32.eqz
- (tee_local $8
- (tee_local $11
- (tee_local $10
+ (tee_local $9
+ (tee_local $13
+ (tee_local $12
(i32.const 129)
)
)
@@ -96,10 +98,10 @@
)
(br_if $label$6
(if (result i32)
- (get_local $6)
+ (get_local $8)
(unreachable)
(block $label$25 (result i32)
- (set_local $9
+ (set_local $11
(block $label$26 (result f64)
(drop
(br_if $label$4
@@ -119,7 +121,7 @@
)
)
)
- (get_local $5)
+ (get_local $4)
)
)
)