Skip to content

Commit c580ce0

Browse files
committed
[MERGE chakra-core#4428 @Cellule] ArrayOpt Assert
Merge pull request chakra-core#4428 from Cellule:array_assert Modify Array Assert to check most conditions at once
2 parents a598f34 + 8cd0adc commit c580ce0

5 files changed

Lines changed: 53 additions & 19 deletions

File tree

lib/Backend/GlobOpt.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ GlobOpt::OptSrc(IR::Opnd *opnd, IR::Instr * *pInstr, Value **indirIndexValRef, I
35303530
ValueType valueType(val->GetValueInfo()->Type());
35313531

35323532
// This block uses local profiling data to optimize the case of a native array being passed to a function that fills it with other types. When the function is inlined
3533-
// into different call paths which use different types this can cause a perf hit by performing unnecessary array conversions, so only perform this optimization when
3533+
// into different call paths which use different types this can cause a perf hit by performing unnecessary array conversions, so only perform this optimization when
35343534
// the function is not inlined.
35353535
if (valueType.IsLikelyNativeArray() && !valueType.IsObject() && instr->IsProfiledInstr() && !instr->m_func->IsInlined())
35363536
{
@@ -5452,7 +5452,7 @@ GlobOpt::ValueNumberLdElemDst(IR::Instr **pInstr, Value *srcVal)
54525452
case ObjectType::Float64MixedArray:
54535453
Float64Array:
54545454
Assert(dst->IsRegOpnd());
5455-
5455+
54565456
// If float type spec is disabled, don't load float64 values
54575457
if (!this->DoFloatTypeSpec())
54585458
{
@@ -7550,7 +7550,7 @@ GlobOpt::TypeSpecializeInlineBuiltInBinary(IR::Instr **pInstr, Value *src1Val, V
75507550
{
75517551
// Compute resulting range info
75527552
int32 min1 = INT32_MIN;
7553-
int32 max1 = INT32_MAX;
7553+
int32 max1 = INT32_MAX;
75547554
int32 min2 = INT32_MIN;
75557555
int32 max2 = INT32_MAX;
75567556
int32 newMin, newMax;
@@ -12273,7 +12273,7 @@ static void SetIsConstFlag(StackSym* dstSym, int value)
1227312273
dstSym->SetIsIntConst(value);
1227412274
}
1227512275

12276-
static IR::Opnd* CreateIntConstOpnd(IR::Instr* instr, int64 value)
12276+
static IR::Opnd* CreateIntConstOpnd(IR::Instr* instr, int64 value)
1227712277
{
1227812278
return (IR::Opnd*)IR::Int64ConstOpnd::New(value, instr->GetDst()->GetType(), instr->m_func);
1227912279
}
@@ -12331,7 +12331,7 @@ bool GlobOpt::OptConstFoldBinaryWasm(
1233112331
}
1233212332

1233312333
T src1IntConstantValue, src2IntConstantValue;
12334-
if (!src1 || !src1->GetValueInfo()->TryGetIntConstantValue(&src1IntConstantValue, false) || //a bit sketchy: false for int32 means likelyInt = false
12334+
if (!src1 || !src1->GetValueInfo()->TryGetIntConstantValue(&src1IntConstantValue, false) || //a bit sketchy: false for int32 means likelyInt = false
1233512335
!src2 || !src2->GetValueInfo()->TryGetIntConstantValue(&src2IntConstantValue, false) //and unsigned = false for int64
1233612336
)
1233712337
{
@@ -13792,19 +13792,18 @@ GlobOpt::OptArraySrc(IR::Instr * *const instrRef)
1379213792
// array type during a prepass.
1379313793
// - StElems in the loop can kill the no-missing-values info.
1379413794
// - The native array type may be made more conservative based on profile data by an instruction in the loop.
13795-
Assert(
13796-
baseValueInLoopLandingPad->GetValueInfo()->CanMergeToSpecificObjectType() ||
13797-
baseValueInLoopLandingPad->GetValueInfo()->Type().SetCanBeTaggedValue(false) ==
13798-
baseValueType.SetCanBeTaggedValue(false) ||
13799-
baseValueInLoopLandingPad->GetValueInfo()->Type().SetHasNoMissingValues(false).SetCanBeTaggedValue(false) ==
13800-
baseValueType.SetHasNoMissingValues(false).SetCanBeTaggedValue(false) ||
13801-
baseValueInLoopLandingPad->GetValueInfo()->Type().SetHasNoMissingValues(false).ToLikely().SetCanBeTaggedValue(false) ==
13802-
baseValueType.SetHasNoMissingValues(false).SetCanBeTaggedValue(false) ||
13803-
(
13804-
baseValueInLoopLandingPad->GetValueInfo()->Type().IsLikelyNativeArray() &&
13805-
baseValueInLoopLandingPad->GetValueInfo()->Type().Merge(baseValueType).SetHasNoMissingValues(false).SetCanBeTaggedValue(false) ==
13806-
baseValueType.SetHasNoMissingValues(false).SetCanBeTaggedValue(false)
13807-
));
13795+
#if DBG
13796+
if (!baseValueInLoopLandingPad->GetValueInfo()->CanMergeToSpecificObjectType())
13797+
{
13798+
ValueType landingPadValueType = baseValueInLoopLandingPad->GetValueInfo()->Type();
13799+
Assert(landingPadValueType.IsSimilar(baseValueType) ||
13800+
(
13801+
landingPadValueType.IsLikelyNativeArray() &&
13802+
landingPadValueType.Merge(baseValueType).IsSimilar(baseValueType)
13803+
)
13804+
);
13805+
}
13806+
#endif
1380813807

1380913808
if(doArrayChecks)
1381013809
{
@@ -18029,7 +18028,7 @@ GlobOpt::DumpSymVal(int index)
1802918028
}
1803018029

1803118030
void
18032-
GlobOpt::Trace(BasicBlock * block, bool before) const
18031+
GlobOpt::Trace(BasicBlock * block, bool before) const
1803318032
{
1803418033
bool globOptTrace = Js::Configuration::Global.flags.Trace.IsEnabled(Js::GlobOptPhase, this->func->GetSourceContextId(), this->func->GetLocalFunctionId());
1803518034
bool typeSpecTrace = Js::Configuration::Global.flags.Trace.IsEnabled(Js::TypeSpecPhase, this->func->GetSourceContextId(), this->func->GetLocalFunctionId());

lib/Runtime/Language/ValueType.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ bool ValueType::IsLikelyPrimitive() const
510510
return result;
511511
}
512512

513+
#if DBG
514+
bool ValueType::IsSimilar(ValueType v) const
515+
{
516+
// Remove bits we don't care for comparison
517+
ValueType left = Verify(bits & ~(Bits::NoMissingValues | Bits::CanBeTaggedValue | Bits::Likely));
518+
ValueType right = Verify(v.bits & ~(Bits::NoMissingValues | Bits::CanBeTaggedValue | Bits::Likely));
519+
return left == right;
520+
}
521+
#endif
513522

514523
bool ValueType::HasBeenObject() const
515524
{

lib/Runtime/Language/ValueType.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ class ValueType
168168
bool IsPrimitive() const;
169169
bool IsLikelyPrimitive() const;
170170

171+
#if DBG
172+
bool IsSimilar(ValueType v) const;
173+
#endif
174+
171175
#if ENABLE_NATIVE_CODEGEN
172176
// SIMD_JS
173177
bool IsSimd128() const;

test/typedarray/likely.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 buf = new ArrayBuffer(0x100000);
7+
var arrays = [new Int32Array(buf)];
8+
function foo() {
9+
var arr = arrays[0];
10+
for (let i = 0; i < 1000; ++i) {
11+
Number(arr[0]) || !!arr[0];
12+
}
13+
}
14+
foo();
15+
print("pass");

test/typedarray/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<regress-exe>
3+
<test>
4+
<default>
5+
<files>likely.js</files>
6+
<compile-flags>-bgjit- -lic:1</compile-flags>
7+
<tags>typedarray</tags>
8+
</default>
9+
</test>
310
<test>
411
<default>
512
<files>arraybuffer.js</files>

0 commit comments

Comments
 (0)