Commit d61c64b2 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm] Enable loop unrolling

We experimentally globally enable loop unrolling for wasm code. This
might be reverted based on the results of perf bots.

Additional change: Add LoopExitValue to Int64Lowering, plus a small
simplification.

Bug: v8:11298

Change-Id: Iaf2829e80f948d70c5fb6ed7c974db7f59265fa3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2718611Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73072}
parent 6fe59c0c
......@@ -174,13 +174,8 @@ void Int64Lowering::LowerNode(Node* node) {
}
case IrOpcode::kLoad:
case IrOpcode::kUnalignedLoad: {
MachineRepresentation rep;
if (node->opcode() == IrOpcode::kLoad) {
rep = LoadRepresentationOf(node->op()).representation();
} else {
DCHECK_EQ(IrOpcode::kUnalignedLoad, node->opcode());
rep = LoadRepresentationOf(node->op()).representation();
}
MachineRepresentation rep =
LoadRepresentationOf(node->op()).representation();
if (rep == MachineRepresentation::kWord64) {
LowerMemoryBaseAndIndex(node);
......@@ -861,6 +856,21 @@ void Int64Lowering::LowerNode(Node* node) {
}
break;
}
case IrOpcode::kLoopExitValue: {
MachineRepresentation rep = LoopExitValueRepresentationOf(node->op());
if (rep == MachineRepresentation::kWord64) {
Node* low_node = graph()->NewNode(
common()->LoopExitValue(MachineRepresentation::kWord32),
GetReplacementLow(node->InputAt(0)), node->InputAt(1));
Node* high_node = graph()->NewNode(
common()->LoopExitValue(MachineRepresentation::kWord32),
GetReplacementHigh(node->InputAt(0)), node->InputAt(1));
ReplaceNode(node, low_node, high_node);
} else {
DefaultLowering(node);
}
break;
}
case IrOpcode::kWord64ReverseBytes: {
Node* input = node->InputAt(0);
ReplaceNode(node,
......
......@@ -933,7 +933,7 @@ DEFINE_BOOL(wasm_stack_checks, true,
DEFINE_BOOL(wasm_math_intrinsics, true,
"intrinsify some Math imports into wasm")
DEFINE_BOOL(wasm_loop_unrolling, false,
DEFINE_BOOL(wasm_loop_unrolling, true,
"enable loop unrolling for wasm functions (experimental)")
DEFINE_BOOL(wasm_trap_handler, true,
"use signal handlers to catch out of bounds memory access in wasm"
......
......@@ -988,6 +988,22 @@ TEST_F(Int64LoweringTest, LoopCycle) {
LowerGraph(load, MachineRepresentation::kWord64);
}
TEST_F(Int64LoweringTest, LoopExitValue) {
Node* loop_header = graph()->NewNode(common()->Loop(1), graph()->start());
Node* loop_exit =
graph()->NewNode(common()->LoopExit(), loop_header, loop_header);
Node* exit =
graph()->NewNode(common()->LoopExitValue(MachineRepresentation::kWord64),
Int64Constant(value(2)), loop_exit);
LowerGraph(exit, MachineRepresentation::kWord64);
EXPECT_THAT(graph()->end()->InputAt(1),
IsReturn2(IsLoopExitValue(MachineRepresentation::kWord32,
IsInt32Constant(low_word_value(2))),
IsLoopExitValue(MachineRepresentation::kWord32,
IsInt32Constant(high_word_value(2))),
start(), start()));
}
TEST_F(Int64LoweringTest, WasmBigIntSpecialCaseBigIntToI64) {
Node* target = Int32Constant(1);
Node* context = Int32Constant(2);
......
......@@ -102,6 +102,36 @@ class IsBranchMatcher final : public TestNodeMatcher {
const Matcher<Node*> control_matcher_;
};
class IsLoopExitValueMatcher final : public TestNodeMatcher {
public:
IsLoopExitValueMatcher(const Matcher<MachineRepresentation>& rep_matcher,
const Matcher<Node*>& value_matcher)
: TestNodeMatcher(IrOpcode::kLoopExitValue),
rep_matcher_(rep_matcher),
value_matcher_(value_matcher) {}
void DescribeTo(std::ostream* os) const final {
TestNodeMatcher::DescribeTo(os);
*os << ") whose rep (";
rep_matcher_.DescribeTo(os);
*os << " and value (";
value_matcher_.DescribeTo(os);
*os << ")";
}
bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
return (TestNodeMatcher::MatchAndExplain(node, listener) &&
PrintMatchAndExplain(LoopExitValueRepresentationOf(node->op()),
"representation", rep_matcher_, listener)) &&
PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "value",
value_matcher_, listener);
}
private:
const Matcher<MachineRepresentation> rep_matcher_;
const Matcher<Node*> value_matcher_;
};
class IsSwitchMatcher final : public TestNodeMatcher {
public:
IsSwitchMatcher(const Matcher<Node*>& value_matcher,
......@@ -1556,6 +1586,10 @@ Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
control1_matcher, control2_matcher));
}
Matcher<Node*> IsLoopExitValue(const Matcher<MachineRepresentation> rep_matcher,
const Matcher<Node*>& value_matcher) {
return MakeMatcher(new IsLoopExitValueMatcher(rep_matcher, value_matcher));
}
Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher) {
return MakeMatcher(new IsControl1Matcher(IrOpcode::kIfTrue, control_matcher));
......
......@@ -58,6 +58,8 @@ Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
const Matcher<Node*>& control1_matcher,
const Matcher<Node*>& control2_matcher);
Matcher<Node*> IsLoopExitValue(const Matcher<MachineRepresentation> rep_matcher,
const Matcher<Node*>& value_matcher);
Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher);
Matcher<Node*> IsIfFalse(const Matcher<Node*>& control_matcher);
Matcher<Node*> IsIfSuccess(const Matcher<Node*>& control_matcher);
......
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