Skip to content

Commit e698825

Browse files
committed
[MERGE #5420 @rajatd] Invariant check for a propertySym before loading a property from it in the landing pad. OS #17516086
Merge pull request #5420 from rajatd:prebug If a property sym is not invariant in the loop, we can't legally preload in the landing pad any property load from it.
2 parents 9130841 + d1bae7f commit e698825

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17187,6 +17187,13 @@ GlobOpt::PRE::InsertSymDefinitionInLandingPad(StackSym * sym, Loop * loop, Sym *
1718717187

1718817188
BasicBlock* loopTail = loop->GetAnyTailBlock();
1718917189
Value * valueOnBackEdge = loopTail->globOptData.FindValue(propSym);
17190+
17191+
// If o.x is not invariant in the loop, we can't use the preloaded value of o.x.y in the landing pad
17192+
Value * valueInLandingPad = loop->landingPad->globOptData.FindValue(propSym);
17193+
if (valueOnBackEdge->GetValueNumber() != valueInLandingPad->GetValueNumber())
17194+
{
17195+
return false;
17196+
}
1719017197

1719117198
*objPtrCopyPropSym = valueOnBackEdge->GetValueInfo()->GetSymStore();
1719217199

test/PRE/bug0.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
7+
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
8+
}
9+
10+
var tests = [
11+
{
12+
name: "test0",
13+
body: function () {
14+
function bar()
15+
{
16+
o = {x:2};
17+
}
18+
o = {x:1}
19+
function test0()
20+
{
21+
var b;
22+
for(var i=0;i<2;i++)
23+
{
24+
b = o.x <<= bar();
25+
}
26+
assert.areEqual(2, b);
27+
}
28+
test0();
29+
test0();
30+
o = {x:1};
31+
test0();
32+
}
33+
},
34+
{
35+
name: "test1",
36+
body: function () {
37+
var obj2 = {};
38+
var i32 = new Int32Array();
39+
var func0 = function () {
40+
return obj2;
41+
};
42+
Object.prototype.prop5 = 1;
43+
var a;
44+
for (var __loopvar0 = 4; __loopvar0 > 0; __loopvar0--)
45+
{
46+
function func7(arg1) {
47+
this.prop2 = arg1;
48+
}
49+
obj2 = new func7(obj2.prop5--);
50+
}
51+
52+
assert.areEqual(1, obj2.prop2);
53+
}
54+
},
55+
{
56+
name: "test2",
57+
body: function (){
58+
function makeArrayLength(x) {
59+
if (!isNaN(x)) {
60+
return Math.floor(x) & 65535;
61+
}
62+
}
63+
var obj0 = {};
64+
var c = 1;
65+
obj0.length = makeArrayLength(4294967295);
66+
67+
for (; obj0.length--; c++)
68+
{
69+
obj0 = {
70+
method1: function () {
71+
return function v1() {
72+
({ nd0: { method1: obj0 } } );
73+
};
74+
}
75+
};
76+
}
77+
assert.areEqual(2, c);
78+
}
79+
}
80+
];
81+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
82+

test/PRE/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@
88
<compile-flags>-testtrace:fieldcopyprop -oopjit-</compile-flags>
99
</default>
1010
</test>
11+
<test>
12+
<default>
13+
<files>bug0.js</files>
14+
<compile-flags>-args summary -endargs</compile-flags>
15+
</default>
16+
</test>
1117
</regress-exe>

0 commit comments

Comments
 (0)