Skip to content

Commit 16de442

Browse files
committed
[MERGE #5229 @Cellule] Array fastpath non-int argument
Merge pull request #5229 from Cellule:array_fastpath_bigint On 32 bits platform, we shouldn't do a fast path for constructors with arguments we know can't be a tagged int. OS#16717501
2 parents 3b5bc60 + a5b260e commit 16de442

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

lib/Backend/Lower.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,12 +3688,12 @@ BOOL Lowerer::IsSmallObject(uint32 length)
36883688
return HeapInfo::IsSmallObject(HeapInfo::GetAlignedSizeNoCheck(allocSize));
36893689
}
36903690

3691-
void
3691+
bool
36923692
Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length)
36933693
{
36943694
if (PHASE_OFF(Js::ArrayCtorFastPathPhase, m_func) || CONFIG_FLAG(ForceES5Array))
36953695
{
3696-
return;
3696+
return false;
36973697
}
36983698

36993699
Func * func = this->m_func;
@@ -3708,7 +3708,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37083708
{
37093709
if (!IsSmallObject<Js::JavascriptNativeIntArray>(length))
37103710
{
3711-
return;
3711+
return false;
37123712
}
37133713
GenerateArrayInfoIsNativeIntArrayTest(instr, arrayInfo, arrayInfoAddr, helperLabel);
37143714
Assert(Js::JavascriptNativeIntArray::GetOffsetOfArrayFlags() + sizeof(uint16) == Js::JavascriptNativeIntArray::GetOffsetOfArrayCallSiteIndex());
@@ -3726,7 +3726,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37263726
{
37273727
if (!IsSmallObject<Js::JavascriptNativeFloatArray>(length))
37283728
{
3729-
return;
3729+
return false;
37303730
}
37313731
GenerateArrayInfoIsNativeFloatAndNotIntArrayTest(instr, arrayInfo, arrayInfoAddr, helperLabel);
37323732
Assert(Js::JavascriptNativeFloatArray::GetOffsetOfArrayFlags() + sizeof(uint16) == Js::JavascriptNativeFloatArray::GetOffsetOfArrayCallSiteIndex());
@@ -3750,7 +3750,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37503750
{
37513751
if (!IsSmallObject<Js::JavascriptArray>(length))
37523752
{
3753-
return;
3753+
return false;
37543754
}
37553755
uint const offsetStart = sizeof(Js::SparseArraySegmentBase);
37563756
headOpnd = GenerateArrayLiteralsAlloc<Js::JavascriptArray>(instr, &size, arrayInfo, &isZeroed);
@@ -3770,6 +3770,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37703770
instr->InsertBefore(helperLabel);
37713771

37723772
instr->InsertAfter(doneLabel);
3773+
return true;
37733774
}
37743775

37753776
void
@@ -4031,12 +4032,12 @@ Lowerer::GenerateArrayAlloc(IR::Instr *instr, IR::Opnd * arrayLenOpnd, Js::Array
40314032
}
40324033

40334034

4034-
void
4035+
bool
40354036
Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs)
40364037
{
40374038
if (PHASE_OFF(Js::ArrayCtorFastPathPhase, m_func))
40384039
{
4039-
return;
4040+
return false;
40404041
}
40414042

40424043
Func * func = this->m_func;
@@ -4096,17 +4097,18 @@ Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSi
40964097
// Skip pass the helper call
40974098
InsertBranch(Js::OpCode::Br, labelDone, instr);
40984099
instr->InsertBefore(helperLabel);
4100+
return true;
40994101
}
41004102

41014103

41024104
template <typename ArrayType>
4103-
void
4105+
bool
41044106
Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel,
41054107
IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef)
41064108
{
41074109
if (PHASE_OFF(Js::ArrayCtorFastPathPhase, m_func))
41084110
{
4109-
return;
4111+
return false;
41104112
}
41114113

41124114
Func * func = this->m_func;
@@ -4200,6 +4202,7 @@ Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSi
42004202

42014203
Lowerer::InsertBranch(Js::OpCode::Br, labelDone, instr);
42024204
instr->InsertBefore(helperLabel);
4205+
return true;
42034206
}
42044207

42054208
void
@@ -5272,26 +5275,29 @@ Lowerer::LowerNewScObjArray(IR::Instr *newObjInstr)
52725275
AssertMsg(linkSym->IsArgSlotSym(), "Not an argSlot symbol...");
52735276
linkOpnd = argInstr->GetSrc2();
52745277

5275-
bool emittedFastPath = true;
5278+
bool emittedFastPath = false;
52765279
// 2a. If 1st parameter is a variable, emit fast path with checks
52775280
if (opndOfArrayCtor->IsRegOpnd())
52785281
{
5279-
// 3. GenerateFastPath
5280-
if (arrayInfo && arrayInfo->IsNativeIntArray())
5281-
{
5282-
GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeIntArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5283-
Js::JavascriptNativeIntArray::GetOffsetOfArrayCallSiteIndex(),
5284-
Js::JavascriptNativeIntArray::GetOffsetOfWeakFuncRef());
5285-
}
5286-
else if (arrayInfo && arrayInfo->IsNativeFloatArray())
5282+
if (!opndOfArrayCtor->AsRegOpnd()->IsNotInt())
52875283
{
5288-
GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeFloatArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5289-
Js::JavascriptNativeFloatArray::GetOffsetOfArrayCallSiteIndex(),
5290-
Js::JavascriptNativeFloatArray::GetOffsetOfWeakFuncRef());
5291-
}
5292-
else
5293-
{
5294-
GenerateProfiledNewScObjArrayFastPath<Js::JavascriptArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor, 0, 0);
5284+
// 3. GenerateFastPath
5285+
if (arrayInfo && arrayInfo->IsNativeIntArray())
5286+
{
5287+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeIntArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5288+
Js::JavascriptNativeIntArray::GetOffsetOfArrayCallSiteIndex(),
5289+
Js::JavascriptNativeIntArray::GetOffsetOfWeakFuncRef());
5290+
}
5291+
else if (arrayInfo && arrayInfo->IsNativeFloatArray())
5292+
{
5293+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeFloatArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5294+
Js::JavascriptNativeFloatArray::GetOffsetOfArrayCallSiteIndex(),
5295+
Js::JavascriptNativeFloatArray::GetOffsetOfWeakFuncRef());
5296+
}
5297+
else
5298+
{
5299+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath<Js::JavascriptArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor, 0, 0);
5300+
}
52955301
}
52965302
}
52975303
// 2b. If 1st parameter is a constant, it is in range 0 and upperBoundValue (inclusive)
@@ -5300,11 +5306,7 @@ Lowerer::LowerNewScObjArray(IR::Instr *newObjInstr)
53005306
int32 length = linkSym->GetIntConstValue();
53015307
if (length >= 0 && length <= upperBoundValue)
53025308
{
5303-
GenerateProfiledNewScObjArrayFastPath(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, (uint32)length, labelDone, false);
5304-
}
5305-
else
5306-
{
5307-
emittedFastPath = false;
5309+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, (uint32)length, labelDone, false);
53085310
}
53095311
}
53105312
// Since we emitted fast path above, move the startCall/argOut instruction right before helper

lib/Backend/Lower.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,11 @@ class Lowerer
667667
template <typename ArrayType>
668668
IR::RegOpnd * GenerateArrayAlloc(IR::Instr *instr, IR::Opnd * sizeOpnd, Js::ArrayCallSiteInfo * arrayInfo);
669669

670-
void GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs);
670+
bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs);
671671

672672
template <typename ArrayType>
673-
void GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel, IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef);
674-
void GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length);
673+
bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel, IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef);
674+
bool GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length);
675675

676676
void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, int32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
677677
void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, uint32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);

test/Array/constructor_fastpath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//-------------------------------------------------------------------------------------------------------
55

66
function makeArray() {
7-
return [new Array(true), new Array("some string")];
7+
return [new Array(true), new Array("some string"), new Array(1075133691)];
88
}
99

1010
for (let i = 0; i < 100; ++i) {

0 commit comments

Comments
 (0)