summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast_utils.h2
-rw-r--r--test/emcc_O2_hello_world.fromasm206
-rw-r--r--test/emcc_O2_hello_world.fromasm.imprecise206
-rw-r--r--test/passes/vacuum.txt24
-rw-r--r--test/passes/vacuum.wast25
5 files changed, 304 insertions, 159 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index 07db4806b..730ef35a6 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -202,8 +202,8 @@ struct ExpressionAnalyzer {
// continue down
} else if (curr->is<If>()) {
auto* iff = curr->cast<If>();
- if (!iff->ifFalse) return false;
if (above == iff->condition) return true;
+ if (!iff->ifFalse) return false;
assert(above == iff->ifTrue || above == iff->ifFalse);
// continue down
} else {
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index e40f7bb6d..7f2c87803 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -579,7 +579,7 @@
(set_local $39
(get_local $18)
)
- (set_local $30
+ (set_local $31
(get_local $9)
)
)
@@ -598,7 +598,7 @@
(i32.const 8)
)
)
- (set_local $30
+ (set_local $31
(get_local $10)
)
)
@@ -608,12 +608,12 @@
(get_local $1)
)
(i32.store offset=12
- (get_local $30)
+ (get_local $31)
(get_local $1)
)
(i32.store offset=8
(get_local $1)
- (get_local $30)
+ (get_local $31)
)
(i32.store offset=12
(get_local $1)
@@ -1298,7 +1298,7 @@
(set_local $40
(get_local $8)
)
- (set_local $31
+ (set_local $32
(get_local $19)
)
)
@@ -1317,7 +1317,7 @@
(i32.const 8)
)
)
- (set_local $31
+ (set_local $32
(get_local $1)
)
)
@@ -1327,12 +1327,12 @@
(get_local $2)
)
(i32.store offset=12
- (get_local $31)
+ (get_local $32)
(get_local $2)
)
(i32.store offset=8
(get_local $2)
- (get_local $31)
+ (get_local $32)
)
(i32.store offset=12
(get_local $2)
@@ -1555,13 +1555,13 @@
(get_local $2)
)
(block
- (set_local $26
+ (set_local $27
(get_local $4)
)
(set_local $25
(get_local $19)
)
- (set_local $29
+ (set_local $30
(get_local $19)
)
(set_local $8
@@ -1626,13 +1626,13 @@
)
)
(block
- (set_local $32
+ (set_local $33
(get_local $5)
)
- (set_local $33
+ (set_local $34
(get_local $18)
)
- (set_local $28
+ (set_local $29
(get_local $6)
)
(set_local $8
@@ -1665,13 +1665,13 @@
)
)
(block
- (set_local $32
+ (set_local $33
(get_local $15)
)
- (set_local $33
+ (set_local $34
(i32.const 0)
)
- (set_local $28
+ (set_local $29
(i32.const 0)
)
(set_local $8
@@ -1690,11 +1690,11 @@
(if
(i32.and
(i32.eq
- (get_local $33)
+ (get_local $34)
(i32.const 0)
)
(i32.eq
- (get_local $28)
+ (get_local $29)
(i32.const 0)
)
)
@@ -1823,18 +1823,18 @@
)
)
)
- (get_local $33)
+ (get_local $34)
)
)
(block
- (set_local $26
- (get_local $32)
+ (set_local $27
+ (get_local $33)
)
(set_local $25
(get_local $0)
)
- (set_local $29
- (get_local $28)
+ (set_local $30
+ (get_local $29)
)
(set_local $8
(i32.const 90)
@@ -1842,10 +1842,10 @@
)
(block
(set_local $7
- (get_local $32)
+ (get_local $33)
)
(set_local $12
- (get_local $28)
+ (get_local $29)
)
)
)
@@ -1872,20 +1872,20 @@
(get_local $2)
)
)
- (get_local $26)
+ (get_local $27)
)
)
(set_local $4
(select
(get_local $6)
- (get_local $26)
+ (get_local $27)
(get_local $1)
)
)
(set_local $6
(select
(get_local $25)
- (get_local $29)
+ (get_local $30)
(get_local $1)
)
)
@@ -1896,13 +1896,13 @@
)
)
(block
- (set_local $26
+ (set_local $27
(get_local $4)
)
(set_local $25
(get_local $1)
)
- (set_local $29
+ (set_local $30
(get_local $6)
)
(br $while-in$20)
@@ -1915,10 +1915,10 @@
)
)
(block
- (set_local $26
+ (set_local $27
(get_local $4)
)
- (set_local $29
+ (set_local $30
(get_local $6)
)
)
@@ -2401,7 +2401,7 @@
(set_local $14
(get_local $4)
)
- (set_local $34
+ (set_local $26
(get_local $5)
)
)
@@ -2420,7 +2420,7 @@
(i32.const 8)
)
)
- (set_local $34
+ (set_local $26
(get_local $10)
)
)
@@ -2430,12 +2430,12 @@
(get_local $6)
)
(i32.store offset=12
- (get_local $34)
+ (get_local $26)
(get_local $6)
)
(i32.store offset=8
(get_local $6)
- (get_local $34)
+ (get_local $26)
)
(i32.store offset=12
(get_local $6)
@@ -3103,16 +3103,31 @@
(if
(if
(i32.ne
- (i32.load
- (i32.const 616)
+ (set_local $9
+ (i32.load
+ (i32.const 616)
+ )
)
(i32.const 0)
)
- (i32.add
- (i32.load
- (i32.const 608)
+ (i32.or
+ (i32.le_u
+ (set_local $14
+ (i32.add
+ (set_local $26
+ (i32.load
+ (i32.const 608)
+ )
+ )
+ (get_local $7)
+ )
+ )
+ (get_local $26)
+ )
+ (i32.gt_u
+ (get_local $14)
+ (get_local $9)
)
- (get_local $7)
)
(i32.const 0)
)
@@ -3156,18 +3171,26 @@
(if
(if
(i32.le_u
- (i32.load
- (get_local $14)
+ (set_local $26
+ (i32.load
+ (get_local $14)
+ )
)
(get_local $9)
)
- (i32.load
- (set_local $11
- (i32.add
- (get_local $14)
- (i32.const 4)
+ (i32.gt_u
+ (i32.add
+ (get_local $26)
+ (i32.load
+ (set_local $11
+ (i32.add
+ (get_local $14)
+ (i32.const 4)
+ )
+ )
)
)
+ (get_local $9)
)
(i32.const 0)
)
@@ -3272,10 +3295,13 @@
(get_local $8)
(i32.const 173)
)
- (set_local $9
- (call_import $_sbrk
- (i32.const 0)
+ (i32.ne
+ (set_local $9
+ (call_import $_sbrk
+ (i32.const 0)
+ )
)
+ (i32.const -1)
)
(i32.const 0)
)
@@ -3540,10 +3566,16 @@
)
(i32.const 0)
)
- (set_local $13
- (i32.sub
- (get_local $7)
- (get_local $3)
+ (i32.gt_u
+ (set_local $13
+ (i32.sub
+ (get_local $7)
+ (get_local $3)
+ )
+ )
+ (i32.add
+ (get_local $0)
+ (i32.const 40)
)
)
(i32.const 0)
@@ -3820,7 +3852,7 @@
)
)
(block
- (set_local $27
+ (set_local $28
(i32.const 624)
)
(br $while-out$48)
@@ -3840,7 +3872,7 @@
)
(i32.const 8)
)
- (set_local $27
+ (set_local $28
(i32.const 624)
)
(block
@@ -5027,18 +5059,21 @@
(i32.le_u
(set_local $3
(i32.load
- (get_local $27)
+ (get_local $28)
)
)
(get_local $13)
)
- (set_local $16
- (i32.add
- (get_local $3)
- (i32.load offset=4
- (get_local $27)
+ (i32.gt_u
+ (set_local $16
+ (i32.add
+ (get_local $3)
+ (i32.load offset=4
+ (get_local $28)
+ )
)
)
+ (get_local $13)
)
(i32.const 0)
)
@@ -5049,9 +5084,9 @@
(br $while-out$71)
)
)
- (set_local $27
+ (set_local $28
(i32.load offset=8
- (get_local $27)
+ (get_local $28)
)
)
(br $while-in$72)
@@ -8815,10 +8850,15 @@
)
(get_local $7)
)
- (set_local $10
- (i32.and
- (get_local $1)
- (i32.const 255)
+ (i32.ne
+ (set_local $10
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
+ )
+ )
+ (i32.load8_s offset=75
+ (get_local $0)
)
)
(i32.const 0)
@@ -9317,15 +9357,20 @@
)
(i32.const 10)
)
- (set_local $2
- (i32.load
- (set_local $4
- (i32.add
- (get_local $1)
- (i32.const 20)
+ (i32.lt_u
+ (set_local $2
+ (i32.load
+ (set_local $4
+ (i32.add
+ (get_local $1)
+ (i32.const 20)
+ )
)
)
)
+ (i32.load offset=16
+ (get_local $1)
+ )
)
(i32.const 0)
)
@@ -9637,9 +9682,12 @@
(i32.const 12)
)
)
- (call_import $___syscall54
- (i32.const 54)
- (get_local $3)
+ (i32.ne
+ (call_import $___syscall54
+ (i32.const 54)
+ (get_local $3)
+ )
+ (i32.const 0)
)
)
(i32.const 0)
diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise
index e40f7bb6d..7f2c87803 100644
--- a/test/emcc_O2_hello_world.fromasm.imprecise
+++ b/test/emcc_O2_hello_world.fromasm.imprecise
@@ -579,7 +579,7 @@
(set_local $39
(get_local $18)
)
- (set_local $30
+ (set_local $31
(get_local $9)
)
)
@@ -598,7 +598,7 @@
(i32.const 8)
)
)
- (set_local $30
+ (set_local $31
(get_local $10)
)
)
@@ -608,12 +608,12 @@
(get_local $1)
)
(i32.store offset=12
- (get_local $30)
+ (get_local $31)
(get_local $1)
)
(i32.store offset=8
(get_local $1)
- (get_local $30)
+ (get_local $31)
)
(i32.store offset=12
(get_local $1)
@@ -1298,7 +1298,7 @@
(set_local $40
(get_local $8)
)
- (set_local $31
+ (set_local $32
(get_local $19)
)
)
@@ -1317,7 +1317,7 @@
(i32.const 8)
)
)
- (set_local $31
+ (set_local $32
(get_local $1)
)
)
@@ -1327,12 +1327,12 @@
(get_local $2)
)
(i32.store offset=12
- (get_local $31)
+ (get_local $32)
(get_local $2)
)
(i32.store offset=8
(get_local $2)
- (get_local $31)
+ (get_local $32)
)
(i32.store offset=12
(get_local $2)
@@ -1555,13 +1555,13 @@
(get_local $2)
)
(block
- (set_local $26
+ (set_local $27
(get_local $4)
)
(set_local $25
(get_local $19)
)
- (set_local $29
+ (set_local $30
(get_local $19)
)
(set_local $8
@@ -1626,13 +1626,13 @@
)
)
(block
- (set_local $32
+ (set_local $33
(get_local $5)
)
- (set_local $33
+ (set_local $34
(get_local $18)
)
- (set_local $28
+ (set_local $29
(get_local $6)
)
(set_local $8
@@ -1665,13 +1665,13 @@
)
)
(block
- (set_local $32
+ (set_local $33
(get_local $15)
)
- (set_local $33
+ (set_local $34
(i32.const 0)
)
- (set_local $28
+ (set_local $29
(i32.const 0)
)
(set_local $8
@@ -1690,11 +1690,11 @@
(if
(i32.and
(i32.eq
- (get_local $33)
+ (get_local $34)
(i32.const 0)
)
(i32.eq
- (get_local $28)
+ (get_local $29)
(i32.const 0)
)
)
@@ -1823,18 +1823,18 @@
)
)
)
- (get_local $33)
+ (get_local $34)
)
)
(block
- (set_local $26
- (get_local $32)
+ (set_local $27
+ (get_local $33)
)
(set_local $25
(get_local $0)
)
- (set_local $29
- (get_local $28)
+ (set_local $30
+ (get_local $29)
)
(set_local $8
(i32.const 90)
@@ -1842,10 +1842,10 @@
)
(block
(set_local $7
- (get_local $32)
+ (get_local $33)
)
(set_local $12
- (get_local $28)
+ (get_local $29)
)
)
)
@@ -1872,20 +1872,20 @@
(get_local $2)
)
)
- (get_local $26)
+ (get_local $27)
)
)
(set_local $4
(select
(get_local $6)
- (get_local $26)
+ (get_local $27)
(get_local $1)
)
)
(set_local $6
(select
(get_local $25)
- (get_local $29)
+ (get_local $30)
(get_local $1)
)
)
@@ -1896,13 +1896,13 @@
)
)
(block
- (set_local $26
+ (set_local $27
(get_local $4)
)
(set_local $25
(get_local $1)
)
- (set_local $29
+ (set_local $30
(get_local $6)
)
(br $while-in$20)
@@ -1915,10 +1915,10 @@
)
)
(block
- (set_local $26
+ (set_local $27
(get_local $4)
)
- (set_local $29
+ (set_local $30
(get_local $6)
)
)
@@ -2401,7 +2401,7 @@
(set_local $14
(get_local $4)
)
- (set_local $34
+ (set_local $26
(get_local $5)
)
)
@@ -2420,7 +2420,7 @@
(i32.const 8)
)
)
- (set_local $34
+ (set_local $26
(get_local $10)
)
)
@@ -2430,12 +2430,12 @@
(get_local $6)
)
(i32.store offset=12
- (get_local $34)
+ (get_local $26)
(get_local $6)
)
(i32.store offset=8
(get_local $6)
- (get_local $34)
+ (get_local $26)
)
(i32.store offset=12
(get_local $6)
@@ -3103,16 +3103,31 @@
(if
(if
(i32.ne
- (i32.load
- (i32.const 616)
+ (set_local $9
+ (i32.load
+ (i32.const 616)
+ )
)
(i32.const 0)
)
- (i32.add
- (i32.load
- (i32.const 608)
+ (i32.or
+ (i32.le_u
+ (set_local $14
+ (i32.add
+ (set_local $26
+ (i32.load
+ (i32.const 608)
+ )
+ )
+ (get_local $7)
+ )
+ )
+ (get_local $26)
+ )
+ (i32.gt_u
+ (get_local $14)
+ (get_local $9)
)
- (get_local $7)
)
(i32.const 0)
)
@@ -3156,18 +3171,26 @@
(if
(if
(i32.le_u
- (i32.load
- (get_local $14)
+ (set_local $26
+ (i32.load
+ (get_local $14)
+ )
)
(get_local $9)
)
- (i32.load
- (set_local $11
- (i32.add
- (get_local $14)
- (i32.const 4)
+ (i32.gt_u
+ (i32.add
+ (get_local $26)
+ (i32.load
+ (set_local $11
+ (i32.add
+ (get_local $14)
+ (i32.const 4)
+ )
+ )
)
)
+ (get_local $9)
)
(i32.const 0)
)
@@ -3272,10 +3295,13 @@
(get_local $8)
(i32.const 173)
)
- (set_local $9
- (call_import $_sbrk
- (i32.const 0)
+ (i32.ne
+ (set_local $9
+ (call_import $_sbrk
+ (i32.const 0)
+ )
)
+ (i32.const -1)
)
(i32.const 0)
)
@@ -3540,10 +3566,16 @@
)
(i32.const 0)
)
- (set_local $13
- (i32.sub
- (get_local $7)
- (get_local $3)
+ (i32.gt_u
+ (set_local $13
+ (i32.sub
+ (get_local $7)
+ (get_local $3)
+ )
+ )
+ (i32.add
+ (get_local $0)
+ (i32.const 40)
)
)
(i32.const 0)
@@ -3820,7 +3852,7 @@
)
)
(block
- (set_local $27
+ (set_local $28
(i32.const 624)
)
(br $while-out$48)
@@ -3840,7 +3872,7 @@
)
(i32.const 8)
)
- (set_local $27
+ (set_local $28
(i32.const 624)
)
(block
@@ -5027,18 +5059,21 @@
(i32.le_u
(set_local $3
(i32.load
- (get_local $27)
+ (get_local $28)
)
)
(get_local $13)
)
- (set_local $16
- (i32.add
- (get_local $3)
- (i32.load offset=4
- (get_local $27)
+ (i32.gt_u
+ (set_local $16
+ (i32.add
+ (get_local $3)
+ (i32.load offset=4
+ (get_local $28)
+ )
)
)
+ (get_local $13)
)
(i32.const 0)
)
@@ -5049,9 +5084,9 @@
(br $while-out$71)
)
)
- (set_local $27
+ (set_local $28
(i32.load offset=8
- (get_local $27)
+ (get_local $28)
)
)
(br $while-in$72)
@@ -8815,10 +8850,15 @@
)
(get_local $7)
)
- (set_local $10
- (i32.and
- (get_local $1)
- (i32.const 255)
+ (i32.ne
+ (set_local $10
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
+ )
+ )
+ (i32.load8_s offset=75
+ (get_local $0)
)
)
(i32.const 0)
@@ -9317,15 +9357,20 @@
)
(i32.const 10)
)
- (set_local $2
- (i32.load
- (set_local $4
- (i32.add
- (get_local $1)
- (i32.const 20)
+ (i32.lt_u
+ (set_local $2
+ (i32.load
+ (set_local $4
+ (i32.add
+ (get_local $1)
+ (i32.const 20)
+ )
)
)
)
+ (i32.load offset=16
+ (get_local $1)
+ )
)
(i32.const 0)
)
@@ -9637,9 +9682,12 @@
(i32.const 12)
)
)
- (call_import $___syscall54
- (i32.const 54)
- (get_local $3)
+ (i32.ne
+ (call_import $___syscall54
+ (i32.const 54)
+ (get_local $3)
+ )
+ (i32.const 0)
)
)
(i32.const 0)
diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt
index 75737713b..2fd45cbc0 100644
--- a/test/passes/vacuum.txt
+++ b/test/passes/vacuum.txt
@@ -97,4 +97,28 @@
(func $func-block
(nop)
)
+ (func $Gu (param $b i32) (param $e f64) (param $l i32) (param $d i32)
+ (if
+ (if
+ (get_local $d)
+ (block $block1
+ (f64.ne
+ (f64.promote/f32
+ (f32.load
+ (set_local $l
+ (i32.add
+ (get_local $b)
+ (i32.const 60)
+ )
+ )
+ )
+ )
+ (get_local $e)
+ )
+ )
+ (i32.const 0)
+ )
+ (unreachable)
+ )
+ )
)
diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast
index fb6125e52..a6f713123 100644
--- a/test/passes/vacuum.wast
+++ b/test/passes/vacuum.wast
@@ -124,5 +124,30 @@
(func $func-block
(f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.const 1.0) ) ) ) ) ) )
)
+ (func $Gu (param $b i32) (param $e f64) (param $l i32) (param $d i32)
+ (if ;; if condition must remain valid
+ (if
+ (get_local $d)
+ (block
+ (nop)
+ (f64.ne
+ (f64.promote/f32
+ (f32.load
+ (set_local $l
+ (i32.add
+ (get_local $b)
+ (i32.const 60)
+ )
+ )
+ )
+ )
+ (get_local $e)
+ )
+ )
+ (i32.const 0)
+ )
+ (unreachable)
+ )
+ )
)