Skip to content

Commit d4f7519

Browse files
committed
fix ExpressionAnalyzer::equals on consts, they need to be bitwise equal, i.e., 0 != -0
1 parent 27af98d commit d4f7519

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/ast/ExpressionAnalyzer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, Expression* right, Expr
252252
break;
253253
}
254254
case Expression::Id::ConstId: {
255-
CHECK(Const, value);
255+
if (!left->cast<Const>()->value.bitwiseEqual(right->cast<Const>()->value)) {
256+
return false;
257+
}
256258
break;
257259
}
258260
case Expression::Id::UnaryId: {

test/passes/code-folding.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(module
22
(type $13 (func (param f32)))
33
(type $1 (func))
4+
(type $2 (func (result f32)))
45
(table 282 282 anyfunc)
56
(memory $0 1 1)
67
(func $0 (type $1)
@@ -21,4 +22,31 @@
2122
)
2223
)
2324
)
25+
(func $negative-zero (type $2) (result f32)
26+
(if (result f32)
27+
(i32.const 0)
28+
(block $label$0 (result f32)
29+
(f32.const 0)
30+
)
31+
(block $label$1 (result f32)
32+
(f32.const -0)
33+
)
34+
)
35+
)
36+
(func $negative-zero-b (type $2) (result f32)
37+
(drop
38+
(i32.const 0)
39+
)
40+
(block $label$0 (result f32)
41+
(f32.const -0)
42+
)
43+
)
44+
(func $negative-zero-c (type $2) (result f32)
45+
(drop
46+
(i32.const 0)
47+
)
48+
(block $label$0 (result f32)
49+
(f32.const 0)
50+
)
51+
)
2452
)

test/passes/code-folding.wast

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,38 @@
1919
)
2020
)
2121
)
22+
(func $negative-zero (result f32)
23+
(if (result f32)
24+
(i32.const 0)
25+
(block $label$0 (result f32)
26+
(f32.const 0)
27+
)
28+
(block $label$1 (result f32)
29+
(f32.const -0)
30+
)
31+
)
32+
)
33+
(func $negative-zero-b (result f32)
34+
(if (result f32)
35+
(i32.const 0)
36+
(block $label$0 (result f32)
37+
(f32.const -0)
38+
)
39+
(block $label$1 (result f32)
40+
(f32.const -0)
41+
)
42+
)
43+
)
44+
(func $negative-zero-c (result f32)
45+
(if (result f32)
46+
(i32.const 0)
47+
(block $label$0 (result f32)
48+
(f32.const 0)
49+
)
50+
(block $label$1 (result f32)
51+
(f32.const 0)
52+
)
53+
)
54+
)
2255
)
2356

0 commit comments

Comments
 (0)