Revision: 24716
Author: [email protected]
Date: Mon Oct 20 06:25:41 2014 UTC
Log: [turbofan] Skip bounds checks for positive indices only.
TEST=unittests,mjsunit/asm/int32array-constant-key
[email protected]
Review URL: https://codereview.chromium.org/647773004
https://code.google.com/p/v8/source/detail?r=24716
Modified:
/branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc
/branches/bleeding_edge/test/mjsunit/asm/int32array-constant-key.js
/branches/bleeding_edge/test/unittests/compiler/simplified-operator-reducer-unittest.cc
=======================================
--- /branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc Fri
Oct 17 09:35:45 2014 UTC
+++ /branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc Mon
Oct 20 06:25:41 2014 UTC
@@ -106,7 +106,7 @@
NumericValueMatcher mlength(node->InputAt(2));
if (mkey.HasValue() && mlength.HasValue()) {
// Skip the typed array bounds check if key and length are
constant.
- if (mkey.Value() < mlength.Value()) {
+ if (mkey.Value() >= 0 && mkey.Value() < mlength.Value()) {
access.bounds_check = kNoBoundsCheck;
node->set_op(simplified()->LoadElement(access));
return Changed(node);
@@ -122,7 +122,7 @@
NumericValueMatcher mlength(node->InputAt(2));
if (mkey.HasValue() && mlength.HasValue()) {
// Skip the typed array bounds check if key and length are
constant.
- if (mkey.Value() < mlength.Value()) {
+ if (mkey.Value() >= 0 && mkey.Value() < mlength.Value()) {
access.bounds_check = kNoBoundsCheck;
node->set_op(simplified()->StoreElement(access));
return Changed(node);
=======================================
--- /branches/bleeding_edge/test/mjsunit/asm/int32array-constant-key.js Fri
Oct 17 09:35:45 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/asm/int32array-constant-key.js Mon
Oct 20 06:25:41 2014 UTC
@@ -5,28 +5,58 @@
function Module(stdlib, foreign, heap) {
"use asm";
var MEM32 = new stdlib.Int32Array(heap);
+ function loadm4194304() {
+ return MEM32[-4194304];
+ }
+ function loadm0() {
+ return MEM32[-0];
+ }
function load0() {
return MEM32[0];
}
function load4() {
return MEM32[4];
}
+ function storem4194304(v) {
+ MEM32[-4194304] = v;
+ }
+ function storem0(v) {
+ MEM32[-0] = v;
+ }
function store0(v) {
MEM32[0] = v;
}
function store4(v) {
MEM32[4] = v;
}
- return { load0: load0, store0: store0, load4: load4, store4: store4 };
+ return { loadm4194304: loadm4194304, storem4194304: storem4194304,
+ loadm0: loadm0, storem0: storem0, load0: load0, store0: store0,
+ load4: load4, store4: store4 };
}
var m = Module(this, {}, new ArrayBuffer(4));
+assertEquals(undefined, m.loadm4194304());
+assertEquals(0, m.loadm0());
assertEquals(0, m.load0());
assertEquals(undefined, m.load4());
+m.storem4194304(123456789);
+assertEquals(undefined, m.loadm4194304());
+assertEquals(0, m.loadm0());
+assertEquals(0, m.load0());
+assertEquals(undefined, m.load4());
+m.storem0(987654321);
+assertEquals(undefined, m.loadm4194304());
+assertEquals(987654321, m.loadm0());
+assertEquals(987654321, m.load0());
+assertEquals(undefined, m.load4());
m.store0(0x12345678);
+assertEquals(undefined, m.loadm4194304());
+assertEquals(0x12345678, m.loadm0());
assertEquals(0x12345678, m.load0());
assertEquals(undefined, m.load4());
m.store4(43);
+assertEquals(undefined, m.loadm4194304());
+assertEquals(0x12345678, m.loadm0());
assertEquals(0x12345678, m.load0());
assertEquals(undefined, m.load4());
=======================================
---
/branches/bleeding_edge/test/unittests/compiler/simplified-operator-reducer-unittest.cc
Fri Oct 17 09:35:45 2014 UTC
+++
/branches/bleeding_edge/test/unittests/compiler/simplified-operator-reducer-unittest.cc
Mon Oct 20 06:25:41 2014 UTC
@@ -490,18 +490,46 @@
Node* const base = Parameter(0);
Node* const effect = graph()->start();
Node* const control = graph()->start();
- TRACED_FOREACH(double, key, kFloat64Values) {
- TRACED_FOREACH(int32_t, length, kInt32Values) {
- if (key < length) {
- Reduction r = Reduce(graph()->NewNode(
- simplified()->LoadElement(access), base, NumberConstant(key),
- Int32Constant(length), effect, control));
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(),
- IsLoadElement(access_nocheck, base,
IsNumberConstant(key),
- IsInt32Constant(length), effect,
control));
- }
- }
+ {
+ Node* const key = NumberConstant(-42.0);
+ Node* const length = NumberConstant(100.0);
+ Reduction r =
Reduce(graph()->NewNode(simplified()->LoadElement(access),
+ base, key, length, effect,
control));
+ ASSERT_FALSE(r.Changed());
+ }
+ {
+ Node* const key = NumberConstant(-0.0);
+ Node* const length = NumberConstant(1.0);
+ Reduction r =
Reduce(graph()->NewNode(simplified()->LoadElement(access),
+ base, key, length, effect,
control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsLoadElement(access_nocheck, base, key,
+ length, effect, control));
+ }
+ {
+ Node* const key = Int32Constant(0);
+ Node* const length = Int32Constant(1);
+ Reduction r =
Reduce(graph()->NewNode(simplified()->LoadElement(access),
+ base, key, length, effect,
control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsLoadElement(access_nocheck, base, key,
+ length, effect, control));
+ }
+ {
+ Node* const key = NumberConstant(42.2);
+ Node* const length = Int32Constant(128);
+ Reduction r =
Reduce(graph()->NewNode(simplified()->LoadElement(access),
+ base, key, length, effect,
control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsLoadElement(access_nocheck, base, key,
+ length, effect, control));
+ }
+ {
+ Node* const key = NumberConstant(39.2);
+ Node* const length = NumberConstant(32.0);
+ Reduction r =
Reduce(graph()->NewNode(simplified()->LoadElement(access),
+ base, key, length, effect,
control));
+ ASSERT_FALSE(r.Changed());
}
}
@@ -519,19 +547,54 @@
Node* const value = Parameter(1);
Node* const effect = graph()->start();
Node* const control = graph()->start();
- TRACED_FOREACH(int32_t, key, kInt32Values) {
- TRACED_FOREACH(double, length, kFloat64Values) {
- if (key < length) {
- Reduction r = Reduce(graph()->NewNode(
- simplified()->StoreElement(access), base, Int32Constant(key),
- NumberConstant(length), value, effect, control));
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(
- r.replacement(),
- IsStoreElement(access_nocheck, base, IsInt32Constant(key),
- IsNumberConstant(length), value, effect,
control));
- }
- }
+ {
+ Node* const key = NumberConstant(-72.1);
+ Node* const length = NumberConstant(0.0);
+ Reduction r =
+ Reduce(graph()->NewNode(simplified()->StoreElement(access), base,
key,
+ length, value, effect, control));
+ ASSERT_FALSE(r.Changed());
+ }
+ {
+ Node* const key = NumberConstant(-0.0);
+ Node* const length = Int32Constant(999);
+ Reduction r =
+ Reduce(graph()->NewNode(simplified()->StoreElement(access), base,
key,
+ length, value, effect, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsStoreElement(access_nocheck, base, key, length, value,
effect,
+ control));
+ }
+ {
+ Node* const key = Int32Constant(0);
+ Node* const length = Int32Constant(1);
+ Reduction r =
+ Reduce(graph()->NewNode(simplified()->StoreElement(access), base,
key,
+ length, value, effect, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsStoreElement(access_nocheck, base, key, length, value,
effect,
+ control));
+ }
+ {
+ Node* const key = NumberConstant(42.2);
+ Node* const length = Int32Constant(128);
+ Reduction r =
+ Reduce(graph()->NewNode(simplified()->StoreElement(access), base,
key,
+ length, value, effect, control));
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(),
+ IsStoreElement(access_nocheck, base, key, length, value,
effect,
+ control));
+ }
+ {
+ Node* const key = NumberConstant(39.2);
+ Node* const length = NumberConstant(32.0);
+ Reduction r =
+ Reduce(graph()->NewNode(simplified()->StoreElement(access), base,
key,
+ length, value, effect, control));
+ ASSERT_FALSE(r.Changed());
}
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.