Skip to content

Commit 67c8361

Browse files
committed
Add tests for simplifying non-boolean && and ||
1 parent 3af9fd3 commit 67c8361

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

tests/compiler/logical.debug.wat

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
(global $~lib/rt/itcms/fromSpace (mut i32) (i32.const 0))
2929
(global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0))
3030
(global $~lib/native/ASC_LOW_MEMORY_LIMIT i32 (i32.const 0))
31+
(global $logical/foo (mut i32) (i32.const 456))
32+
(global $logical/bar (mut f64) (f64.const -0))
33+
(global $logical/baz (mut i32) (i32.const 321))
34+
(global $logical/qux (mut f64) (f64.const 2.718))
3135
(global $logical/b (mut i32) (i32.const 0))
3236
(global $logical/c (mut i32) (i32.const 0))
3337
(global $~lib/rt/__rtti_base i32 (i32.const 464))
@@ -47,6 +51,10 @@
4751
(data $9 (i32.const 464) "\08\00\00\00 \00\00\00 \00\00\00 \00\00\00\00\00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00")
4852
(table $0 1 1 funcref)
4953
(elem $0 (i32.const 1))
54+
(export "foo" (global $logical/foo))
55+
(export "bar" (global $logical/bar))
56+
(export "baz" (global $logical/baz))
57+
(export "qux" (global $logical/qux))
5058
(export "memory" (memory $0))
5159
(start $~start)
5260
(func $logical/testShortcutAnd (param $a i64) (param $b i32) (result i32)
@@ -2926,7 +2934,7 @@
29262934
if
29272935
i32.const 0
29282936
i32.const 32
2929-
i32.const 106
2937+
i32.const 114
29302938
i32.const 1
29312939
call $~lib/builtins/abort
29322940
unreachable
@@ -2939,7 +2947,7 @@
29392947
if
29402948
i32.const 0
29412949
i32.const 32
2942-
i32.const 107
2950+
i32.const 115
29432951
i32.const 1
29442952
call $~lib/builtins/abort
29452953
unreachable
@@ -2957,7 +2965,7 @@
29572965
if
29582966
i32.const 0
29592967
i32.const 32
2960-
i32.const 112
2968+
i32.const 120
29612969
i32.const 1
29622970
call $~lib/builtins/abort
29632971
unreachable
@@ -2970,7 +2978,7 @@
29702978
if
29712979
i32.const 0
29722980
i32.const 32
2973-
i32.const 113
2981+
i32.const 121
29742982
i32.const 1
29752983
call $~lib/builtins/abort
29762984
unreachable

tests/compiler/logical.release.wat

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
(global $~lib/rt/itcms/white (mut i32) (i32.const 0))
1818
(global $~lib/rt/itcms/fromSpace (mut i32) (i32.const 0))
1919
(global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0))
20+
(global $logical/foo (mut i32) (i32.const 456))
21+
(global $logical/bar (mut f64) (f64.const -0))
22+
(global $logical/baz (mut i32) (i32.const 321))
23+
(global $logical/qux (mut f64) (f64.const 2.718))
2024
(global $logical/b (mut i32) (i32.const 0))
2125
(global $logical/c (mut i32) (i32.const 0))
2226
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 34292))
@@ -34,6 +38,10 @@
3438
(data $8 (i32.const 1420) "<")
3539
(data $8.1 (i32.const 1432) "\02\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00t\00l\00s\00f\00.\00t\00s")
3640
(data $9 (i32.const 1488) "\08\00\00\00 \00\00\00 \00\00\00 \00\00\00\00\00\00\00 \00\00\00 \00\00\00 \00\00\00 ")
41+
(export "foo" (global $logical/foo))
42+
(export "bar" (global $logical/bar))
43+
(export "baz" (global $logical/baz))
44+
(export "qux" (global $logical/qux))
3745
(export "memory" (memory $0))
3846
(start $~start)
3947
(func $~lib/rt/itcms/visitRoots
@@ -1568,7 +1576,7 @@
15681576
if
15691577
i32.const 0
15701578
i32.const 1056
1571-
i32.const 106
1579+
i32.const 114
15721580
i32.const 1
15731581
call $~lib/builtins/abort
15741582
unreachable
@@ -1586,7 +1594,7 @@
15861594
if
15871595
i32.const 0
15881596
i32.const 1056
1589-
i32.const 112
1597+
i32.const 120
15901598
i32.const 1
15911599
call $~lib/builtins/abort
15921600
unreachable

tests/compiler/logical.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ function testContextualBoolOr(someObj: Obj, someInt: i32): bool {
9191
}
9292
assert(testContextualBoolOr(new Obj(), 0));
9393

94+
// Test simplification with precomputable LHS operands
95+
// see: https://github.com/AssemblyScript/assemblyscript/issues/2946
96+
97+
export let foo = 123 && 456;
98+
export let bar = -0.0 && 1.23;
99+
export let baz = 321 || 654;
100+
export let qux = NaN || 2.718;
101+
94102
// Common type
95103

96104
class A {}

0 commit comments

Comments
 (0)