Commit c58497c0 authored by Ng Zhi An's avatar Ng Zhi An Committed by V8 LUCI CQ

[wasm] Optimize when Select's cond is a constant

Handle all 4 selects that wasm-compiler generates.

Also modify unittest to allow optional operations (select
operations are not supported on all archs).

Bug: v8:12136
Change-Id: Ia54d7a71cffaa1c5cc8203520a1f3d812997bbb1
Fixed: v8:12136
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3119991Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76539}
parent 1a7584fe
......@@ -947,6 +947,20 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
return ReduceWord64Comparisons(node);
}
case IrOpcode::kFloat32Select:
case IrOpcode::kFloat64Select:
case IrOpcode::kWord32Select:
case IrOpcode::kWord64Select: {
Int32Matcher match(node->InputAt(0));
if (match.HasResolvedValue()) {
if (match.Is(0)) {
return Replace(node->InputAt(2));
} else {
return Replace(node->InputAt(1));
}
}
break;
}
default:
break;
}
......@@ -2061,7 +2075,6 @@ bool IsFloat64RepresentableAsFloat32(const Float64Matcher& m) {
} // namespace
Reduction MachineOperatorReducer::ReduceFloat64Compare(Node* node) {
DCHECK(IrOpcode::kFloat64Equal == node->opcode() ||
IrOpcode::kFloat64LessThan == node->opcode() ||
......
......@@ -3,12 +3,15 @@
// found in the LICENSE file.
#include "src/compiler/machine-operator-reducer.h"
#include <limits>
#include "src/base/bits.h"
#include "src/base/division-by-constant.h"
#include "src/base/ieee754.h"
#include "src/base/overflowing-math.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/typer.h"
#include "src/numbers/conversions-inl.h"
#include "test/unittests/compiler/graph-unittest.h"
......@@ -29,7 +32,8 @@ class MachineOperatorReducerTest : public GraphTest {
public:
explicit MachineOperatorReducerTest(int num_parameters = 2)
: GraphTest(num_parameters),
machine_(zone()),
machine_(zone(), MachineType::PointerRepresentation(),
MachineOperatorBuilder::kAllOptionalOps),
common_(zone()),
javascript_(zone()),
jsgraph_(isolate(), graph(), &common_, &javascript_, nullptr,
......@@ -2880,6 +2884,27 @@ TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32SarAndWord32Shl) {
}
}
TEST_F(MachineOperatorReducerTest, Select) {
static const std::vector<const Operator*> ops = {
machine()->Float32Select().op(), machine()->Float64Select().op(),
machine()->Word32Select().op(), machine()->Word64Select().op()};
TRACED_FOREACH(const Operator*, op, ops) {
Node* arg0 = Parameter(0);
Node* arg1 = Parameter(1);
Node* select_true = graph()->NewNode(op, Int32Constant(1), arg0, arg1);
Reduction r_true = Reduce(select_true);
ASSERT_TRUE(r_true.Changed());
EXPECT_THAT(r_true.replacement(), IsParameter(0));
Node* select_false = graph()->NewNode(op, Int32Constant(0), arg0, arg1);
Reduction r_false = Reduce(select_false);
ASSERT_TRUE(r_false.Changed());
EXPECT_THAT(r_false.replacement(), IsParameter(1));
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
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