Skip to content

Commit fe84b27

Browse files
author
Meghana Gupta
committed
[MERGE #6086 @meg-gupta] OS#19035235:Fix constant branch folding for BrOnObject
Merge pull request #6086 from meg-gupta:fixobject BrOnObject is true for non-primitives, false for primitives. We were relying on IsDefinite along with IsPrimitive check to constant fold BrOnObject. But this is not sufficient for a valueType like Null | Object. IsPrimitive returns false because it sees the Object bit, we cannot constant fold BrOnObject to true with just this check. Because the valueType can also be Null. This change fixes this.
2 parents 2200b10 + f00433e commit fe84b27

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6960,7 +6960,20 @@ GlobOpt::CanProveConditionalBranch(IR::Instr *instr, Value *src1Val, Value *src2
69606960
{
69616961
return false;
69626962
}
6963-
*result = !src1ValueInfo->IsPrimitive();
6963+
6964+
if (src1ValueInfo->IsPrimitive())
6965+
{
6966+
*result = false;
6967+
}
6968+
else
6969+
{
6970+
if (src1ValueInfo->HasBeenPrimitive())
6971+
{
6972+
return false;
6973+
}
6974+
*result = true;
6975+
}
6976+
69646977
break;
69656978
}
69666979
default:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[object Object]
2+
[object Object]
3+
[object Object]

test/Optimizer/bugconstfoldobject.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
function test0() {
7+
class class3 {
8+
constructor() {
9+
return '9'.match(/^(?=[a7])$/gim);
10+
}
11+
}
12+
strvar0 = new class3();
13+
new class3();
14+
WScript.Echo(strvar0);
15+
}
16+
test0();
17+
test0();
18+
test0();
19+

0 commit comments

Comments
 (0)