Commit 753a2b55 authored by danno's avatar danno Committed by Commit bot

[csa] Add IsIntPtrOrSmiConstantZero to detect and optimize constant zero values

Review-Url: https://codereview.chromium.org/2658253002
Cr-Commit-Position: refs/heads/master@{#42766}
parent 409d0180
......@@ -171,6 +171,16 @@ Node* CodeStubAssembler::IntPtrOrSmiConstant(int value, ParameterMode mode) {
}
}
bool CodeStubAssembler::IsIntPtrOrSmiConstantZero(Node* test) {
int32_t constant_test;
Smi* smi_test;
if ((ToInt32Constant(test, constant_test) && constant_test == 0) ||
(ToSmiConstant(test, smi_test) && smi_test->value() == 0)) {
return true;
}
return false;
}
Node* CodeStubAssembler::IntPtrRoundUpToPowerOfTwo32(Node* value) {
Comment("IntPtrRoundUpToPowerOfTwo32");
CSA_ASSERT(this, UintPtrLessThanOrEqual(value, IntPtrConstant(0x80000000u)));
......@@ -2062,8 +2072,7 @@ Node* CodeStubAssembler::AllocateJSArray(ElementsKind kind, Node* array_map,
Node* allocation_site,
ParameterMode capacity_mode) {
Node *array = nullptr, *elements = nullptr;
int32_t constant_capacity;
if (ToInt32Constant(capacity, constant_capacity) && constant_capacity == 0) {
if (IsIntPtrOrSmiConstantZero(capacity)) {
// Array is empty. Use the shared empty fixed array instead of allocating a
// new one.
array = AllocateUninitializedJSArrayWithoutElements(kind, array_map, length,
......
......@@ -140,6 +140,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* IntPtrOrSmiConstant(int value, ParameterMode mode);
bool IsIntPtrOrSmiConstantZero(Node* test);
// Round the 32bits payload of the provided word up to the next power of two.
Node* IntPtrRoundUpToPowerOfTwo32(Node* value);
// Select the maximum of the two provided IntPtr values.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment