Skip to content

Commit

Permalink
[MERGE #5717 @nhat-nguyen] Only do float type specialization if both …
Browse files Browse the repository at this point in the history
…sources are number

Merge pull request #5717 from nhat-nguyen:floattypespecfix

Fix a bug where we try to type specialize non-numbers to floats
  • Loading branch information
nhat-nguyen committed Sep 21, 2018
2 parents e1583ae + 1c3ea7e commit 842077d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Backend/GlobOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10648,6 +10648,11 @@ GlobOpt::TypeSpecializeFloatBinary(IR::Instr *instr, Value *src1Val, Value *src2
case Js::OpCode::CmGe_A:
case Js::OpCode::CmGt_A:
{
if (src1Val->GetValueInfo()->IsNotNumber() || src2Val->GetValueInfo()->IsNotNumber())
{
return false;
}

convertDstToBool = true;
break;
}
Expand Down
17 changes: 17 additions & 0 deletions test/Basics/FloatComparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ var tests = [
assert.isFalse({} < 0.5);
assert.isFalse({} <= 0.5);
}
},
{
name: "No float type specialization when operands are not number",
body: function() {
function test0() {
var func2 = function () {
return f32[1];
};
var f32 = new Float32Array();
var f = 100;
for (let i = 0; i < f; i++) {
var id41 = 'caller';
({ 18: func2() === 'caller' });
}
}
test0();
}
}
];

Expand Down

0 comments on commit 842077d

Please sign in to comment.