Commit 19418d76 authored by Benedikt Meurer's avatar Benedikt Meurer

[x64] Fix optimization for certain checked load/stores.

BUG=chromium:439743
LOG=y
TEST=mjsunit
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/733893008

Cr-Commit-Position: refs/heads/master@{#25731}
parent a068503b
This diff is collapsed.
......@@ -230,12 +230,21 @@ void InstructionSelector::VisitCheckedLoad(Node* node) {
UNREACHABLE();
return;
}
InstructionOperand* offset_operand = g.UseRegister(offset);
if (offset->opcode() == IrOpcode::kInt32Add && CanCover(node, offset)) {
Int32Matcher mlength(length);
Int32BinopMatcher moffset(offset);
if (mlength.HasValue() && moffset.right().HasValue() &&
mlength.Value() >= moffset.right().Value()) {
Emit(opcode, g.DefineAsRegister(node), g.UseRegister(buffer),
g.UseRegister(moffset.left().node()),
g.UseImmediate(moffset.right().node()), g.UseImmediate(length));
return;
}
}
InstructionOperand* length_operand =
g.CanBeImmediate(length) ? g.UseImmediate(length) : g.UseRegister(length);
Emit(opcode | AddressingModeField::encode(kMode_MR1),
g.DefineAsRegister(node), offset_operand, length_operand,
g.UseRegister(buffer), offset_operand);
Emit(opcode, g.DefineAsRegister(node), g.UseRegister(buffer),
g.UseRegister(offset), g.TempImmediate(0), length_operand);
}
......@@ -269,11 +278,22 @@ void InstructionSelector::VisitCheckedStore(Node* node) {
}
InstructionOperand* value_operand =
g.CanBeImmediate(value) ? g.UseImmediate(value) : g.UseRegister(value);
InstructionOperand* offset_operand = g.UseRegister(offset);
if (offset->opcode() == IrOpcode::kInt32Add && CanCover(node, offset)) {
Int32Matcher mlength(length);
Int32BinopMatcher moffset(offset);
if (mlength.HasValue() && moffset.right().HasValue() &&
mlength.Value() >= moffset.right().Value()) {
Emit(opcode, nullptr, g.UseRegister(buffer),
g.UseRegister(moffset.left().node()),
g.UseImmediate(moffset.right().node()), g.UseImmediate(length),
value_operand);
return;
}
}
InstructionOperand* length_operand =
g.CanBeImmediate(length) ? g.UseImmediate(length) : g.UseRegister(length);
Emit(opcode | AddressingModeField::encode(kMode_MR1), nullptr, offset_operand,
length_operand, value_operand, g.UseRegister(buffer), offset_operand);
Emit(opcode, nullptr, g.UseRegister(buffer), g.UseRegister(offset),
g.TempImmediate(0), length_operand, value_operand);
}
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var stdlib = this;
var buffer = new ArrayBuffer(64 * 1024);
var foreign = {}
var m = (function Module(stdlib, foreign, heap) {
"use asm";
var MEM32 = new stdlib.Float32Array(heap);
function load(i) {
i = i|0;
i = +MEM32[i >> 2];
return i;
}
function store(i, v) {
i = i|0;
v = +v;
MEM32[i >> 2] = v;
}
function load8(i) {
i = i|0;
i = +MEM32[i + 8 >> 2];
return i;
}
function store8(i, v) {
i = i|0;
v = +v;
MEM32[i + 8 >> 2] = v;
}
return { load: load, store: store, load8: load8, store8: store8 };
})(stdlib, foreign, buffer);
assertEquals(NaN, m.load(-8));
assertEquals(NaN, m.load8(-16));
m.store(0, 42.0);
assertEquals(42.0, m.load8(-8));
m.store8(-8, 99.0);
assertEquals(99.0, m.load(0));
assertEquals(99.0, m.load8(-8));
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var stdlib = this;
var buffer = new ArrayBuffer(64 * 1024);
var foreign = {}
var m = (function Module(stdlib, foreign, heap) {
"use asm";
var MEM64 = new stdlib.Float64Array(heap);
function load(i) {
i = i|0;
i = +MEM64[i >> 3];
return i;
}
function store(i, v) {
i = i|0;
v = +v;
MEM64[i >> 3] = v;
}
function load8(i) {
i = i|0;
i = +MEM64[i + 8 >> 3];
return i;
}
function store8(i, v) {
i = i|0;
v = +v;
MEM64[i + 8 >> 3] = v;
}
return { load: load, store: store, load8: load8, store8: store8 };
})(stdlib, foreign, buffer);
assertEquals(NaN, m.load(-8));
assertEquals(NaN, m.load8(-16));
m.store(0, 42.0);
assertEquals(42.0, m.load8(-8));
m.store8(-8, 99.0);
assertEquals(99.0, m.load(0));
assertEquals(99.0, m.load8(-8));
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var stdlib = this;
var buffer = new ArrayBuffer(64 * 1024);
var foreign = {}
var m = (function Module(stdlib, foreign, heap) {
"use asm";
var MEM16 = new stdlib.Int16Array(heap);
function load(i) {
i = i|0;
i = MEM16[i >> 1]|0;
return i;
}
function store(i, v) {
i = i|0;
v = v|0;
MEM16[i >> 1] = v;
}
function load8(i) {
i = i|0;
i = MEM16[i + 8 >> 1]|0;
return i;
}
function store8(i, v) {
i = i|0;
v = v|0;
MEM16[i + 8 >> 1] = v;
}
return { load: load, store: store, load8: load8, store8: store8 };
})(stdlib, foreign, buffer);
assertEquals(0, m.load(-8));
assertEquals(0, m.load8(-16));
m.store(0, 42);
assertEquals(42, m.load8(-8));
m.store8(-8, 99);
assertEquals(99, m.load(0));
assertEquals(99, m.load8(-8));
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var stdlib = this;
var buffer = new ArrayBuffer(64 * 1024);
var foreign = {}
var m = (function Module(stdlib, foreign, heap) {
"use asm";
var MEM32 = new stdlib.Int32Array(heap);
function load(i) {
i = i|0;
i = MEM32[i >> 2]|0;
return i;
}
function store(i, v) {
i = i|0;
v = v|0;
MEM32[i >> 2] = v;
}
function load8(i) {
i = i|0;
i = MEM32[i + 8 >> 2]|0;
return i;
}
function store8(i, v) {
i = i|0;
v = v|0;
MEM32[i + 8 >> 2] = v;
}
return { load: load, store: store, load8: load8, store8: store8 };
})(stdlib, foreign, buffer);
assertEquals(0, m.load(-8));
assertEquals(0, m.load8(-16));
m.store(0, 42);
assertEquals(42, m.load8(-8));
m.store8(-8, 99);
assertEquals(99, m.load(0));
assertEquals(99, m.load8(-8));
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var stdlib = this;
var buffer = new ArrayBuffer(64 * 1024);
var foreign = {}
var m = (function Module(stdlib, foreign, heap) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
function load(i) {
i = i|0;
i = MEM8[i >> 0]|0;
return i;
}
function store(i, v) {
i = i|0;
v = v|0;
MEM8[i >> 0] = v;
}
function load8(i) {
i = i|0;
i = MEM8[i + 8 >> 0]|0;
return i;
}
function store8(i, v) {
i = i|0;
v = v|0;
MEM8[i + 8 >> 0] = v;
}
return { load: load, store: store, load8: load8, store8: store8 };
})(stdlib, foreign, buffer);
assertEquals(0, m.load(-8));
assertEquals(0, m.load8(-16));
m.store(0, 42);
assertEquals(42, m.load8(-8));
m.store8(-8, 99);
assertEquals(99, m.load(0));
assertEquals(99, m.load8(-8));
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