Commit 5c16cac9 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Int64Lowering of Word64Clz.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#34809}
parent 33c08596
......@@ -4,6 +4,7 @@
#include "src/compiler/int64-lowering.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/diamond.h"
#include "src/compiler/graph.h"
#include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h"
......@@ -522,6 +523,24 @@ void Int64Lowering::LowerNode(Node* node) {
break;
}
// kExprI64Clz:
case IrOpcode::kWord64Clz: {
DCHECK(node->InputCount() == 1);
Node* input = node->InputAt(0);
Diamond d(
graph(), common(),
graph()->NewNode(machine()->Word32Equal(), GetReplacementHigh(input),
graph()->NewNode(common()->Int32Constant(0))));
Node* low_node = d.Phi(
MachineRepresentation::kWord32,
graph()->NewNode(machine()->Int32Add(),
graph()->NewNode(machine()->Word32Clz(),
GetReplacementLow(input)),
graph()->NewNode(common()->Int32Constant(32))),
graph()->NewNode(machine()->Word32Clz(), GetReplacementHigh(input)));
ReplaceNode(node, low_node, graph()->NewNode(common()->Int32Constant(0)));
break;
}
// kExprI64Ctz:
case IrOpcode::kWord64Popcnt: {
DCHECK(node->InputCount() == 1);
......
......@@ -472,12 +472,12 @@ const Operator* MachineOperatorBuilder::CheckedStore(
return nullptr;
}
// On 32 bit platforms we need to get a reference to a Word64Popcnt operator for
// later lowering, even though 32 bit platforms don't support Word64Popcnt.
// On 32 bit platforms we need to get a reference to optional operators of
// 64-bit instructions for later Int64Lowering, even though 32 bit platforms
// don't support the original 64-bit instruction.
const Operator* MachineOperatorBuilder::Word64PopcntPlaceholder() {
return &cache_.kWord64Popcnt;
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -838,6 +838,9 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input) {
op = m->BitcastFloat64ToInt64();
break;
// kExprI64Clz:
case wasm::kExprI64Clz:
op = m->Word64Clz();
break;
// kExprI64Ctz:
// kExprI64Popcnt:
case wasm::kExprI64Popcnt: {
......@@ -900,9 +903,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::kExprI64Clz:
op = m->Word64Clz();
break;
case wasm::kExprI64Ctz: {
if (m->Word64Ctz().IsSupported()) {
op = m->Word64Ctz().op();
......
......@@ -69,7 +69,7 @@
V(I64GeS, true) \
V(I64GtU, true) \
V(I64GeU, true) \
V(I64Clz, false) \
V(I64Clz, true) \
V(I64Ctz, false) \
V(I64Popcnt, !MIPS_OR_X87) \
V(I32ConvertI64, true) \
......
......@@ -567,6 +567,28 @@ TEST_F(Int64LoweringTest, I64ReinterpretF64) {
start(), start()));
}
// kExprI64Clz:
TEST_F(Int64LoweringTest, I64Clz) {
LowerGraph(graph()->NewNode(machine()->Word64Clz(), Int64Constant(value(0))),
MachineRepresentation::kWord64);
Capture<Node*> branch_capture;
Matcher<Node*> branch_matcher = IsBranch(
IsWord32Equal(IsInt32Constant(high_word_value(0)), IsInt32Constant(0)),
start());
EXPECT_THAT(
graph()->end()->InputAt(1),
IsReturn2(
IsPhi(MachineRepresentation::kWord32,
IsInt32Add(IsWord32Clz(IsInt32Constant(low_word_value(0))),
IsInt32Constant(32)),
IsWord32Clz(IsInt32Constant(high_word_value(0))),
IsMerge(
IsIfTrue(AllOf(CaptureEq(&branch_capture), branch_matcher)),
IsIfFalse(
AllOf(CaptureEq(&branch_capture), branch_matcher)))),
IsInt32Constant(0), start(), start()));
}
// kExprI64Ctz:
// kExprI64Popcnt:
......
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