Skip to content

Commit c968607

Browse files
jakobkummerowCommit Bot
authored andcommitted
Update LookupIterator and ICs for size_t indices
They have to be in sync, so this patch updates both systems. Bug: v8:4153 Change-Id: I09252e41a710e79f823fe6818c1c6c0038faeb31 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1903434 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#65078}
1 parent c4cf2ea commit c968607

35 files changed

Lines changed: 544 additions & 363 deletions

src/ast/ast-value-factory.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace internal {
3838

3939
namespace {
4040

41-
// For using StringToArrayIndex.
41+
// For using StringToIndex.
4242
class OneByteStringStream {
4343
public:
4444
explicit OneByteStringStream(Vector<const byte> lb) :
@@ -76,11 +76,15 @@ bool AstRawString::AsArrayIndex(uint32_t* index) const {
7676
*index = Name::ArrayIndexValueBits::decode(hash_field_);
7777
} else {
7878
OneByteStringStream stream(literal_bytes_);
79-
CHECK(StringToArrayIndex(&stream, index));
79+
CHECK(StringToIndex(&stream, index));
8080
}
8181
return true;
8282
}
8383

84+
bool AstRawString::IsIntegerIndex() const {
85+
return (hash_field_ & Name::kIsNotIntegerIndexMask) == 0;
86+
}
87+
8488
bool AstRawString::IsOneByteEqualTo(const char* data) const {
8589
if (!is_one_byte()) return false;
8690

src/ast/ast-value-factory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AstRawString final : public ZoneObject {
5252
: literal_bytes_.length() / 2;
5353
}
5454
bool AsArrayIndex(uint32_t* index) const;
55+
bool IsIntegerIndex() const;
5556
V8_EXPORT_PRIVATE bool IsOneByteEqualTo(const char* data) const;
5657
uint16_t FirstCharacter() const;
5758

src/builtins/builtins-object-gen.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ TF_BUILTIN(ObjectPrototypeHasOwnProperty, ObjectBuiltinsAssembler) {
398398

399399
BIND(&if_index);
400400
{
401-
// Handle negative keys in the runtime.
402-
GotoIf(IntPtrLessThan(var_index.value(), IntPtrConstant(0)),
403-
&call_runtime);
404401
TryLookupElement(object, map, instance_type, var_index.value(),
405402
&return_true, &return_false, &return_false,
406403
&call_runtime);

src/codegen/code-stub-assembler.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9241,9 +9241,15 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
92419241
}
92429242
BIND(&if_oob);
92439243
{
9244-
// Positive OOB indices mean "not found", negative indices must be
9245-
// converted to property names.
9246-
GotoIf(IntPtrLessThan(intptr_index, IntPtrConstant(0)), if_bailout);
9244+
// Positive OOB indices mean "not found", negative indices and indices
9245+
// out of array index range must be converted to property names.
9246+
if (Is64()) {
9247+
GotoIf(UintPtrLessThan(IntPtrConstant(JSArray::kMaxArrayIndex),
9248+
intptr_index),
9249+
if_bailout);
9250+
} else {
9251+
GotoIf(IntPtrLessThan(intptr_index, IntPtrConstant(0)), if_bailout);
9252+
}
92479253
Goto(if_not_found);
92489254
}
92499255
}
@@ -9754,10 +9760,10 @@ TNode<IntPtrT> CodeStubAssembler::TryToIntptr(
97549760
BIND(&key_is_heapnumber);
97559761
{
97569762
TNode<Float64T> value = LoadHeapNumberValue(CAST(key));
9757-
TNode<Int32T> int_value = RoundFloat64ToInt32(value);
9758-
GotoIfNot(Float64Equal(value, ChangeInt32ToFloat64(int_value)),
9763+
TNode<IntPtrT> int_value = ChangeFloat64ToIntPtr(value);
9764+
GotoIfNot(Float64Equal(value, RoundIntPtrToFloat64(int_value)),
97599765
if_not_intptr);
9760-
var_intptr_key = ChangeInt32ToIntPtr(int_value);
9766+
var_intptr_key = int_value;
97619767
Goto(&done);
97629768
}
97639769

@@ -10190,7 +10196,7 @@ void CodeStubAssembler::EmitElementStore(Node* object, Node* key, Node* value,
1019010196
Node* CodeStubAssembler::CheckForCapacityGrow(Node* object, Node* elements,
1019110197
ElementsKind kind,
1019210198
SloppyTNode<UintPtrT> length,
10193-
SloppyTNode<WordT> key,
10199+
TNode<IntPtrT> key,
1019410200
ParameterMode mode,
1019510201
Label* bailout) {
1019610202
DCHECK(IsFastElementsKind(kind));
@@ -10225,9 +10231,11 @@ Node* CodeStubAssembler::CheckForCapacityGrow(Node* object, Node* elements,
1022510231

1022610232
BIND(&grow_bailout);
1022710233
{
10234+
GotoIf(IntPtrOrSmiLessThan(key, IntPtrOrSmiConstant(0, mode), mode),
10235+
bailout);
1022810236
Node* tagged_key = mode == SMI_PARAMETERS
1022910237
? static_cast<Node*>(key)
10230-
: ChangeInt32ToTagged(TruncateWordToInt32(key));
10238+
: ChangeUintPtrToTagged(Unsigned(key));
1023110239
TNode<Object> maybe_elements = CallRuntime(
1023210240
Runtime::kGrowArrayElements, NoContextConstant(), object, tagged_key);
1023310241
GotoIf(TaggedIsSmi(maybe_elements), bailout);

src/codegen/code-stub-assembler.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,9 +3266,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
32663266
Variable* maybe_converted_value = nullptr);
32673267

32683268
Node* CheckForCapacityGrow(Node* object, Node* elements, ElementsKind kind,
3269-
SloppyTNode<UintPtrT> length,
3270-
SloppyTNode<WordT> key, ParameterMode mode,
3271-
Label* bailout);
3269+
SloppyTNode<UintPtrT> length, TNode<IntPtrT> key,
3270+
ParameterMode mode, Label* bailout);
32723271

32733272
Node* CopyElementsOnWrite(Node* object, Node* elements, ElementsKind kind,
32743273
Node* length, ParameterMode mode, Label* bailout);

src/compiler/code-assembler.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,14 @@ TNode<IntPtrT> CodeAssembler::ChangeInt32ToIntPtr(SloppyTNode<Word32T> value) {
915915
return ReinterpretCast<IntPtrT>(value);
916916
}
917917

918+
TNode<IntPtrT> CodeAssembler::ChangeFloat64ToIntPtr(TNode<Float64T> value) {
919+
if (raw_assembler()->machine()->Is64()) {
920+
return ReinterpretCast<IntPtrT>(
921+
raw_assembler()->ChangeFloat64ToInt64(value));
922+
}
923+
return ReinterpretCast<IntPtrT>(raw_assembler()->ChangeFloat64ToInt32(value));
924+
}
925+
918926
TNode<UintPtrT> CodeAssembler::ChangeFloat64ToUintPtr(
919927
SloppyTNode<Float64T> value) {
920928
if (raw_assembler()->machine()->Is64()) {

src/compiler/code-assembler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ class V8_EXPORT_PRIVATE CodeAssembler {
916916

917917
// Changes a double to an inptr_t for pointer arithmetic outside of Smi range.
918918
// Assumes that the double can be exactly represented as an int.
919+
TNode<IntPtrT> ChangeFloat64ToIntPtr(TNode<Float64T> value);
919920
TNode<UintPtrT> ChangeFloat64ToUintPtr(SloppyTNode<Float64T> value);
920921
// Same in the opposite direction.
921922
TNode<Float64T> ChangeUintPtrToFloat64(TNode<UintPtrT> value);

src/compiler/effect-control-linearizer.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,11 +2493,11 @@ Node* EffectControlLinearizer::LowerCheckedTaggedToArrayIndex(
24932493
Node* value = node->InputAt(0);
24942494

24952495
auto if_not_smi = __ MakeDeferredLabel();
2496-
auto done = __ MakeLabel(MachineRepresentation::kWord32);
2496+
auto done = __ MakeLabel(MachineType::PointerRepresentation());
24972497

24982498
__ GotoIfNot(ObjectIsSmi(value), &if_not_smi);
2499-
// In the Smi case, just convert to int32.
2500-
__ Goto(&done, ChangeSmiToInt32(value));
2499+
// In the Smi case, just convert to intptr_t.
2500+
__ Goto(&done, ChangeSmiToIntPtr(value));
25012501

25022502
// In the non-Smi case, check the heap numberness, load the number and convert
25032503
// to int32.
@@ -2523,7 +2523,7 @@ Node* EffectControlLinearizer::LowerCheckedTaggedToArrayIndex(
25232523
is_string, frame_state);
25242524

25252525
MachineSignature::Builder builder(graph()->zone(), 1, 1);
2526-
builder.AddReturn(MachineType::Int32());
2526+
builder.AddReturn(MachineType::IntPtr());
25272527
builder.AddParam(MachineType::TaggedPointer());
25282528
Node* string_to_array_index_function =
25292529
__ ExternalConstant(ExternalReference::string_to_array_index_function());

src/compiler/machine-graph-verifier.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class MachineRepresentationInferrer {
283283
case IrOpcode::kInt64Constant:
284284
case IrOpcode::kRelocatableInt64Constant:
285285
case IrOpcode::kBitcastFloat64ToInt64:
286+
case IrOpcode::kChangeFloat64ToInt64:
286287
case IrOpcode::kChangeFloat64ToUint64:
287288
MACHINE_BINOP_64_LIST(LABEL) {
288289
representation_vector_[node->id()] =
@@ -511,6 +512,7 @@ class MachineRepresentationChecker {
511512
}
512513
break;
513514
case IrOpcode::kFloat64SilenceNaN:
515+
case IrOpcode::kChangeFloat64ToInt64:
514516
case IrOpcode::kChangeFloat64ToUint64:
515517
MACHINE_FLOAT64_UNOP_LIST(LABEL) {
516518
CheckValueInputForFloat64Op(node, 0);

src/compiler/operation-typer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ Type OperationTyper::CheckBounds(Type index, Type length) {
12611261
index = Type::Union(index, cache_->kSingletonZero, zone());
12621262
}
12631263
if (index.Maybe(Type::String())) {
1264-
index = Type::Union(index, cache_->kUnsigned31, zone());
1264+
index = Type::Union(index, cache_->kIntPtr, zone());
12651265
}
12661266
return Type::Intersect(index, mask, zone());
12671267
}

0 commit comments

Comments
 (0)