summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast_utils.h26
-rw-r--r--test/emcc_hello_world.fromasm299
-rw-r--r--test/emcc_hello_world.fromasm.imprecise299
-rw-r--r--test/unit.asm.js13
-rw-r--r--test/unit.fromasm28
-rw-r--r--test/unit.fromasm.imprecise28
-rw-r--r--test/unit.fromasm.imprecise.no-opts35
-rw-r--r--test/unit.fromasm.no-opts35
8 files changed, 455 insertions, 308 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index 9b2ff10cd..f7a486332 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -92,13 +92,16 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer
bool calls = false;
std::set<Index> localsRead;
std::set<Index> localsWritten;
+ std::set<Name> globalsRead;
+ std::set<Name> globalsWritten;
bool readsMemory = false;
bool writesMemory = false;
bool accessesLocal() { return localsRead.size() + localsWritten.size() > 0; }
+ bool accessesGlobal() { return globalsRead.size() + globalsWritten.size() > 0; }
bool accessesMemory() { return calls || readsMemory || writesMemory; }
- bool hasSideEffects() { return calls || localsWritten.size() > 0 || writesMemory || branches; }
- bool hasAnything() { return branches || calls || accessesLocal() || readsMemory || writesMemory; }
+ bool hasSideEffects() { return calls || localsWritten.size() > 0 || writesMemory || branches || globalsWritten.size() > 0; }
+ bool hasAnything() { return branches || calls || accessesLocal() || readsMemory || writesMemory || accessesGlobal(); }
// checks if these effects would invalidate another set (e.g., if we write, we invalidate someone that reads, they can't be moved past us)
bool invalidates(EffectAnalyzer& other) {
@@ -115,6 +118,17 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer
for (auto local : localsRead) {
if (other.localsWritten.count(local)) return true;
}
+ if ((accessesGlobal() && other.calls) || (other.accessesGlobal() && calls)) {
+ return true;
+ }
+ for (auto global : globalsWritten) {
+ if (other.globalsWritten.count(global) || other.globalsRead.count(global)) {
+ return true;
+ }
+ }
+ for (auto global : globalsRead) {
+ if (other.globalsWritten.count(global)) return true;
+ }
return false;
}
@@ -163,8 +177,12 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer
void visitSetLocal(SetLocal *curr) {
localsWritten.insert(curr->index);
}
- void visitGetGlobal(GetGlobal *curr) { readsMemory = true; } // TODO: global-specific
- void visitSetGlobal(SetGlobal *curr) { writesMemory = true; } // stuff?
+ void visitGetGlobal(GetGlobal *curr) {
+ globalsRead.insert(curr->name);
+ }
+ void visitSetGlobal(SetGlobal *curr) {
+ globalsWritten.insert(curr->name);
+ }
void visitLoad(Load *curr) { readsMemory = true; }
void visitStore(Store *curr) { writesMemory = true; }
void visitReturn(Return *curr) { branches = true; }
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 15b9aa473..36a6c1ff1 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -2779,7 +2779,7 @@
(i32.const 528)
)
)
- (set_local $44
+ (set_local $45
(i32.ne
(get_local $0)
(i32.const 0)
@@ -2815,7 +2815,7 @@
(i32.const 4)
)
)
- (set_local $52
+ (set_local $53
(i32.add
(tee_local $5
(i32.add
@@ -2835,7 +2835,7 @@
(set_local $77
(i32.sub
(tee_local $40
- (get_local $52)
+ (get_local $53)
)
(tee_local $64
(tee_local $29
@@ -2871,14 +2871,14 @@
)
)
(set_local $75
- (tee_local $45
+ (tee_local $46
(i32.add
(get_local $29)
(i32.const 9)
)
)
)
- (set_local $53
+ (set_local $54
(i32.add
(get_local $29)
(i32.const 8)
@@ -2973,7 +2973,7 @@
)
)
)
- (set_local $54
+ (set_local $55
(get_local $5)
)
(set_local $65
@@ -2987,7 +2987,7 @@
(set_local $41
(get_local $5)
)
- (set_local $55
+ (set_local $56
(get_local $5)
)
(br $label$break$L9)
@@ -3019,15 +3019,15 @@
(if
(i32.ne
(i32.load8_s offset=1
- (get_local $54)
+ (get_local $55)
)
(i32.const 37)
)
(block
(set_local $41
- (get_local $54)
+ (get_local $55)
)
- (set_local $55
+ (set_local $56
(get_local $65)
)
(br $label$break$L12)
@@ -3044,7 +3044,7 @@
(i32.load8_s
(tee_local $1
(i32.add
- (get_local $54)
+ (get_local $55)
(i32.const 2)
)
)
@@ -3052,7 +3052,7 @@
(i32.const 37)
)
(block
- (set_local $54
+ (set_local $55
(get_local $1)
)
(set_local $65
@@ -3063,7 +3063,7 @@
(set_local $41
(get_local $1)
)
- (set_local $55
+ (set_local $56
(get_local $5)
)
(br $while-out$7)
@@ -3076,12 +3076,12 @@
)
(set_local $17
(i32.sub
- (get_local $55)
+ (get_local $56)
(get_local $20)
)
)
(if
- (get_local $44)
+ (get_local $45)
(if
(i32.eqz
(i32.and
@@ -3100,7 +3100,7 @@
)
(if
(i32.ne
- (get_local $55)
+ (get_local $56)
(get_local $20)
)
(block
@@ -3360,7 +3360,7 @@
(i32.const 3)
)
)
- (set_local $56
+ (set_local $57
(get_local $1)
)
)
@@ -3392,7 +3392,7 @@
)
(if
(i32.eqz
- (get_local $44)
+ (get_local $45)
)
(block
(set_local $9
@@ -3435,7 +3435,7 @@
(set_local $67
(get_local $6)
)
- (set_local $56
+ (set_local $57
(get_local $5)
)
)
@@ -3443,7 +3443,7 @@
(set_local $8
(if
(i32.lt_s
- (get_local $56)
+ (get_local $57)
(i32.const 0)
)
(block
@@ -3456,7 +3456,7 @@
(set_local $16
(i32.sub
(i32.const 0)
- (get_local $56)
+ (get_local $57)
)
)
(i32.or
@@ -3472,7 +3472,7 @@
(get_local $66)
)
(set_local $16
- (get_local $56)
+ (get_local $57)
)
(get_local $8)
)
@@ -3746,7 +3746,7 @@
)
)
(if
- (get_local $44)
+ (get_local $45)
(block
(set_local $5
(i32.load
@@ -3963,7 +3963,7 @@
)
(if
(i32.eqz
- (get_local $44)
+ (get_local $45)
)
(block
(set_local $24
@@ -3991,7 +3991,7 @@
)
(if
(i32.eqz
- (get_local $44)
+ (get_local $45)
)
(block
(set_local $20
@@ -4255,13 +4255,13 @@
)
(br $label$continue$L1)
)
- (set_local $46
+ (set_local $47
(i32.or
(get_local $18)
(i32.const 8)
)
)
- (set_local $57
+ (set_local $58
(select
(get_local $10)
(i32.const 8)
@@ -4279,10 +4279,10 @@
)
(br $switch$24)
)
- (set_local $46
+ (set_local $47
(get_local $18)
)
- (set_local $57
+ (set_local $58
(get_local $10)
)
(set_local $68
@@ -4362,7 +4362,7 @@
)
)
)
- (set_local $58
+ (set_local $59
(if
(i32.and
(get_local $18)
@@ -4383,7 +4383,7 @@
)
)
)
- (set_local $34
+ (set_local $33
(get_local $18)
)
(set_local $32
@@ -4393,10 +4393,10 @@
(get_local $5)
)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -4405,16 +4405,16 @@
(get_local $6)
)
(block
- (set_local $34
+ (set_local $33
(get_local $18)
)
(set_local $32
(get_local $10)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -4435,7 +4435,7 @@
)
(if
(i32.lt_s
- (tee_local $33
+ (tee_local $36
(i32.load offset=4
(get_local $1)
)
@@ -4443,31 +4443,29 @@
(i32.const 0)
)
(block
- (set_local $1
- (call $_i64Subtract
- (i32.const 0)
- (i32.const 0)
- (get_local $5)
- (get_local $33)
- )
- )
- (set_local $5
- (get_global $tempRet0)
- )
(i32.store
- (tee_local $33
+ (tee_local $42
(get_local $19)
)
- (get_local $1)
+ (tee_local $1
+ (call $_i64Subtract
+ (i32.const 0)
+ (i32.const 0)
+ (get_local $5)
+ (get_local $36)
+ )
+ )
)
(i32.store offset=4
- (get_local $33)
- (get_local $5)
+ (get_local $42)
+ (tee_local $5
+ (get_global $tempRet0)
+ )
)
- (set_local $33
+ (set_local $36
(get_local $1)
)
- (set_local $59
+ (set_local $42
(get_local $5)
)
(set_local $60
@@ -4482,15 +4480,15 @@
(br $switch$24)
)
)
- (set_local $33
+ (set_local $36
(if
(i32.and
(get_local $18)
(i32.const 2048)
)
(block
- (set_local $59
- (get_local $33)
+ (set_local $42
+ (get_local $36)
)
(set_local $60
(i32.const 1)
@@ -4518,8 +4516,8 @@
)
)
)
- (set_local $59
- (get_local $33)
+ (set_local $42
+ (get_local $36)
)
(set_local $60
(get_local $6)
@@ -4536,14 +4534,14 @@
)
(br $switch$24)
)
- (set_local $33
+ (set_local $36
(i32.load
(tee_local $1
(get_local $19)
)
)
)
- (set_local $59
+ (set_local $42
(i32.load offset=4
(get_local $1)
)
@@ -4571,27 +4569,27 @@
(i32.const 255)
)
)
- (set_local $47
+ (set_local $48
(get_local $72)
)
(set_local $37
(get_local $7)
)
- (set_local $42
+ (set_local $43
(i32.const 1)
)
- (set_local $43
+ (set_local $44
(i32.const 0)
)
- (set_local $48
+ (set_local $49
(i32.const 4091)
)
- (set_local $49
+ (set_local $50
(get_local $28)
)
(br $switch$24)
)
- (set_local $50
+ (set_local $51
(call $_strerror
(i32.load
(call $___errno_location)
@@ -4613,7 +4611,7 @@
(i32.const 0)
)
)
- (set_local $50
+ (set_local $51
(select
(get_local $1)
(i32.const 4101)
@@ -4689,7 +4687,7 @@
(get_global $tempDoublePtr)
(get_local $14)
)
- (set_local $51
+ (set_local $52
(if
(i32.lt_s
(i32.load offset=4
@@ -4825,7 +4823,7 @@
)
(set_local $7
(i32.or
- (get_local $51)
+ (get_local $52)
(i32.const 2)
)
)
@@ -4940,10 +4938,10 @@
(call $_fmt_u
(get_local $8)
(get_local $5)
- (get_local $52)
+ (get_local $53)
)
)
- (get_local $52)
+ (get_local $53)
)
(block
(i32.store8
@@ -6039,7 +6037,7 @@
(set_local $14
(block $do-once$90
(if
- (get_local $51)
+ (get_local $52)
(block
(br_if $do-once$90
(get_local $14)
@@ -6618,7 +6616,7 @@
(call $_fmt_u
(get_local $6)
(get_local $5)
- (get_local $52)
+ (get_local $53)
)
)
)
@@ -6698,7 +6696,7 @@
(i32.add
(i32.add
(i32.add
- (get_local $51)
+ (get_local $52)
(i32.const 1)
)
(get_local $15)
@@ -6721,7 +6719,7 @@
)
(call $___fwritex
(get_local $39)
- (get_local $51)
+ (get_local $52)
(get_local $0)
)
)
@@ -6759,7 +6757,7 @@
(get_local $7)
)
(i32.const 0)
- (get_local $45)
+ (get_local $46)
)
)
(block $do-once$110
@@ -6772,15 +6770,15 @@
(br_if $do-once$110
(i32.ne
(get_local $5)
- (get_local $45)
+ (get_local $46)
)
)
(i32.store8
- (get_local $53)
+ (get_local $54)
(i32.const 48)
)
(set_local $5
- (get_local $53)
+ (get_local $54)
)
)
(block
@@ -6900,7 +6898,7 @@
(get_local $5)
)
(i32.const 0)
- (get_local $45)
+ (get_local $46)
)
)
(get_local $29)
@@ -7033,17 +7031,17 @@
(get_local $5)
)
(i32.const 0)
- (get_local $45)
+ (get_local $46)
)
)
- (get_local $45)
+ (get_local $46)
)
(block
(i32.store8
- (get_local $53)
+ (get_local $54)
(i32.const 48)
)
- (get_local $53)
+ (get_local $54)
)
(get_local $1)
)
@@ -7272,7 +7270,7 @@
(set_local $6
(select
(i32.const 0)
- (get_local $51)
+ (get_local $52)
(tee_local $1
(i32.or
(f64.ne
@@ -7369,22 +7367,22 @@
)
(br $label$continue$L1)
)
- (set_local $47
+ (set_local $48
(get_local $20)
)
(set_local $37
(get_local $18)
)
- (set_local $42
+ (set_local $43
(get_local $10)
)
- (set_local $43
+ (set_local $44
(i32.const 0)
)
- (set_local $48
+ (set_local $49
(i32.const 4091)
)
- (set_local $49
+ (set_local $50
(get_local $28)
)
)
@@ -7401,7 +7399,7 @@
(i32.const 32)
)
)
- (set_local $58
+ (set_local $59
(if
(i32.and
(i32.eqz
@@ -7422,16 +7420,16 @@
)
)
(block
- (set_local $34
- (get_local $46)
+ (set_local $33
+ (get_local $47)
)
(set_local $32
- (get_local $57)
+ (get_local $58)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -7496,7 +7494,7 @@
(i32.or
(i32.eqz
(i32.and
- (get_local $46)
+ (get_local $47)
(i32.const 8)
)
)
@@ -7516,16 +7514,16 @@
)
)
(block
- (set_local $34
- (get_local $46)
+ (set_local $33
+ (get_local $47)
)
(set_local $32
- (get_local $57)
+ (get_local $58)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -7534,16 +7532,16 @@
(get_local $6)
)
(block
- (set_local $34
- (get_local $46)
+ (set_local $33
+ (get_local $47)
)
(set_local $32
- (get_local $57)
+ (get_local $58)
)
- (set_local $35
+ (set_local $34
(i32.const 2)
)
- (set_local $36
+ (set_local $35
(i32.add
(i32.const 4091)
(i32.shr_s
@@ -7568,23 +7566,23 @@
(i32.const 76)
)
(block
- (set_local $58
+ (set_local $59
(call $_fmt_u
- (get_local $33)
- (get_local $59)
+ (get_local $36)
+ (get_local $42)
(get_local $28)
)
)
- (set_local $34
+ (set_local $33
(get_local $18)
)
(set_local $32
(get_local $10)
)
- (set_local $35
+ (set_local $34
(get_local $60)
)
- (set_local $36
+ (set_local $35
(get_local $61)
)
(set_local $12
@@ -7604,39 +7602,39 @@
(i32.eqz
(tee_local $1
(call $_memchr
- (get_local $50)
+ (get_local $51)
(i32.const 0)
(get_local $10)
)
)
)
)
- (set_local $47
- (get_local $50)
+ (set_local $48
+ (get_local $51)
)
(set_local $37
(get_local $7)
)
- (set_local $42
+ (set_local $43
(select
(get_local $10)
(i32.sub
(get_local $1)
- (get_local $50)
+ (get_local $51)
)
(get_local $5)
)
)
- (set_local $43
+ (set_local $44
(i32.const 0)
)
- (set_local $48
+ (set_local $49
(i32.const 4091)
)
- (set_local $49
+ (set_local $50
(select
(i32.add
- (get_local $50)
+ (get_local $51)
(get_local $10)
)
(get_local $1)
@@ -7907,17 +7905,17 @@
(set_local $5
(select
(i32.and
- (get_local $34)
+ (get_local $33)
(i32.const -65537)
)
- (get_local $34)
+ (get_local $33)
(i32.gt_s
(get_local $32)
(i32.const -1)
)
)
)
- (set_local $47
+ (set_local $48
(if
(i32.or
(i32.ne
@@ -7958,7 +7956,7 @@
)
(i32.sub
(get_local $71)
- (get_local $58)
+ (get_local $59)
)
)
)
@@ -7967,38 +7965,38 @@
(set_local $37
(get_local $5)
)
- (set_local $42
+ (set_local $43
(select
(get_local $32)
(get_local $1)
(get_local $7)
)
)
- (set_local $43
- (get_local $35)
- )
- (set_local $48
- (get_local $36)
+ (set_local $44
+ (get_local $34)
)
(set_local $49
+ (get_local $35)
+ )
+ (set_local $50
(get_local $28)
)
- (get_local $58)
+ (get_local $59)
)
(block
(set_local $37
(get_local $5)
)
- (set_local $42
+ (set_local $43
(i32.const 0)
)
- (set_local $43
- (get_local $35)
- )
- (set_local $48
- (get_local $36)
+ (set_local $44
+ (get_local $34)
)
(set_local $49
+ (get_local $35)
+ )
+ (set_local $50
(get_local $28)
)
(get_local $28)
@@ -8009,11 +8007,11 @@
)
(set_local $1
(i32.lt_s
- (get_local $42)
+ (get_local $43)
(tee_local $7
(i32.sub
- (get_local $49)
- (get_local $47)
+ (get_local $50)
+ (get_local $48)
)
)
)
@@ -8023,11 +8021,11 @@
(get_local $16)
(tee_local $1
(i32.add
- (get_local $43)
+ (get_local $44)
(tee_local $6
(select
(get_local $7)
- (get_local $42)
+ (get_local $43)
(get_local $1)
)
)
@@ -8058,8 +8056,8 @@
)
)
(call $___fwritex
- (get_local $48)
- (get_local $43)
+ (get_local $49)
+ (get_local $44)
(get_local $0)
)
)
@@ -8090,7 +8088,7 @@
)
)
(call $___fwritex
- (get_local $47)
+ (get_local $48)
(get_local $7)
(get_local $0)
)
@@ -17681,14 +17679,11 @@
(get_local $5)
)
)
- (set_local $1
- (get_global $tempRet0)
- )
(set_global $STACKTOP
(get_local $6)
)
(set_global $tempRet0
- (get_local $1)
+ (get_global $tempRet0)
)
(get_local $0)
)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 9d70778d5..cb25aad51 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -2772,7 +2772,7 @@
(i32.const 528)
)
)
- (set_local $44
+ (set_local $45
(i32.ne
(get_local $0)
(i32.const 0)
@@ -2808,7 +2808,7 @@
(i32.const 4)
)
)
- (set_local $52
+ (set_local $53
(i32.add
(tee_local $5
(i32.add
@@ -2828,7 +2828,7 @@
(set_local $77
(i32.sub
(tee_local $40
- (get_local $52)
+ (get_local $53)
)
(tee_local $64
(tee_local $29
@@ -2864,14 +2864,14 @@
)
)
(set_local $75
- (tee_local $45
+ (tee_local $46
(i32.add
(get_local $29)
(i32.const 9)
)
)
)
- (set_local $53
+ (set_local $54
(i32.add
(get_local $29)
(i32.const 8)
@@ -2966,7 +2966,7 @@
)
)
)
- (set_local $54
+ (set_local $55
(get_local $5)
)
(set_local $65
@@ -2980,7 +2980,7 @@
(set_local $41
(get_local $5)
)
- (set_local $55
+ (set_local $56
(get_local $5)
)
(br $label$break$L9)
@@ -3012,15 +3012,15 @@
(if
(i32.ne
(i32.load8_s offset=1
- (get_local $54)
+ (get_local $55)
)
(i32.const 37)
)
(block
(set_local $41
- (get_local $54)
+ (get_local $55)
)
- (set_local $55
+ (set_local $56
(get_local $65)
)
(br $label$break$L12)
@@ -3037,7 +3037,7 @@
(i32.load8_s
(tee_local $1
(i32.add
- (get_local $54)
+ (get_local $55)
(i32.const 2)
)
)
@@ -3045,7 +3045,7 @@
(i32.const 37)
)
(block
- (set_local $54
+ (set_local $55
(get_local $1)
)
(set_local $65
@@ -3056,7 +3056,7 @@
(set_local $41
(get_local $1)
)
- (set_local $55
+ (set_local $56
(get_local $5)
)
(br $while-out$7)
@@ -3069,12 +3069,12 @@
)
(set_local $17
(i32.sub
- (get_local $55)
+ (get_local $56)
(get_local $20)
)
)
(if
- (get_local $44)
+ (get_local $45)
(if
(i32.eqz
(i32.and
@@ -3093,7 +3093,7 @@
)
(if
(i32.ne
- (get_local $55)
+ (get_local $56)
(get_local $20)
)
(block
@@ -3353,7 +3353,7 @@
(i32.const 3)
)
)
- (set_local $56
+ (set_local $57
(get_local $1)
)
)
@@ -3385,7 +3385,7 @@
)
(if
(i32.eqz
- (get_local $44)
+ (get_local $45)
)
(block
(set_local $9
@@ -3428,7 +3428,7 @@
(set_local $67
(get_local $6)
)
- (set_local $56
+ (set_local $57
(get_local $5)
)
)
@@ -3436,7 +3436,7 @@
(set_local $8
(if
(i32.lt_s
- (get_local $56)
+ (get_local $57)
(i32.const 0)
)
(block
@@ -3449,7 +3449,7 @@
(set_local $16
(i32.sub
(i32.const 0)
- (get_local $56)
+ (get_local $57)
)
)
(i32.or
@@ -3465,7 +3465,7 @@
(get_local $66)
)
(set_local $16
- (get_local $56)
+ (get_local $57)
)
(get_local $8)
)
@@ -3739,7 +3739,7 @@
)
)
(if
- (get_local $44)
+ (get_local $45)
(block
(set_local $5
(i32.load
@@ -3956,7 +3956,7 @@
)
(if
(i32.eqz
- (get_local $44)
+ (get_local $45)
)
(block
(set_local $24
@@ -3984,7 +3984,7 @@
)
(if
(i32.eqz
- (get_local $44)
+ (get_local $45)
)
(block
(set_local $20
@@ -4248,13 +4248,13 @@
)
(br $label$continue$L1)
)
- (set_local $46
+ (set_local $47
(i32.or
(get_local $18)
(i32.const 8)
)
)
- (set_local $57
+ (set_local $58
(select
(get_local $10)
(i32.const 8)
@@ -4272,10 +4272,10 @@
)
(br $switch$24)
)
- (set_local $46
+ (set_local $47
(get_local $18)
)
- (set_local $57
+ (set_local $58
(get_local $10)
)
(set_local $68
@@ -4355,7 +4355,7 @@
)
)
)
- (set_local $58
+ (set_local $59
(if
(i32.and
(get_local $18)
@@ -4376,7 +4376,7 @@
)
)
)
- (set_local $34
+ (set_local $33
(get_local $18)
)
(set_local $32
@@ -4386,10 +4386,10 @@
(get_local $5)
)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -4398,16 +4398,16 @@
(get_local $6)
)
(block
- (set_local $34
+ (set_local $33
(get_local $18)
)
(set_local $32
(get_local $10)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -4428,7 +4428,7 @@
)
(if
(i32.lt_s
- (tee_local $33
+ (tee_local $36
(i32.load offset=4
(get_local $1)
)
@@ -4436,31 +4436,29 @@
(i32.const 0)
)
(block
- (set_local $1
- (call $_i64Subtract
- (i32.const 0)
- (i32.const 0)
- (get_local $5)
- (get_local $33)
- )
- )
- (set_local $5
- (get_global $tempRet0)
- )
(i32.store
- (tee_local $33
+ (tee_local $42
(get_local $19)
)
- (get_local $1)
+ (tee_local $1
+ (call $_i64Subtract
+ (i32.const 0)
+ (i32.const 0)
+ (get_local $5)
+ (get_local $36)
+ )
+ )
)
(i32.store offset=4
- (get_local $33)
- (get_local $5)
+ (get_local $42)
+ (tee_local $5
+ (get_global $tempRet0)
+ )
)
- (set_local $33
+ (set_local $36
(get_local $1)
)
- (set_local $59
+ (set_local $42
(get_local $5)
)
(set_local $60
@@ -4475,15 +4473,15 @@
(br $switch$24)
)
)
- (set_local $33
+ (set_local $36
(if
(i32.and
(get_local $18)
(i32.const 2048)
)
(block
- (set_local $59
- (get_local $33)
+ (set_local $42
+ (get_local $36)
)
(set_local $60
(i32.const 1)
@@ -4511,8 +4509,8 @@
)
)
)
- (set_local $59
- (get_local $33)
+ (set_local $42
+ (get_local $36)
)
(set_local $60
(get_local $6)
@@ -4529,14 +4527,14 @@
)
(br $switch$24)
)
- (set_local $33
+ (set_local $36
(i32.load
(tee_local $1
(get_local $19)
)
)
)
- (set_local $59
+ (set_local $42
(i32.load offset=4
(get_local $1)
)
@@ -4564,27 +4562,27 @@
(i32.const 255)
)
)
- (set_local $47
+ (set_local $48
(get_local $72)
)
(set_local $37
(get_local $7)
)
- (set_local $42
+ (set_local $43
(i32.const 1)
)
- (set_local $43
+ (set_local $44
(i32.const 0)
)
- (set_local $48
+ (set_local $49
(i32.const 4091)
)
- (set_local $49
+ (set_local $50
(get_local $28)
)
(br $switch$24)
)
- (set_local $50
+ (set_local $51
(call $_strerror
(i32.load
(call $___errno_location)
@@ -4606,7 +4604,7 @@
(i32.const 0)
)
)
- (set_local $50
+ (set_local $51
(select
(get_local $1)
(i32.const 4101)
@@ -4682,7 +4680,7 @@
(get_global $tempDoublePtr)
(get_local $14)
)
- (set_local $51
+ (set_local $52
(if
(i32.lt_s
(i32.load offset=4
@@ -4818,7 +4816,7 @@
)
(set_local $7
(i32.or
- (get_local $51)
+ (get_local $52)
(i32.const 2)
)
)
@@ -4933,10 +4931,10 @@
(call $_fmt_u
(get_local $8)
(get_local $5)
- (get_local $52)
+ (get_local $53)
)
)
- (get_local $52)
+ (get_local $53)
)
(block
(i32.store8
@@ -6032,7 +6030,7 @@
(set_local $14
(block $do-once$90
(if
- (get_local $51)
+ (get_local $52)
(block
(br_if $do-once$90
(get_local $14)
@@ -6611,7 +6609,7 @@
(call $_fmt_u
(get_local $6)
(get_local $5)
- (get_local $52)
+ (get_local $53)
)
)
)
@@ -6691,7 +6689,7 @@
(i32.add
(i32.add
(i32.add
- (get_local $51)
+ (get_local $52)
(i32.const 1)
)
(get_local $15)
@@ -6714,7 +6712,7 @@
)
(call $___fwritex
(get_local $39)
- (get_local $51)
+ (get_local $52)
(get_local $0)
)
)
@@ -6752,7 +6750,7 @@
(get_local $7)
)
(i32.const 0)
- (get_local $45)
+ (get_local $46)
)
)
(block $do-once$110
@@ -6765,15 +6763,15 @@
(br_if $do-once$110
(i32.ne
(get_local $5)
- (get_local $45)
+ (get_local $46)
)
)
(i32.store8
- (get_local $53)
+ (get_local $54)
(i32.const 48)
)
(set_local $5
- (get_local $53)
+ (get_local $54)
)
)
(block
@@ -6893,7 +6891,7 @@
(get_local $5)
)
(i32.const 0)
- (get_local $45)
+ (get_local $46)
)
)
(get_local $29)
@@ -7026,17 +7024,17 @@
(get_local $5)
)
(i32.const 0)
- (get_local $45)
+ (get_local $46)
)
)
- (get_local $45)
+ (get_local $46)
)
(block
(i32.store8
- (get_local $53)
+ (get_local $54)
(i32.const 48)
)
- (get_local $53)
+ (get_local $54)
)
(get_local $1)
)
@@ -7265,7 +7263,7 @@
(set_local $6
(select
(i32.const 0)
- (get_local $51)
+ (get_local $52)
(tee_local $1
(i32.or
(f64.ne
@@ -7362,22 +7360,22 @@
)
(br $label$continue$L1)
)
- (set_local $47
+ (set_local $48
(get_local $20)
)
(set_local $37
(get_local $18)
)
- (set_local $42
+ (set_local $43
(get_local $10)
)
- (set_local $43
+ (set_local $44
(i32.const 0)
)
- (set_local $48
+ (set_local $49
(i32.const 4091)
)
- (set_local $49
+ (set_local $50
(get_local $28)
)
)
@@ -7394,7 +7392,7 @@
(i32.const 32)
)
)
- (set_local $58
+ (set_local $59
(if
(i32.and
(i32.eqz
@@ -7415,16 +7413,16 @@
)
)
(block
- (set_local $34
- (get_local $46)
+ (set_local $33
+ (get_local $47)
)
(set_local $32
- (get_local $57)
+ (get_local $58)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -7489,7 +7487,7 @@
(i32.or
(i32.eqz
(i32.and
- (get_local $46)
+ (get_local $47)
(i32.const 8)
)
)
@@ -7509,16 +7507,16 @@
)
)
(block
- (set_local $34
- (get_local $46)
+ (set_local $33
+ (get_local $47)
)
(set_local $32
- (get_local $57)
+ (get_local $58)
)
- (set_local $35
+ (set_local $34
(i32.const 0)
)
- (set_local $36
+ (set_local $35
(i32.const 4091)
)
(set_local $12
@@ -7527,16 +7525,16 @@
(get_local $6)
)
(block
- (set_local $34
- (get_local $46)
+ (set_local $33
+ (get_local $47)
)
(set_local $32
- (get_local $57)
+ (get_local $58)
)
- (set_local $35
+ (set_local $34
(i32.const 2)
)
- (set_local $36
+ (set_local $35
(i32.add
(i32.const 4091)
(i32.shr_s
@@ -7561,23 +7559,23 @@
(i32.const 76)
)
(block
- (set_local $58
+ (set_local $59
(call $_fmt_u
- (get_local $33)
- (get_local $59)
+ (get_local $36)
+ (get_local $42)
(get_local $28)
)
)
- (set_local $34
+ (set_local $33
(get_local $18)
)
(set_local $32
(get_local $10)
)
- (set_local $35
+ (set_local $34
(get_local $60)
)
- (set_local $36
+ (set_local $35
(get_local $61)
)
(set_local $12
@@ -7597,39 +7595,39 @@
(i32.eqz
(tee_local $1
(call $_memchr
- (get_local $50)
+ (get_local $51)
(i32.const 0)
(get_local $10)
)
)
)
)
- (set_local $47
- (get_local $50)
+ (set_local $48
+ (get_local $51)
)
(set_local $37
(get_local $7)
)
- (set_local $42
+ (set_local $43
(select
(get_local $10)
(i32.sub
(get_local $1)
- (get_local $50)
+ (get_local $51)
)
(get_local $5)
)
)
- (set_local $43
+ (set_local $44
(i32.const 0)
)
- (set_local $48
+ (set_local $49
(i32.const 4091)
)
- (set_local $49
+ (set_local $50
(select
(i32.add
- (get_local $50)
+ (get_local $51)
(get_local $10)
)
(get_local $1)
@@ -7900,17 +7898,17 @@
(set_local $5
(select
(i32.and
- (get_local $34)
+ (get_local $33)
(i32.const -65537)
)
- (get_local $34)
+ (get_local $33)
(i32.gt_s
(get_local $32)
(i32.const -1)
)
)
)
- (set_local $47
+ (set_local $48
(if
(i32.or
(i32.ne
@@ -7951,7 +7949,7 @@
)
(i32.sub
(get_local $71)
- (get_local $58)
+ (get_local $59)
)
)
)
@@ -7960,38 +7958,38 @@
(set_local $37
(get_local $5)
)
- (set_local $42
+ (set_local $43
(select
(get_local $32)
(get_local $1)
(get_local $7)
)
)
- (set_local $43
- (get_local $35)
- )
- (set_local $48
- (get_local $36)
+ (set_local $44
+ (get_local $34)
)
(set_local $49
+ (get_local $35)
+ )
+ (set_local $50
(get_local $28)
)
- (get_local $58)
+ (get_local $59)
)
(block
(set_local $37
(get_local $5)
)
- (set_local $42
+ (set_local $43
(i32.const 0)
)
- (set_local $43
- (get_local $35)
- )
- (set_local $48
- (get_local $36)
+ (set_local $44
+ (get_local $34)
)
(set_local $49
+ (get_local $35)
+ )
+ (set_local $50
(get_local $28)
)
(get_local $28)
@@ -8002,11 +8000,11 @@
)
(set_local $1
(i32.lt_s
- (get_local $42)
+ (get_local $43)
(tee_local $7
(i32.sub
- (get_local $49)
- (get_local $47)
+ (get_local $50)
+ (get_local $48)
)
)
)
@@ -8016,11 +8014,11 @@
(get_local $16)
(tee_local $1
(i32.add
- (get_local $43)
+ (get_local $44)
(tee_local $6
(select
(get_local $7)
- (get_local $42)
+ (get_local $43)
(get_local $1)
)
)
@@ -8051,8 +8049,8 @@
)
)
(call $___fwritex
- (get_local $48)
- (get_local $43)
+ (get_local $49)
+ (get_local $44)
(get_local $0)
)
)
@@ -8083,7 +8081,7 @@
)
)
(call $___fwritex
- (get_local $47)
+ (get_local $48)
(get_local $7)
(get_local $0)
)
@@ -17674,14 +17672,11 @@
(get_local $5)
)
)
- (set_local $1
- (get_global $tempRet0)
- )
(set_global $STACKTOP
(get_local $6)
)
(set_global $tempRet0
- (get_local $1)
+ (get_global $tempRet0)
)
(get_local $0)
)
diff --git a/test/unit.asm.js b/test/unit.asm.js
index a25e60721..2435c0938 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -347,6 +347,19 @@ function asm(global, env, buffer) {
function w() {
}
+ function globalOpts() {
+ var x = 0, y = +0;
+ x = Int;
+ y = Double;
+ HEAP8[13] = HEAP32[3]; // access memory, should not confuse the global writes
+ Double = y;
+ Int = x;
+ globalOpts();
+ x = Int;
+ if (1) Int = 20;
+ Int = x;
+ }
+
var FUNCTION_TABLE_a = [ z, big_negative, z, z ];
var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ];
var FUNCTION_TABLE_c = [ z, cneg ];
diff --git a/test/unit.fromasm b/test/unit.fromasm
index bafc17f3f..578385db3 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -682,4 +682,32 @@
)
)
)
+ (func $globalOpts
+ (local $0 i32)
+ (i32.store8
+ (i32.const 13)
+ (i32.load
+ (i32.const 12)
+ )
+ )
+ (set_global $Double
+ (get_global $Double)
+ )
+ (set_global $Int
+ (get_global $Int)
+ )
+ (call $globalOpts)
+ (set_local $0
+ (get_global $Int)
+ )
+ (if
+ (i32.const 1)
+ (set_global $Int
+ (i32.const 20)
+ )
+ )
+ (set_global $Int
+ (get_local $0)
+ )
+ )
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index cdaca7e10..1f303aef6 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -663,4 +663,32 @@
)
)
)
+ (func $globalOpts
+ (local $0 i32)
+ (i32.store8
+ (i32.const 13)
+ (i32.load
+ (i32.const 12)
+ )
+ )
+ (set_global $Double
+ (get_global $Double)
+ )
+ (set_global $Int
+ (get_global $Int)
+ )
+ (call $globalOpts)
+ (set_local $0
+ (get_global $Int)
+ )
+ (if
+ (i32.const 1)
+ (set_global $Int
+ (i32.const 20)
+ )
+ )
+ (set_global $Int
+ (get_local $0)
+ )
+ )
)
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index 244ef7cd8..b4add4ad7 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -1097,4 +1097,39 @@
(func $w
(nop)
)
+ (func $globalOpts
+ (local $x i32)
+ (local $y f64)
+ (set_local $x
+ (get_global $Int)
+ )
+ (set_local $y
+ (get_global $Double)
+ )
+ (i32.store8
+ (i32.const 13)
+ (i32.load
+ (i32.const 12)
+ )
+ )
+ (set_global $Double
+ (get_local $y)
+ )
+ (set_global $Int
+ (get_local $x)
+ )
+ (call $globalOpts)
+ (set_local $x
+ (get_global $Int)
+ )
+ (if
+ (i32.const 1)
+ (set_global $Int
+ (i32.const 20)
+ )
+ )
+ (set_global $Int
+ (get_local $x)
+ )
+ )
)
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index 1c0e87f6a..56436ab7f 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -1103,4 +1103,39 @@
(func $w
(nop)
)
+ (func $globalOpts
+ (local $x i32)
+ (local $y f64)
+ (set_local $x
+ (get_global $Int)
+ )
+ (set_local $y
+ (get_global $Double)
+ )
+ (i32.store8
+ (i32.const 13)
+ (i32.load
+ (i32.const 12)
+ )
+ )
+ (set_global $Double
+ (get_local $y)
+ )
+ (set_global $Int
+ (get_local $x)
+ )
+ (call $globalOpts)
+ (set_local $x
+ (get_global $Int)
+ )
+ (if
+ (i32.const 1)
+ (set_global $Int
+ (i32.const 20)
+ )
+ )
+ (set_global $Int
+ (get_local $x)
+ )
+ )
)