Skip to content

Commit 5e53397

Browse files
author
Meghana Gupta
committed
[MERGE #6085 @meg-gupta] OS#19078643: Fix constant branch folding when equal sources can be Undefined
Merge pull request #6085 from meg-gupta:fixundefined We constant fold branches with same sources. The outcome of this folding is different when the source has a valueType of Undefined. Previously, we checked for this case with ValueType::IsUndefined. But this check does not include valueTypes like - Undefined | Boolean, in which case we cannot constant fold. With this fix, we handle the case where we can have a definite valueType which could be Undefined.
2 parents e35b59c + df74779 commit 5e53397

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6666,7 +6666,8 @@ GlobOpt::CanProveConditionalBranch(IR::Instr *instr, Value *src1Val, Value *src2
66666666
{
66676667
return undefinedCmp;
66686668
}
6669-
return val1->GetValueInfo()->IsPrimitive() && val1->GetValueInfo()->IsNotFloat();
6669+
ValueInfo * valInfo = val1->GetValueInfo();
6670+
return !valInfo->HasBeenUndefined() && valInfo->IsPrimitive() && valInfo->IsNotFloat();
66706671
}
66716672
return false;
66726673
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1,6333966881283110000
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
var obj1 = {};
7+
var litObj1 = {};
8+
var func1 = function () {
9+
if (ary.push(arguments[0])) {
10+
}
11+
};
12+
obj1.method0 = func1;
13+
var ary = Array();
14+
var FloatArr0 = [
15+
6333966881283110000,
16+
1
17+
];
18+
var VarArr0 = Array();
19+
var v3 = 0;
20+
function v4() {
21+
return caller1_bar();
22+
}
23+
function v5() {
24+
return v4();
25+
}
26+
function caller1_bar() {
27+
v3++;
28+
if (v3 < 10) {
29+
v4();
30+
var id33 = {} instanceof Boolean;
31+
}
32+
if (ary.shift(), (obj1.method0.call(litObj1, FloatArr0), id33 <= id33 ? VarArr0 : FloatArr0.reverse())) {
33+
}
34+
}
35+
v5();
36+
WScript.Echo(ary.slice().reduce(function () {
37+
}));
38+

test/Optimizer/rlexe.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,14 @@
15671567
<tags>exclude_dynapogo,exclude_nonative</tags>
15681568
</default>
15691569
</test>
1570+
<test>
1571+
<default>
1572+
<files>bugconstfoldundefined.js</files>
1573+
<baseline>bugconstfoldundefined.baseline</baseline>
1574+
<compile-flags>-maxinterpretcount:6 -maxsimplejitruncount:4 -werexceptionsupport -oopjit- -mic:1 -off:simplejit -forcejitloopbody</compile-flags>
1575+
<tags>exclude_dynapogo,exclude_nonative</tags>
1576+
</default>
1577+
</test>
15701578
<test>
15711579
<default>
15721580
<files>bcebug.js</files>

0 commit comments

Comments
 (0)