summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-12-03 16:12:40 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-12-07 16:50:05 -1000
commit8ce6594dc19cb3203267d1f5e8f335f0ee5a450e (patch)
tree16356346412c69b459690a2ca760d1b400a5e50f
parent92fb30a71c901c08bf676215efa0103cf23bcab8 (diff)
downloadbinaryen-8ce6594dc19cb3203267d1f5e8f335f0ee5a450e.tar.gz
binaryen-8ce6594dc19cb3203267d1f5e8f335f0ee5a450e.tar.bz2
binaryen-8ce6594dc19cb3203267d1f5e8f335f0ee5a450e.zip
fix legalization issues with f32s
-rw-r--r--src/passes/LegalizeJSInterface.cpp4
-rw-r--r--test/wasm-only.asm.js8
-rw-r--r--test/wasm-only.fromasm17
-rw-r--r--test/wasm-only.fromasm.imprecise17
-rw-r--r--test/wasm-only.fromasm.imprecise.no-opts24
-rw-r--r--test/wasm-only.fromasm.no-opts24
6 files changed, 83 insertions, 11 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp
index 1c2685b10..c9cada3c0 100644
--- a/src/passes/LegalizeJSInterface.cpp
+++ b/src/passes/LegalizeJSInterface.cpp
@@ -180,7 +180,7 @@ private:
type->params.push_back(i32);
type->params.push_back(i32);
} else if (param == f32) {
- call->operands.push_back(builder.makeUnary(PromoteFloat32, builder.makeGetLocal(func->params.size(), f64)));
+ call->operands.push_back(builder.makeUnary(PromoteFloat32, builder.makeGetLocal(func->params.size(), f32)));
type->params.push_back(f64);
} else {
call->operands.push_back(builder.makeGetLocal(func->params.size(), param));
@@ -198,7 +198,7 @@ private:
type->result = i32;
} else if (im->functionType->result == f32) {
call->type = f64;
- func->body = builder.makeUnary(PromoteFloat32, call);
+ func->body = builder.makeUnary(DemoteFloat64, call);
type->result = f64;
} else {
call->type = im->functionType->result;
diff --git a/test/wasm-only.asm.js b/test/wasm-only.asm.js
index e4ec8b5f7..eb18fce03 100644
--- a/test/wasm-only.asm.js
+++ b/test/wasm-only.asm.js
@@ -21,6 +21,8 @@ function asm(global, env, buffer) {
var illegalImport = env.illegalImport;
var illegalImportResult = env.illegalImportResult;
+ var _fabsf = env._fabsf;
+
function loads() {
var i = 0, f = fround(0), d = +0;
i = load1(100);
@@ -237,7 +239,11 @@ function asm(global, env, buffer) {
switch64(i64(0)) | 0;
}
- var FUNCTION_TABLE_X = [illegalImport]; // must stay ok in the table, not legalized, as it will be called internally by the true type
+ function __emscripten_dceable_type_decls() { // dce-able, but this defines the type of fabsf which has no other use
+ fround(_fabsf(fround(0.0)));
+ }
+
+ var FUNCTION_TABLE_X = [illegalImport, _fabsf]; // must stay ok in the table, not legalized, as it will be called internally by the true type
return { test64: test64, illegalParam : illegalParam, illegalResult: illegalResult, keepAlive: keepAlive };
}
diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm
index b36cc536c..30793df2c 100644
--- a/test/wasm-only.fromasm
+++ b/test/wasm-only.fromasm
@@ -1,17 +1,21 @@
(module
(type $FUNCSIG$vdji (func (param f64 i64 i32)))
(type $FUNCSIG$j (func (result i64)))
+ (type $FUNCSIG$ff (func (param f32) (result f32)))
(type $legaltype$illegalImport (func (param f64 i32 i32 i32)))
(type $legaltype$illegalImportResult (func (result i32)))
+ (type $legaltype$_fabsf (func (param f64) (result f64)))
(import "env" "illegalImport" (func $illegalImport (param f64 i64 i32)))
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
+ (import "env" "_fabsf" (func $_fabsf (param f32) (result f32)))
(import "env" "illegalImport" (func $legalimport$illegalImport (param f64 i32 i32 i32)))
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
+ (import "env" "_fabsf" (func $legalimport$_fabsf (param f64) (result f64)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 1 1 anyfunc))
+ (import "env" "table" (table 2 2 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (get_global $tableBase) $illegalImport)
+ (elem (get_global $tableBase) $illegalImport $_fabsf)
(data (get_global $memoryBase) "wasm-only.asm.js")
(global $tempRet0 (mut i32) (i32.const 0))
(export "test64" (func $test64))
@@ -439,4 +443,13 @@
)
)
)
+ (func $legalfunc$_fabsf (param $0 f32) (result f32)
+ (f32.demote/f64
+ (call $legalimport$_fabsf
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
)
diff --git a/test/wasm-only.fromasm.imprecise b/test/wasm-only.fromasm.imprecise
index b7cc3a482..c65c70ada 100644
--- a/test/wasm-only.fromasm.imprecise
+++ b/test/wasm-only.fromasm.imprecise
@@ -1,17 +1,21 @@
(module
(type $FUNCSIG$vdji (func (param f64 i64 i32)))
(type $FUNCSIG$j (func (result i64)))
+ (type $FUNCSIG$ff (func (param f32) (result f32)))
(type $legaltype$illegalImport (func (param f64 i32 i32 i32)))
(type $legaltype$illegalImportResult (func (result i32)))
+ (type $legaltype$_fabsf (func (param f64) (result f64)))
(import "env" "illegalImport" (func $illegalImport (param f64 i64 i32)))
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
+ (import "env" "_fabsf" (func $_fabsf (param f32) (result f32)))
(import "env" "illegalImport" (func $legalimport$illegalImport (param f64 i32 i32 i32)))
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
+ (import "env" "_fabsf" (func $legalimport$_fabsf (param f64) (result f64)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 1 1 anyfunc))
+ (import "env" "table" (table 2 2 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (get_global $tableBase) $illegalImport)
+ (elem (get_global $tableBase) $illegalImport $_fabsf)
(global $tempRet0 (mut i32) (i32.const 0))
(export "test64" (func $test64))
(export "illegalParam" (func $legalstub$illegalParam))
@@ -367,4 +371,13 @@
)
)
)
+ (func $legalfunc$_fabsf (param $0 f32) (result f32)
+ (f32.demote/f64
+ (call $legalimport$_fabsf
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
)
diff --git a/test/wasm-only.fromasm.imprecise.no-opts b/test/wasm-only.fromasm.imprecise.no-opts
index 542b0cad2..9311971fb 100644
--- a/test/wasm-only.fromasm.imprecise.no-opts
+++ b/test/wasm-only.fromasm.imprecise.no-opts
@@ -1,17 +1,21 @@
(module
(type $FUNCSIG$vdji (func (param f64 i64 i32)))
(type $FUNCSIG$j (func (result i64)))
+ (type $FUNCSIG$ff (func (param f32) (result f32)))
(type $legaltype$illegalImport (func (param f64 i32 i32 i32)))
(type $legaltype$illegalImportResult (func (result i32)))
+ (type $legaltype$_fabsf (func (param f64) (result f64)))
(import "env" "illegalImport" (func $illegalImport (param f64 i64 i32)))
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
+ (import "env" "_fabsf" (func $_fabsf (param f32) (result f32)))
(import "env" "illegalImport" (func $legalimport$illegalImport (param f64 i32 i32 i32)))
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
+ (import "env" "_fabsf" (func $legalimport$_fabsf (param f64) (result f64)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 1 1 anyfunc))
+ (import "env" "table" (table 2 2 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (get_global $tableBase) $illegalImport)
+ (elem (get_global $tableBase) $illegalImport $_fabsf)
(global $tempRet0 (mut i32) (i32.const 0))
(export "test64" (func $test64))
(export "illegalParam" (func $legalstub$illegalParam))
@@ -755,6 +759,13 @@
)
)
)
+ (func $__emscripten_dceable_type_decls
+ (drop
+ (call $legalfunc$_fabsf
+ (f32.const 0)
+ )
+ )
+ )
(func $legalstub$illegalParam (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64)
(call $illegalParam
(get_local $0)
@@ -817,4 +828,13 @@
)
)
)
+ (func $legalfunc$_fabsf (param $0 f32) (result f32)
+ (f32.demote/f64
+ (call $legalimport$_fabsf
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
)
diff --git a/test/wasm-only.fromasm.no-opts b/test/wasm-only.fromasm.no-opts
index 1f0760e6b..54d39cd0a 100644
--- a/test/wasm-only.fromasm.no-opts
+++ b/test/wasm-only.fromasm.no-opts
@@ -1,17 +1,21 @@
(module
(type $FUNCSIG$vdji (func (param f64 i64 i32)))
(type $FUNCSIG$j (func (result i64)))
+ (type $FUNCSIG$ff (func (param f32) (result f32)))
(type $legaltype$illegalImport (func (param f64 i32 i32 i32)))
(type $legaltype$illegalImportResult (func (result i32)))
+ (type $legaltype$_fabsf (func (param f64) (result f64)))
(import "env" "illegalImport" (func $illegalImport (param f64 i64 i32)))
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
+ (import "env" "_fabsf" (func $_fabsf (param f32) (result f32)))
(import "env" "illegalImport" (func $legalimport$illegalImport (param f64 i32 i32 i32)))
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
+ (import "env" "_fabsf" (func $legalimport$_fabsf (param f64) (result f64)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 1 1 anyfunc))
+ (import "env" "table" (table 2 2 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (get_global $tableBase) $illegalImport)
+ (elem (get_global $tableBase) $illegalImport $_fabsf)
(global $tempRet0 (mut i32) (i32.const 0))
(export "test64" (func $test64))
(export "illegalParam" (func $legalstub$illegalParam))
@@ -803,6 +807,13 @@
)
)
)
+ (func $__emscripten_dceable_type_decls
+ (drop
+ (call $legalfunc$_fabsf
+ (f32.const 0)
+ )
+ )
+ )
(func $legalstub$illegalParam (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64)
(call $illegalParam
(get_local $0)
@@ -865,4 +876,13 @@
)
)
)
+ (func $legalfunc$_fabsf (param $0 f32) (result f32)
+ (f32.demote/f64
+ (call $legalimport$_fabsf
+ (f64.promote/f32
+ (get_local $0)
+ )
+ )
+ )
+ )
)