[wasm] Int64Lowering of I64XConvertI32.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#34629}
This commit is contained in:
ahaas 2016-03-09 08:20:59 -08:00 committed by Commit bot
parent 8340f52f98
commit d7ddd35c29
4 changed files with 89 additions and 11 deletions

View File

@ -356,8 +356,31 @@ void Int64Lowering::LowerNode(Node* node) {
}
// kExprI64SConvertI32:
// kExprI64UConvertI32:
case IrOpcode::kChangeInt32ToInt64: {
DCHECK(node->InputCount() == 1);
Node* input = node->InputAt(0);
if (HasReplacementLow(input)) {
input = GetReplacementLow(input);
}
// We use SAR to preserve the sign in the high word.
ReplaceNode(
node, input,
graph()->NewNode(machine()->Word32Sar(), input,
graph()->NewNode(common()->Int32Constant(31))));
node->NullAllInputs();
break;
}
// kExprI64UConvertI32: {
case IrOpcode::kChangeUint32ToUint64: {
DCHECK(node->InputCount() == 1);
Node* input = node->InputAt(0);
if (HasReplacementLow(input)) {
input = GetReplacementLow(input);
}
ReplaceNode(node, input, graph()->NewNode(common()->Int32Constant(0)));
node->NullAllInputs();
break;
}
// kExprF64ReinterpretI64:
// kExprI64ReinterpretF64:

View File

@ -846,13 +846,18 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input) {
case wasm::kExprF64Log: {
return BuildF64Log(input);
}
// kExprI32ConvertI64:
case wasm::kExprI32ConvertI64:
op = m->TruncateInt64ToInt32();
break;
// kExprI32ConvertI64:
// kExprI64SConvertI32:
case wasm::kExprI64SConvertI32:
op = m->ChangeInt32ToInt64();
break;
// kExprI64UConvertI32:
case wasm::kExprI64UConvertI32:
op = m->ChangeUint32ToUint64();
break;
// kExprF64ReinterpretI64:
// kExprI64ReinterpretF64:
// kExprI64Clz:
@ -893,12 +898,6 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input) {
#if WASM_64
// Opcodes only supported on 64-bit platforms.
// TODO(titzer): query the machine operator builder here instead of #ifdef.
case wasm::kExprI64SConvertI32:
op = m->ChangeInt32ToInt64();
break;
case wasm::kExprI64UConvertI32:
op = m->ChangeUint32ToUint64();
break;
case wasm::kExprI64SConvertF32: {
Node* trunc = graph()->NewNode(m->TryTruncateFloat32ToInt64(), input);
Node* result =

View File

@ -170,7 +170,18 @@ TEST(Run_WasmI32ConvertI64) {
}
}
// kExprI64SConvertI32:
TEST(Run_WasmI64SConvertI32) {
WasmRunner<int64_t> r(MachineType::Int32());
BUILD(r, WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); }
}
// kExprI64UConvertI32:
TEST(Run_WasmI64UConvertI32) {
WasmRunner<int64_t> r(MachineType::Uint32());
BUILD(r, WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0)));
FOR_UINT32_INPUTS(i) { CHECK_EQ(static_cast<uint64_t>(*i), r.Call(*i)); }
}
// kExprF64ReinterpretI64:
// kExprI64ReinterpretF64:

View File

@ -396,8 +396,53 @@ TEST_F(Int64LoweringTest, I32ConvertI64) {
IsReturn(IsInt32Constant(low_word_value(0)), start(), start()));
}
// kExprI64SConvertI32:
// kExprI64UConvertI32:
TEST_F(Int64LoweringTest, I64SConvertI32) {
LowerGraph(graph()->NewNode(machine()->ChangeInt32ToInt64(),
Int32Constant(low_word_value(0))),
MachineRepresentation::kWord64);
EXPECT_THAT(graph()->end()->InputAt(1),
IsReturn2(IsInt32Constant(low_word_value(0)),
IsWord32Sar(IsInt32Constant(low_word_value(0)),
IsInt32Constant(31)),
start(), start()));
}
TEST_F(Int64LoweringTest, I64SConvertI32_2) {
LowerGraph(
graph()->NewNode(machine()->ChangeInt32ToInt64(),
graph()->NewNode(machine()->TruncateInt64ToInt32(),
Int64Constant(value(0)))),
MachineRepresentation::kWord64);
EXPECT_THAT(graph()->end()->InputAt(1),
IsReturn2(IsInt32Constant(low_word_value(0)),
IsWord32Sar(IsInt32Constant(low_word_value(0)),
IsInt32Constant(31)),
start(), start()));
}
// kExprI64UConvertI32:
TEST_F(Int64LoweringTest, I64UConvertI32) {
LowerGraph(graph()->NewNode(machine()->ChangeUint32ToUint64(),
Int32Constant(low_word_value(0))),
MachineRepresentation::kWord64);
EXPECT_THAT(graph()->end()->InputAt(1),
IsReturn2(IsInt32Constant(low_word_value(0)), IsInt32Constant(0),
start(), start()));
}
TEST_F(Int64LoweringTest, I64UConvertI32_2) {
LowerGraph(
graph()->NewNode(machine()->ChangeUint32ToUint64(),
graph()->NewNode(machine()->TruncateInt64ToInt32(),
Int64Constant(value(0)))),
MachineRepresentation::kWord64);
EXPECT_THAT(graph()->end()->InputAt(1),
IsReturn2(IsInt32Constant(low_word_value(0)), IsInt32Constant(0),
start(), start()));
}
// kExprF64ReinterpretI64:
// kExprI64ReinterpretF64: