diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-09-27 13:08:24 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2017-09-27 13:08:24 -0700 |
commit | d4f7519e64d2246be81b24b8e5fc72c8abccb759 (patch) | |
tree | fa2069220ddc7c461319846551fdc9deffe225bf | |
parent | 27af98deb91d1d64be44cdf12f01833b677fbf34 (diff) | |
download | binaryen-d4f7519e64d2246be81b24b8e5fc72c8abccb759.tar.gz binaryen-d4f7519e64d2246be81b24b8e5fc72c8abccb759.tar.bz2 binaryen-d4f7519e64d2246be81b24b8e5fc72c8abccb759.zip |
fix ExpressionAnalyzer::equals on consts, they need to be bitwise equal, i.e., 0 != -0
-rw-r--r-- | src/ast/ExpressionAnalyzer.cpp | 4 | ||||
-rw-r--r-- | test/passes/code-folding.txt | 28 | ||||
-rw-r--r-- | test/passes/code-folding.wast | 33 |
3 files changed, 64 insertions, 1 deletions
diff --git a/src/ast/ExpressionAnalyzer.cpp b/src/ast/ExpressionAnalyzer.cpp index 8a372c2db..3556fcdd5 100644 --- a/src/ast/ExpressionAnalyzer.cpp +++ b/src/ast/ExpressionAnalyzer.cpp @@ -252,7 +252,9 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, Expression* right, Expr break; } case Expression::Id::ConstId: { - CHECK(Const, value); + if (!left->cast<Const>()->value.bitwiseEqual(right->cast<Const>()->value)) { + return false; + } break; } case Expression::Id::UnaryId: { diff --git a/test/passes/code-folding.txt b/test/passes/code-folding.txt index 9143b9615..a3c3f664c 100644 --- a/test/passes/code-folding.txt +++ b/test/passes/code-folding.txt @@ -1,6 +1,7 @@ (module (type $13 (func (param f32))) (type $1 (func)) + (type $2 (func (result f32))) (table 282 282 anyfunc) (memory $0 1 1) (func $0 (type $1) @@ -21,4 +22,31 @@ ) ) ) + (func $negative-zero (type $2) (result f32) + (if (result f32) + (i32.const 0) + (block $label$0 (result f32) + (f32.const 0) + ) + (block $label$1 (result f32) + (f32.const -0) + ) + ) + ) + (func $negative-zero-b (type $2) (result f32) + (drop + (i32.const 0) + ) + (block $label$0 (result f32) + (f32.const -0) + ) + ) + (func $negative-zero-c (type $2) (result f32) + (drop + (i32.const 0) + ) + (block $label$0 (result f32) + (f32.const 0) + ) + ) ) diff --git a/test/passes/code-folding.wast b/test/passes/code-folding.wast index 2310f9721..ca1768c16 100644 --- a/test/passes/code-folding.wast +++ b/test/passes/code-folding.wast @@ -19,5 +19,38 @@ ) ) ) + (func $negative-zero (result f32) + (if (result f32) + (i32.const 0) + (block $label$0 (result f32) + (f32.const 0) + ) + (block $label$1 (result f32) + (f32.const -0) + ) + ) + ) + (func $negative-zero-b (result f32) + (if (result f32) + (i32.const 0) + (block $label$0 (result f32) + (f32.const -0) + ) + (block $label$1 (result f32) + (f32.const -0) + ) + ) + ) + (func $negative-zero-c (result f32) + (if (result f32) + (i32.const 0) + (block $label$0 (result f32) + (f32.const 0) + ) + (block $label$1 (result f32) + (f32.const 0) + ) + ) + ) ) |