summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/emscripten-optimizer/optimizer-shared.cpp2
-rw-r--r--test/unit.asm.js8
-rw-r--r--test/unit.fromasm14
-rw-r--r--test/unit.fromasm.clamp14
-rw-r--r--test/unit.fromasm.clamp.no-opts46
-rw-r--r--test/unit.fromasm.imprecise6
-rw-r--r--test/unit.fromasm.imprecise.no-opts46
-rw-r--r--test/unit.fromasm.no-opts46
8 files changed, 151 insertions, 31 deletions
diff --git a/src/emscripten-optimizer/optimizer-shared.cpp b/src/emscripten-optimizer/optimizer-shared.cpp
index 212aa112a..c990e2605 100644
--- a/src/emscripten-optimizer/optimizer-shared.cpp
+++ b/src/emscripten-optimizer/optimizer-shared.cpp
@@ -158,7 +158,7 @@ AsmSign detectSign(Ref node, IString minifiedFround) {
} // fallthrough
case '|': case '&': case '^': case '<': case '=': case '!': return ASM_SIGNED;
case '+': case '-': return ASM_FLEXIBLE;
- case '*': case '/': return ASM_NONSIGNED; // without a coercion, these are double
+ case '*': case '/': case '%': return ASM_NONSIGNED; // without a coercion, these are double
default: abort_on(node);
}
} else if (type == UNARY_PREFIX) {
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 82b6bdcd1..05827ce54 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -768,6 +768,13 @@ function asm(global, env, buffer) {
emscripten_log(), 2 ? abort() | 0 : 3;
}
+ function mod_detectSign(d1, d2, d8) {
+ d1 = +d1;
+ d2 = +d2;
+ d8 = +d8;
+ return ~~(d2 - d8 % d1 / d1 * d2);
+ }
+
function keepAlive() {
sqrts(3.14159);
sqrts(2.18281); // don't inline it either
@@ -777,6 +784,7 @@ function asm(global, env, buffer) {
indirectInSequence();
emterpretify_assertions_safeHeap();
call_emscripten_log();
+ mod_detectSign(1.0, 2.31, 9.78);
}
function v() {
diff --git a/test/unit.fromasm b/test/unit.fromasm
index edefbfff7..858ed8268 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -1180,6 +1180,20 @@
)
)
)
+ (drop
+ (call $f64-to-int
+ (f64.sub
+ (f64.const 2.31)
+ (f64.mul
+ (call $f64-rem
+ (f64.const 9.78)
+ (f64.const 1)
+ )
+ (f64.const 2.31)
+ )
+ )
+ )
+ )
)
(func $vi (; 55 ;) (; has Stack IR ;) (param $0 i32)
(nop)
diff --git a/test/unit.fromasm.clamp b/test/unit.fromasm.clamp
index ee2c395df..2a759ff01 100644
--- a/test/unit.fromasm.clamp
+++ b/test/unit.fromasm.clamp
@@ -1256,6 +1256,20 @@
)
)
)
+ (drop
+ (call $f64-to-int
+ (f64.sub
+ (f64.const 2.31)
+ (f64.mul
+ (call $f64-rem
+ (f64.const 9.78)
+ (f64.const 1)
+ )
+ (f64.const 2.31)
+ )
+ )
+ )
+ )
)
(func $vi (; 57 ;) (; has Stack IR ;) (param $0 i32)
(nop)
diff --git a/test/unit.fromasm.clamp.no-opts b/test/unit.fromasm.clamp.no-opts
index 55ec07e1e..76e27ee2f 100644
--- a/test/unit.fromasm.clamp.no-opts
+++ b/test/unit.fromasm.clamp.no-opts
@@ -2160,7 +2160,26 @@
)
)
)
- (func $keepAlive (; 81 ;)
+ (func $mod_detectSign (; 81 ;) (param $d1 f64) (param $d2 f64) (param $d8 f64) (result i32)
+ (return
+ (call $f64-to-int
+ (f64.sub
+ (get_local $d2)
+ (f64.mul
+ (f64.div
+ (call $f64-rem
+ (get_local $d8)
+ (get_local $d1)
+ )
+ (get_local $d1)
+ )
+ (get_local $d2)
+ )
+ )
+ )
+ )
+ )
+ (func $keepAlive (; 82 ;)
(drop
(call $sqrts
(f64.const 3.14159)
@@ -2189,19 +2208,26 @@
(call $indirectInSequence)
(call $emterpretify_assertions_safeHeap)
(call $call_emscripten_log)
+ (drop
+ (call $mod_detectSign
+ (f64.const 1)
+ (f64.const 2.31)
+ (f64.const 9.78)
+ )
+ )
)
- (func $v (; 82 ;)
+ (func $v (; 83 ;)
(nop)
)
- (func $vi (; 83 ;) (param $x i32)
+ (func $vi (; 84 ;) (param $x i32)
(nop)
)
- (func $ii (; 84 ;) (param $x i32) (result i32)
+ (func $ii (; 85 ;) (param $x i32) (result i32)
(return
(get_local $x)
)
)
- (func $legalstub$conversions (; 85 ;) (param $0 i32) (param $1 f64) (param $2 f64)
+ (func $legalstub$conversions (; 86 ;) (param $0 i32) (param $1 f64) (param $2 f64)
(call $conversions
(get_local $0)
(get_local $1)
@@ -2210,19 +2236,19 @@
)
)
)
- (func $legalstub$frem_float (; 86 ;) (result f64)
+ (func $legalstub$frem_float (; 87 ;) (result f64)
(f64.promote/f32
(call $frem_float)
)
)
- (func $legalstub$fr (; 87 ;) (param $0 f64)
+ (func $legalstub$fr (; 88 ;) (param $0 f64)
(call $fr
(f32.demote/f64
(get_local $0)
)
)
)
- (func $legalstub$ceiling_32_64 (; 88 ;) (param $0 f64) (param $1 f64)
+ (func $legalstub$ceiling_32_64 (; 89 ;) (param $0 f64) (param $1 f64)
(call $ceiling_32_64
(f32.demote/f64
(get_local $0)
@@ -2230,7 +2256,7 @@
(get_local $1)
)
)
- (func $legalstub$bitcasts (; 89 ;) (param $0 i32) (param $1 f64)
+ (func $legalstub$bitcasts (; 90 ;) (param $0 i32) (param $1 f64)
(call $bitcasts
(get_local $0)
(f32.demote/f64
@@ -2238,7 +2264,7 @@
)
)
)
- (func $legalstub$exported_f32_user (; 90 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f64)
+ (func $legalstub$exported_f32_user (; 91 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f64)
(f64.promote/f32
(call $exported_f32_user
(get_local $0)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index b8f679fb4..d9854f9d6 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -1167,6 +1167,12 @@
(f64.const 0)
)
)
+ (drop
+ (call $f64-rem
+ (f64.const 9.78)
+ (f64.const 1)
+ )
+ )
)
(func $vi (; 54 ;) (; has Stack IR ;) (param $0 i32)
(nop)
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index 22570bea4..bb0ffb996 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -2045,7 +2045,26 @@
)
)
)
- (func $keepAlive (; 76 ;)
+ (func $mod_detectSign (; 76 ;) (param $d1 f64) (param $d2 f64) (param $d8 f64) (result i32)
+ (return
+ (i32.trunc_s/f64
+ (f64.sub
+ (get_local $d2)
+ (f64.mul
+ (f64.div
+ (call $f64-rem
+ (get_local $d8)
+ (get_local $d1)
+ )
+ (get_local $d1)
+ )
+ (get_local $d2)
+ )
+ )
+ )
+ )
+ )
+ (func $keepAlive (; 77 ;)
(drop
(call $sqrts
(f64.const 3.14159)
@@ -2074,19 +2093,26 @@
(call $indirectInSequence)
(call $emterpretify_assertions_safeHeap)
(call $call_emscripten_log)
+ (drop
+ (call $mod_detectSign
+ (f64.const 1)
+ (f64.const 2.31)
+ (f64.const 9.78)
+ )
+ )
)
- (func $v (; 77 ;)
+ (func $v (; 78 ;)
(nop)
)
- (func $vi (; 78 ;) (param $x i32)
+ (func $vi (; 79 ;) (param $x i32)
(nop)
)
- (func $ii (; 79 ;) (param $x i32) (result i32)
+ (func $ii (; 80 ;) (param $x i32) (result i32)
(return
(get_local $x)
)
)
- (func $legalstub$conversions (; 80 ;) (param $0 i32) (param $1 f64) (param $2 f64)
+ (func $legalstub$conversions (; 81 ;) (param $0 i32) (param $1 f64) (param $2 f64)
(call $conversions
(get_local $0)
(get_local $1)
@@ -2095,19 +2121,19 @@
)
)
)
- (func $legalstub$frem_float (; 81 ;) (result f64)
+ (func $legalstub$frem_float (; 82 ;) (result f64)
(f64.promote/f32
(call $frem_float)
)
)
- (func $legalstub$fr (; 82 ;) (param $0 f64)
+ (func $legalstub$fr (; 83 ;) (param $0 f64)
(call $fr
(f32.demote/f64
(get_local $0)
)
)
)
- (func $legalstub$ceiling_32_64 (; 83 ;) (param $0 f64) (param $1 f64)
+ (func $legalstub$ceiling_32_64 (; 84 ;) (param $0 f64) (param $1 f64)
(call $ceiling_32_64
(f32.demote/f64
(get_local $0)
@@ -2115,7 +2141,7 @@
(get_local $1)
)
)
- (func $legalstub$bitcasts (; 84 ;) (param $0 i32) (param $1 f64)
+ (func $legalstub$bitcasts (; 85 ;) (param $0 i32) (param $1 f64)
(call $bitcasts
(get_local $0)
(f32.demote/f64
@@ -2123,7 +2149,7 @@
)
)
)
- (func $legalstub$exported_f32_user (; 85 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f64)
+ (func $legalstub$exported_f32_user (; 86 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f64)
(f64.promote/f32
(call $exported_f32_user
(get_local $0)
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index 59061aa91..07bada359 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -2086,7 +2086,26 @@
)
)
)
- (func $keepAlive (; 79 ;)
+ (func $mod_detectSign (; 79 ;) (param $d1 f64) (param $d2 f64) (param $d8 f64) (result i32)
+ (return
+ (call $f64-to-int
+ (f64.sub
+ (get_local $d2)
+ (f64.mul
+ (f64.div
+ (call $f64-rem
+ (get_local $d8)
+ (get_local $d1)
+ )
+ (get_local $d1)
+ )
+ (get_local $d2)
+ )
+ )
+ )
+ )
+ )
+ (func $keepAlive (; 80 ;)
(drop
(call $sqrts
(f64.const 3.14159)
@@ -2115,19 +2134,26 @@
(call $indirectInSequence)
(call $emterpretify_assertions_safeHeap)
(call $call_emscripten_log)
+ (drop
+ (call $mod_detectSign
+ (f64.const 1)
+ (f64.const 2.31)
+ (f64.const 9.78)
+ )
+ )
)
- (func $v (; 80 ;)
+ (func $v (; 81 ;)
(nop)
)
- (func $vi (; 81 ;) (param $x i32)
+ (func $vi (; 82 ;) (param $x i32)
(nop)
)
- (func $ii (; 82 ;) (param $x i32) (result i32)
+ (func $ii (; 83 ;) (param $x i32) (result i32)
(return
(get_local $x)
)
)
- (func $legalstub$conversions (; 83 ;) (param $0 i32) (param $1 f64) (param $2 f64)
+ (func $legalstub$conversions (; 84 ;) (param $0 i32) (param $1 f64) (param $2 f64)
(call $conversions
(get_local $0)
(get_local $1)
@@ -2136,19 +2162,19 @@
)
)
)
- (func $legalstub$frem_float (; 84 ;) (result f64)
+ (func $legalstub$frem_float (; 85 ;) (result f64)
(f64.promote/f32
(call $frem_float)
)
)
- (func $legalstub$fr (; 85 ;) (param $0 f64)
+ (func $legalstub$fr (; 86 ;) (param $0 f64)
(call $fr
(f32.demote/f64
(get_local $0)
)
)
)
- (func $legalstub$ceiling_32_64 (; 86 ;) (param $0 f64) (param $1 f64)
+ (func $legalstub$ceiling_32_64 (; 87 ;) (param $0 f64) (param $1 f64)
(call $ceiling_32_64
(f32.demote/f64
(get_local $0)
@@ -2156,7 +2182,7 @@
(get_local $1)
)
)
- (func $legalstub$bitcasts (; 87 ;) (param $0 i32) (param $1 f64)
+ (func $legalstub$bitcasts (; 88 ;) (param $0 i32) (param $1 f64)
(call $bitcasts
(get_local $0)
(f32.demote/f64
@@ -2164,7 +2190,7 @@
)
)
)
- (func $legalstub$exported_f32_user (; 88 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f64)
+ (func $legalstub$exported_f32_user (; 89 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f64)
(f64.promote/f32
(call $exported_f32_user
(get_local $0)