From b6a3f9f6504e57359a722099930faf69befb8d9a Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 16 Oct 2013 18:02:13 -0500 Subject: [PATCH] Bug 927112 - OdinMonkey: loosen up type rules for + (r=sstangl) --HG-- extra : rebase_source : 7c3cc07c2885202524f604cdd259e029f47282e9 --- .../jit-test/tests/asm.js/testExpressions.js | 2 +- js/src/jit/AsmJS.cpp | 33 +++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/js/src/jit-test/tests/asm.js/testExpressions.js b/js/src/jit-test/tests/asm.js/testExpressions.js index 9ac72a6eaf0f..68ec4cfe1df6 100644 --- a/js/src/jit-test/tests/asm.js/testExpressions.js +++ b/js/src/jit-test/tests/asm.js/testExpressions.js @@ -253,8 +253,8 @@ assertEq(f(-1,false), 0); assertEq(f(-5,false), 1); assertAsmTypeFail('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return (i32[0]+1)|0 } return f"); -assertAsmTypeFail('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] + 1.0); } return f"); new Float64Array(BUF_64KB)[0] = 2.3; +assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] + 2.0) } return f"), this, null, BUF_64KB)(), 2.3+2); assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] - 2.0) } return f"), this, null, BUF_64KB)(), 2.3-2); assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] * 2.0) } return f"), this, null, BUF_64KB)(), 2.3*2); assertEq(asmLink(asmCompile('glob','imp','b', USE_ASM + HEAP_IMPORTS + "function f() { return +(f64[0] / 2.0) } return f"), this, null, BUF_64KB)(), 2.3/2); diff --git a/js/src/jit/AsmJS.cpp b/js/src/jit/AsmJS.cpp index 3f1426c98f4e..5f189cc00f3a 100644 --- a/js/src/jit/AsmJS.cpp +++ b/js/src/jit/AsmJS.cpp @@ -4157,28 +4157,19 @@ CheckAddOrSub(FunctionCompiler &f, ParseNode *expr, MDefinition **def, Type *typ if (numAddOrSub > (1<<20)) return f.fail(expr, "too many + or - without intervening coercion"); - if (expr->isKind(PNK_ADD)) { - if (lhsType.isInt() && rhsType.isInt()) { - *def = f.binary(lhsDef, rhsDef, MIRType_Int32); - *type = Type::Intish; - } else if (lhsType.isDouble() && rhsType.isDouble()) { - *def = f.binary(lhsDef, rhsDef, MIRType_Double); - *type = Type::Double; - } else { - return f.failf(expr, "operands to + must both be int or double, got %s and %s", - lhsType.toChars(), rhsType.toChars()); - } + if (lhsType.isInt() && rhsType.isInt()) { + *def = expr->isKind(PNK_ADD) + ? f.binary(lhsDef, rhsDef, MIRType_Int32) + : f.binary(lhsDef, rhsDef, MIRType_Int32); + *type = Type::Intish; + } else if (lhsType.isDoublish() && rhsType.isDoublish()) { + *def = expr->isKind(PNK_ADD) + ? f.binary(lhsDef, rhsDef, MIRType_Double) + : f.binary(lhsDef, rhsDef, MIRType_Double); + *type = Type::Double; } else { - if (lhsType.isInt() && rhsType.isInt()) { - *def = f.binary(lhsDef, rhsDef, MIRType_Int32); - *type = Type::Intish; - } else if (lhsType.isDoublish() && rhsType.isDoublish()) { - *def = f.binary(lhsDef, rhsDef, MIRType_Double); - *type = Type::Double; - } else { - return f.failf(expr, "operands to - must both be int or doublish, got %s and %s", - lhsType.toChars(), rhsType.toChars()); - } + return f.failf(expr, "operands to +/- must both be int or doublish, got %s and %s", + lhsType.toChars(), rhsType.toChars()); } if (numAddOrSubOut)