diff --git a/src/compiler.ts b/src/compiler.ts index 5cea5c78..a794c40c 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1545,6 +1545,11 @@ export class Compiler extends DiagnosticEmitter { case Token.EQUALS_EQUALS: case Token.EQUALS_EQUALS_EQUALS: + + // NOTE that this favors correctness, in terms of emitting a binary expression, over + // checking for a possible use of unary EQZ. while the most classic of all optimizations, + // that's not what the source told us to do. for reference, `!left` emits unary EQZ. + left = this.compileExpression(expression.left, contextualType, ConversionKind.NONE); right = this.compileExpression(expression.right, this.currentType); diff --git a/tests/compiler/fmod.optimized.wast b/tests/compiler/fmod.optimized.wast index 25ec00a2..b6945be3 100644 --- a/tests/compiler/fmod.optimized.wast +++ b/tests/compiler/fmod.optimized.wast @@ -154,18 +154,18 @@ ) ) (block - (set_local $4 - (i64.shl - (get_local $4) - (i64.const 1) - ) - ) (set_local $3 (i32.sub (get_local $3) (i32.const 1) ) ) + (set_local $4 + (i64.shl + (get_local $4) + (i64.const 1) + ) + ) (br $continue|0) ) ) @@ -211,18 +211,18 @@ ) ) (block - (set_local $4 - (i64.shl - (get_local $4) - (i64.const 1) - ) - ) (set_local $6 (i32.sub (get_local $6) (i32.const 1) ) ) + (set_local $4 + (i64.shl + (get_local $4) + (i64.const 1) + ) + ) (br $continue|1) ) ) @@ -332,18 +332,18 @@ ) ) (block - (set_local $2 - (i64.shl - (get_local $2) - (i64.const 1) - ) - ) (set_local $3 (i32.sub (get_local $3) (i32.const 1) ) ) + (set_local $2 + (i64.shl + (get_local $2) + (i64.const 1) + ) + ) (br $continue|3) ) ) diff --git a/tests/compiler/fmod.ts b/tests/compiler/fmod.ts index 8f2cf74f..786df7f8 100644 --- a/tests/compiler/fmod.ts +++ b/tests/compiler/fmod.ts @@ -15,14 +15,16 @@ export function fmod(x: f64, y: f64): f64 { } if (!ex) { - for (var i = ux << 12; !(i >> 63); ex--) i <<= 1; + for (var i = ux << 12; !(i >> 63); i <<= 1) + --ex; ux <<= -ex + 1; } else { ux &= -1 >> 12; ux |= 1 << 52; } if (!ey) { - for (i = uy << 12; !(i >> 63); ey--) i <<= 1; + for (i = uy << 12; !(i >> 63); i <<= 1) + --ey; uy <<= -ey + 1; } else { uy &= -1 >> 12; @@ -44,7 +46,8 @@ export function fmod(x: f64, y: f64): f64 { return 0 * x; ux = i; } - for (; !(ux >> 52); ex--) ux <<= 1; + for (; !(ux >> 52); ux <<= 1) + --ex; if (ex > 0) { ux -= 1 << 52; diff --git a/tests/compiler/fmod.wast b/tests/compiler/fmod.wast index 01078801..6ed67b2b 100644 --- a/tests/compiler/fmod.wast +++ b/tests/compiler/fmod.wast @@ -165,26 +165,18 @@ ) ) (block + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 1) + ) + ) (set_local $9 (i64.shl (get_local $9) (i64.const 1) ) ) - (drop - (block (result i32) - (set_local $8 - (get_local $4) - ) - (set_local $4 - (i32.sub - (get_local $8) - (i32.const 1) - ) - ) - (get_local $8) - ) - ) (br $continue|0) ) ) @@ -250,26 +242,18 @@ ) ) (block + (set_local $5 + (i32.sub + (get_local $5) + (i32.const 1) + ) + ) (set_local $9 (i64.shl (get_local $9) (i64.const 1) ) ) - (drop - (block (result i32) - (set_local $8 - (get_local $5) - ) - (set_local $5 - (i32.sub - (get_local $8) - (i32.const 1) - ) - ) - (get_local $8) - ) - ) (br $continue|1) ) ) @@ -421,26 +405,18 @@ ) ) (block + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 1) + ) + ) (set_local $2 (i64.shl (get_local $2) (i64.const 1) ) ) - (drop - (block (result i32) - (set_local $8 - (get_local $4) - ) - (set_local $4 - (i32.sub - (get_local $8) - (i32.const 1) - ) - ) - (get_local $8) - ) - ) (br $continue|3) ) )