summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/Precompute.cpp54
-rw-r--r--src/tools/wasm-opt.cpp2
-rw-r--r--test/merge/basics.wast2
-rw-r--r--test/merge/basics.wast.combined8
-rw-r--r--test/merge/basics.wast.combined.finalized8
-rw-r--r--test/merge/basics.wast.combined.finalized.opt20
-rw-r--r--test/merge/basics.wast.combined.opt20
-rw-r--r--test/merge/basics.wast.toMerge2
-rw-r--r--test/merge/fusing.wast.combined.finalized.opt14
-rw-r--r--test/merge/fusing.wast.combined.opt14
-rw-r--r--test/merge/global-init.wast2
-rw-r--r--test/merge/global-init.wast.combined4
-rw-r--r--test/merge/global-init.wast.combined.finalized4
-rw-r--r--test/merge/global-init.wast.toMerge2
-rw-r--r--test/merge/noBases.wast.combined.finalized.opt20
-rw-r--r--test/merge/noBases.wast.combined.opt20
-rw-r--r--test/passes/precompute.txt23
-rw-r--r--test/passes/precompute.wast29
18 files changed, 140 insertions, 108 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
index 8d6111ab4..b902c4231 100644
--- a/src/passes/Precompute.cpp
+++ b/src/passes/Precompute.cpp
@@ -29,12 +29,14 @@
namespace wasm {
-static const Name NONSTANDALONE_FLOW("Binaryen|nonstandalone");
+static const Name NOTPRECOMPUTABLE_FLOW("Binaryen|notprecomputable");
typedef std::unordered_map<GetLocal*, Literal> GetValues;
-// Execute an expression by itself. Errors if we hit anything we need anything not in the expression itself standalone.
-class StandaloneExpressionRunner : public ExpressionRunner<StandaloneExpressionRunner> {
+// Precomputes an expression. Errors if we hit anything that can't be precomputed.
+class PrecomputingExpressionRunner : public ExpressionRunner<PrecomputingExpressionRunner> {
+ Module* module;
+
// map gets to constant values, if they are known to be constant
GetValues& getValues;
@@ -46,24 +48,24 @@ class StandaloneExpressionRunner : public ExpressionRunner<StandaloneExpressionR
bool replaceExpression;
public:
- StandaloneExpressionRunner(GetValues& getValues, bool replaceExpression) : getValues(getValues), replaceExpression(replaceExpression) {}
+ PrecomputingExpressionRunner(Module* module, GetValues& getValues, bool replaceExpression) : module(module), getValues(getValues), replaceExpression(replaceExpression) {}
struct NonstandaloneException {}; // TODO: use a flow with a special name, as this is likely very slow
Flow visitLoop(Loop* curr) {
// loops might be infinite, so must be careful
// but we can't tell if non-infinite, since we don't have state, so loops are just impossible to optimize for now
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitCall(Call* curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitCallImport(CallImport* curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitCallIndirect(CallIndirect* curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitGetLocal(GetLocal *curr) {
auto iter = getValues.find(curr);
@@ -73,7 +75,7 @@ public:
return Flow(value);
}
}
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitSetLocal(SetLocal *curr) {
// If we don't need to replace the whole expression, see if there
@@ -84,34 +86,40 @@ public:
return visit(curr->value);
}
}
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitGetGlobal(GetGlobal *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ auto* global = module->getGlobalOrNull(curr->name);
+ if (global) {
+ if (!global->mutable_) {
+ return visit(global->init);
+ }
+ }
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitSetGlobal(SetGlobal *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitLoad(Load *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitStore(Store *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitAtomicRMW(AtomicRMW *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitAtomicCmpxchg(AtomicCmpxchg *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitAtomicWait(AtomicWait *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitAtomicWake(AtomicWake *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
Flow visitHost(Host *curr) {
- return Flow(NONSTANDALONE_FLOW);
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
void trap(const char* why) override {
@@ -156,7 +164,7 @@ struct Precompute : public WalkerPass<PostWalker<Precompute, UnifiedExpressionVi
// try to evaluate this into a const
Flow flow = precomputeExpression(curr);
if (flow.breaking()) {
- if (flow.breakTo == NONSTANDALONE_FLOW) return;
+ if (flow.breakTo == NOTPRECOMPUTABLE_FLOW) return;
if (flow.breakTo == RETURN_FLOW) {
// this expression causes a return. if it's already a return, reuse the node
if (auto* ret = curr->dynCast<Return>()) {
@@ -223,9 +231,9 @@ private:
// (that we can replace the expression with if replaceExpression is set).
Flow precomputeExpression(Expression* curr, bool replaceExpression = true) {
try {
- return StandaloneExpressionRunner(getValues, replaceExpression).visit(curr);
- } catch (StandaloneExpressionRunner::NonstandaloneException&) {
- return Flow(NONSTANDALONE_FLOW);
+ return PrecomputingExpressionRunner(getModule(), getValues, replaceExpression).visit(curr);
+ } catch (PrecomputingExpressionRunner::NonstandaloneException&) {
+ return Flow(NOTPRECOMPUTABLE_FLOW);
}
}
diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp
index f78278bcf..278a9879d 100644
--- a/src/tools/wasm-opt.cpp
+++ b/src/tools/wasm-opt.cpp
@@ -149,7 +149,7 @@ int main(int argc, const char* argv[]) {
p.dump(std::cerr);
std::cerr << '\n';
Fatal() << "error in parsing wasm source map";
- } catch (std::bad_alloc& b) {
+ } catch (std::bad_alloc&) {
Fatal() << "error in building module, std::bad_alloc (possibly invalid request for silly amounts of memory)";
}
diff --git a/test/merge/basics.wast b/test/merge/basics.wast
index b5fc97f7e..920c1e977 100644
--- a/test/merge/basics.wast
+++ b/test/merge/basics.wast
@@ -10,6 +10,7 @@
(global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
(global $global-a i32 (i32.const 1))
+ (global $global-a-mut (mut i32) (i32.const 1))
(elem (get_global $tableBase) $only-a $willCollide $some-func $some-collide $only-a)
(export "exp-a" (func $only-a))
(export "exp-collide" (func $only-a))
@@ -26,6 +27,7 @@
)
(drop (get_global $global-collide))
(drop (get_global $global-a))
+ (drop (get_global $global-a-mut))
(drop (get_global $memoryBase))
(drop (get_global $tableBase))
(set_global $global-collide-mut (i32.const 1234))
diff --git a/test/merge/basics.wast.combined b/test/merge/basics.wast.combined
index e90b4f594..a0d1ea7db 100644
--- a/test/merge/basics.wast.combined
+++ b/test/merge/basics.wast.combined
@@ -16,9 +16,11 @@
(global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
(global $global-a i32 (i32.const 1))
+ (global $global-a-mut (mut i32) (i32.const 1))
(global $global-collide$0 i32 (i32.const 0))
(global $global-collide-mut$0 (mut i32) (i32.const 0))
(global $global-b i32 (i32.const 1))
+ (global $global-b-mut (mut i32) (i32.const 1))
(elem (get_global $tableBase) $only-a $willCollide $some-func $some-collide $only-a $only-a $only-b $willCollide$0 $some-func-b $some-collide$0)
(data (get_global $memoryBase) "hello, A!\n\00\00\00\00\00\00hello, B!\n\00\00\00\00\00\00")
(export "exp-a" (func $only-a))
@@ -45,6 +47,9 @@
(get_global $global-a)
)
(drop
+ (get_global $global-a-mut)
+ )
+ (drop
(get_global $memoryBase)
)
(drop
@@ -79,6 +84,9 @@
(get_global $global-b)
)
(drop
+ (get_global $global-b-mut)
+ )
+ (drop
(i32.add
(get_global $memoryBase$0)
(i32.const 16)
diff --git a/test/merge/basics.wast.combined.finalized b/test/merge/basics.wast.combined.finalized
index e25d70a6e..f68e8c808 100644
--- a/test/merge/basics.wast.combined.finalized
+++ b/test/merge/basics.wast.combined.finalized
@@ -16,9 +16,11 @@
(global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
(global $global-a i32 (i32.const 1))
+ (global $global-a-mut (mut i32) (i32.const 1))
(global $global-collide$0 i32 (i32.const 0))
(global $global-collide-mut$0 (mut i32) (i32.const 0))
(global $global-b i32 (i32.const 1))
+ (global $global-b-mut (mut i32) (i32.const 1))
(elem (i32.const 8) $only-a $willCollide $some-func $some-collide $only-a $only-a $only-b $willCollide$0 $some-func-b $some-collide$0)
(data (i32.const 1024) "hello, A!\n\00\00\00\00\00\00hello, B!\n\00\00\00\00\00\00")
(export "exp-a" (func $only-a))
@@ -45,6 +47,9 @@
(get_global $global-a)
)
(drop
+ (get_global $global-a-mut)
+ )
+ (drop
(i32.const 1024)
)
(drop
@@ -79,6 +84,9 @@
(get_global $global-b)
)
(drop
+ (get_global $global-b-mut)
+ )
+ (drop
(i32.add
(i32.const 1024)
(i32.const 16)
diff --git a/test/merge/basics.wast.combined.finalized.opt b/test/merge/basics.wast.combined.finalized.opt
index d023ca183..a117042bb 100644
--- a/test/merge/basics.wast.combined.finalized.opt
+++ b/test/merge/basics.wast.combined.finalized.opt
@@ -7,12 +7,10 @@
(import "env" "some-collide" (func $some-collide))
(import "env" "some-func-b" (func $some-func-b))
(import "env" "some-collide" (func $some-collide$0))
- (global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
- (global $global-a i32 (i32.const 1))
- (global $global-collide$0 i32 (i32.const 0))
+ (global $global-a-mut (mut i32) (i32.const 1))
(global $global-collide-mut$0 (mut i32) (i32.const 0))
- (global $global-b i32 (i32.const 1))
+ (global $global-b-mut (mut i32) (i32.const 1))
(elem (i32.const 8) $only-a $willCollide $some-func $some-collide $only-a $only-a $only-b $willCollide$0 $some-func-b $some-collide$0)
(data (i32.const 1024) "hello, A!\n\00\00\00\00\00\00hello, B!\n")
(export "exp-a" (func $only-a))
@@ -30,11 +28,10 @@
(i32.const 456)
(i32.const 789)
)
+ (nop)
+ (nop)
(drop
- (get_global $global-collide)
- )
- (drop
- (get_global $global-a)
+ (get_global $global-a-mut)
)
(nop)
(nop)
@@ -56,11 +53,10 @@
(i32.const 34)
(i32.const 56)
)
+ (nop)
+ (nop)
(drop
- (get_global $global-collide$0)
- )
- (drop
- (get_global $global-b)
+ (get_global $global-b-mut)
)
(nop)
(nop)
diff --git a/test/merge/basics.wast.combined.opt b/test/merge/basics.wast.combined.opt
index beddc7e0b..d940ad38e 100644
--- a/test/merge/basics.wast.combined.opt
+++ b/test/merge/basics.wast.combined.opt
@@ -11,12 +11,10 @@
(import "env" "tableBase" (global $tableBase$0 i32))
(import "env" "some-func-b" (func $some-func-b))
(import "env" "some-collide" (func $some-collide$0))
- (global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
- (global $global-a i32 (i32.const 1))
- (global $global-collide$0 i32 (i32.const 0))
+ (global $global-a-mut (mut i32) (i32.const 1))
(global $global-collide-mut$0 (mut i32) (i32.const 0))
- (global $global-b i32 (i32.const 1))
+ (global $global-b-mut (mut i32) (i32.const 1))
(elem (get_global $tableBase) $only-a $willCollide $some-func $some-collide $only-a $only-a $only-b $willCollide$0 $some-func-b $some-collide$0)
(data (get_global $memoryBase) "hello, A!\n\00\00\00\00\00\00hello, B!\n")
(export "exp-a" (func $only-a))
@@ -34,11 +32,10 @@
(i32.const 456)
(i32.const 789)
)
+ (nop)
+ (nop)
(drop
- (get_global $global-collide)
- )
- (drop
- (get_global $global-a)
+ (get_global $global-a-mut)
)
(drop
(get_global $memoryBase)
@@ -64,11 +61,10 @@
(i32.const 34)
(i32.const 56)
)
+ (nop)
+ (nop)
(drop
- (get_global $global-collide$0)
- )
- (drop
- (get_global $global-b)
+ (get_global $global-b-mut)
)
(drop
(i32.add
diff --git a/test/merge/basics.wast.toMerge b/test/merge/basics.wast.toMerge
index 954b95bce..97d4a73a3 100644
--- a/test/merge/basics.wast.toMerge
+++ b/test/merge/basics.wast.toMerge
@@ -10,6 +10,7 @@
(global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
(global $global-b i32 (i32.const 1))
+ (global $global-b-mut (mut i32) (i32.const 1))
(elem (get_global $tableBase) $only-b $willCollide $some-func-b $some-collide)
(export "exp-b" (func $only-b))
(export "exp-collide" (func $only-b))
@@ -27,6 +28,7 @@
)
(drop (get_global $global-collide))
(drop (get_global $global-b))
+ (drop (get_global $global-b-mut))
(drop (get_global $memoryBase))
(drop (get_global $tableBase))
(drop
diff --git a/test/merge/fusing.wast.combined.finalized.opt b/test/merge/fusing.wast.combined.finalized.opt
index 409fe83c4..9a07b683c 100644
--- a/test/merge/fusing.wast.combined.finalized.opt
+++ b/test/merge/fusing.wast.combined.finalized.opt
@@ -11,20 +11,10 @@
(func $foo-func (; 0 ;) (type $FUNCSIG$v)
(nop)
(call $bar-func)
- (drop
- (get_global $a-global)
- )
- (drop
- (get_global $b-global)
- )
+ (nop)
+ (nop)
)
(func $bar-func (; 1 ;) (type $FUNCSIG$v)
(nop)
- (drop
- (get_global $a-global)
- )
- (drop
- (get_global $b-global)
- )
)
)
diff --git a/test/merge/fusing.wast.combined.opt b/test/merge/fusing.wast.combined.opt
index d2fed3cbd..c27ab0228 100644
--- a/test/merge/fusing.wast.combined.opt
+++ b/test/merge/fusing.wast.combined.opt
@@ -14,20 +14,10 @@
(func $foo-func (; 0 ;) (type $FUNCSIG$v)
(nop)
(call $bar-func)
- (drop
- (get_global $a-global)
- )
- (drop
- (get_global $b-global)
- )
+ (nop)
+ (nop)
)
(func $bar-func (; 1 ;) (type $FUNCSIG$v)
(nop)
- (drop
- (get_global $a-global)
- )
- (drop
- (get_global $b-global)
- )
)
)
diff --git a/test/merge/global-init.wast b/test/merge/global-init.wast
index ddf1a868f..532aafd76 100644
--- a/test/merge/global-init.wast
+++ b/test/merge/global-init.wast
@@ -5,6 +5,8 @@
(import "env" "table" (table 0 anyfunc))
(import "env" "globally" (global $i-collide i32))
(global $a i32 (get_global $i-collide))
+ (global $a-mut (mut i32) (get_global $i-collide))
(global $g-collide i32 (get_global $i-collide))
+ (global $g-collide-mut (mut i32) (get_global $i-collide))
)
diff --git a/test/merge/global-init.wast.combined b/test/merge/global-init.wast.combined
index 0361e567f..095d6056b 100644
--- a/test/merge/global-init.wast.combined
+++ b/test/merge/global-init.wast.combined
@@ -8,8 +8,12 @@
(import "env" "tableBase" (global $tableBase$0 i32))
(import "env" "globally" (global $i-collide$0 f64))
(global $a i32 (get_global $i-collide))
+ (global $a-mut (mut i32) (get_global $i-collide))
(global $g-collide i32 (get_global $i-collide))
+ (global $g-collide-mut (mut i32) (get_global $i-collide))
(global $b f64 (get_global $i-collide$0))
+ (global $b-mut (mut f64) (get_global $i-collide$0))
(global $g-collide$0 f64 (get_global $i-collide$0))
+ (global $g-collide-mut$0 (mut f64) (get_global $i-collide$0))
(data (get_global $memoryBase) "")
)
diff --git a/test/merge/global-init.wast.combined.finalized b/test/merge/global-init.wast.combined.finalized
index c60d28850..832e86457 100644
--- a/test/merge/global-init.wast.combined.finalized
+++ b/test/merge/global-init.wast.combined.finalized
@@ -8,8 +8,12 @@
(import "env" "tableBase" (global $tableBase$0 i32))
(import "env" "globally" (global $i-collide$0 f64))
(global $a i32 (get_global $i-collide))
+ (global $a-mut (mut i32) (get_global $i-collide))
(global $g-collide i32 (get_global $i-collide))
+ (global $g-collide-mut (mut i32) (get_global $i-collide))
(global $b f64 (get_global $i-collide$0))
+ (global $b-mut (mut f64) (get_global $i-collide$0))
(global $g-collide$0 f64 (get_global $i-collide$0))
+ (global $g-collide-mut$0 (mut f64) (get_global $i-collide$0))
(data (i32.const 1024) "")
)
diff --git a/test/merge/global-init.wast.toMerge b/test/merge/global-init.wast.toMerge
index 6f5d5e6dd..b4efd3ca4 100644
--- a/test/merge/global-init.wast.toMerge
+++ b/test/merge/global-init.wast.toMerge
@@ -5,6 +5,8 @@
(import "env" "table" (table 0 anyfunc))
(import "env" "globally" (global $i-collide f64))
(global $b f64 (get_global $i-collide))
+ (global $b-mut (mut f64) (get_global $i-collide))
(global $g-collide f64 (get_global $i-collide))
+ (global $g-collide-mut (mut f64) (get_global $i-collide))
)
diff --git a/test/merge/noBases.wast.combined.finalized.opt b/test/merge/noBases.wast.combined.finalized.opt
index 95e42c10d..8f8433211 100644
--- a/test/merge/noBases.wast.combined.finalized.opt
+++ b/test/merge/noBases.wast.combined.finalized.opt
@@ -7,12 +7,8 @@
(import "env" "some-collide" (func $some-collide))
(import "env" "some-func-b" (func $some-func-b))
(import "env" "some-collide" (func $some-collide$0))
- (global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
- (global $global-a i32 (i32.const 1))
- (global $global-collide$0 i32 (i32.const 0))
(global $global-collide-mut$0 (mut i32) (i32.const 0))
- (global $global-b i32 (i32.const 1))
(elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
(elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
(data (i32.const 100) "hello, A!\n")
@@ -32,12 +28,8 @@
(i32.const 456)
(i32.const 789)
)
- (drop
- (get_global $global-collide)
- )
- (drop
- (get_global $global-a)
- )
+ (nop)
+ (nop)
(set_global $global-collide-mut
(i32.const 1234)
)
@@ -56,12 +48,8 @@
(i32.const 34)
(i32.const 56)
)
- (drop
- (get_global $global-collide$0)
- )
- (drop
- (get_global $global-b)
- )
+ (nop)
+ (nop)
(set_global $global-collide-mut$0
(i32.const 5678)
)
diff --git a/test/merge/noBases.wast.combined.opt b/test/merge/noBases.wast.combined.opt
index d844aa292..921cf5f9b 100644
--- a/test/merge/noBases.wast.combined.opt
+++ b/test/merge/noBases.wast.combined.opt
@@ -9,12 +9,8 @@
(import "env" "tableBase" (global $tableBase i32))
(import "env" "some-func-b" (func $some-func-b))
(import "env" "some-collide" (func $some-collide$0))
- (global $global-collide i32 (i32.const 0))
(global $global-collide-mut (mut i32) (i32.const 0))
- (global $global-a i32 (i32.const 1))
- (global $global-collide$0 i32 (i32.const 0))
(global $global-collide-mut$0 (mut i32) (i32.const 0))
- (global $global-b i32 (i32.const 1))
(elem (i32.const 10) $only-a $willCollide $some-func $some-collide $only-a)
(elem (i32.const 20) $only-b $willCollide $some-func-b $some-collide)
(data (i32.const 100) "hello, A!\n")
@@ -35,12 +31,8 @@
(i32.const 456)
(i32.const 789)
)
- (drop
- (get_global $global-collide)
- )
- (drop
- (get_global $global-a)
- )
+ (nop)
+ (nop)
(set_global $global-collide-mut
(i32.const 1234)
)
@@ -59,12 +51,8 @@
(i32.const 34)
(i32.const 56)
)
- (drop
- (get_global $global-collide$0)
- )
- (drop
- (get_global $global-b)
- )
+ (nop)
+ (nop)
(set_global $global-collide-mut$0
(i32.const 5678)
)
diff --git a/test/passes/precompute.txt b/test/passes/precompute.txt
index 1468e8a66..166d0b575 100644
--- a/test/passes/precompute.txt
+++ b/test/passes/precompute.txt
@@ -3,7 +3,8 @@
(type $1 (func (result i32)))
(type $2 (func))
(type $3 (func (result f64)))
- (global $global$0 (mut i32) (i32.const 0))
+ (global $global i32 (i32.const 1))
+ (global $global-mut (mut i32) (i32.const 2))
(memory $0 0)
(func $x (; 0 ;) (type $0) (param $x i32)
(call $x
@@ -165,7 +166,7 @@
(select
(i64.const 1)
(block $block
- (set_global $global$0
+ (set_global $global-mut
(i32.const 1)
)
(br $label$0
@@ -188,4 +189,22 @@
)
)
)
+ (func $global-notprecomputable (; 8 ;) (type $1) (result i32)
+ (i32.add
+ (i32.const 1)
+ (get_global $global-mut)
+ )
+ )
+ (func $global-precomputable (; 9 ;) (type $1) (result i32)
+ (i32.const 2)
+ )
+ (func $global-partiallyprecomputable (; 10 ;) (type $1) (result i32)
+ (i32.sub
+ (i32.add
+ (i32.const 1)
+ (get_global $global-mut)
+ )
+ (i32.const 2)
+ )
+ )
)
diff --git a/test/passes/precompute.wast b/test/passes/precompute.wast
index da4185b6a..2c87d3706 100644
--- a/test/passes/precompute.wast
+++ b/test/passes/precompute.wast
@@ -1,7 +1,8 @@
(module
(memory 0)
(type $0 (func (param i32)))
- (global $global$0 (mut i32) (i32.const 0))
+ (global $global i32 (i32.const 1))
+ (global $global-mut (mut i32) (i32.const 2))
(func $x (type $0) (param $x i32)
(call $x
(i32.add
@@ -257,7 +258,7 @@
(select
(i64.const 1)
(block (result i64)
- (set_global $global$0
+ (set_global $global-mut
(i32.const 1)
)
(br_if $label$0
@@ -281,4 +282,28 @@
)
)
)
+ (func $global-notprecomputable (result i32)
+ (i32.add
+ (i32.const 1)
+ (get_global $global-mut)
+ )
+ )
+ (func $global-precomputable (result i32)
+ (i32.add
+ (i32.const 1)
+ (get_global $global)
+ )
+ )
+ (func $global-partiallyprecomputable (result i32)
+ (i32.sub
+ (i32.add
+ (i32.const 1)
+ (get_global $global-mut)
+ )
+ (i32.add
+ (i32.const 1)
+ (get_global $global)
+ )
+ )
+ )
)