Commit 7205f6ee authored by Benedikt Meurer's avatar Benedikt Meurer

[turbofan] Avoid useless bit masking in typed lowering.

There's no need to apply the 0x1f mask to right hand sides of shifts if
the input is already in range [0,31].

TEST=cctest,unittests
R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25313}
parent c513297f
......@@ -36,6 +36,8 @@ JSTypedLowering::JSTypedLowering(JSGraph* jsgraph)
Handle<Object> one = factory->NewNumber(1.0);
zero_range_ = Type::Range(zero, zero, zone());
one_range_ = Type::Range(one, one, zone());
Handle<Object> thirtyone = factory->NewNumber(31.0);
zero_thirtyone_range_ = Type::Range(zero, thirtyone, zone());
}
......@@ -79,8 +81,12 @@ class JSBinopReduction {
void ConvertInputsForShift(bool left_signed) {
node_->ReplaceInput(0, ConvertToI32(left_signed, left()));
Node* rnum = ConvertToI32(false, right());
node_->ReplaceInput(1, graph()->NewNode(machine()->Word32And(), rnum,
jsgraph()->Int32Constant(0x1F)));
Type* rnum_type = NodeProperties::GetBounds(rnum).upper;
if (!rnum_type->Is(lowering_->zero_thirtyone_range_)) {
rnum = graph()->NewNode(machine()->Word32And(), rnum,
jsgraph()->Int32Constant(0x1F));
}
node_->ReplaceInput(1, rnum);
}
void SwapInputs() {
......
......@@ -58,6 +58,7 @@ class JSTypedLowering FINAL : public Reducer {
SimplifiedOperatorBuilder simplified_;
Type* zero_range_;
Type* one_range_;
Type* zero_thirtyone_range_;
};
} // namespace compiler
......
......@@ -327,9 +327,13 @@ TEST(Int32BitwiseShifts) {
CheckToI32(p0, r0, R.signedness[k]);
R.CheckPureBinop(IrOpcode::kWord32And, r1);
CheckToI32(p1, r1->InputAt(0), R.signedness[k + 1]);
R.CheckInt32Constant(0x1F, r1->InputAt(1));
if (r1->opcode() == IrOpcode::kWord32And) {
R.CheckPureBinop(IrOpcode::kWord32And, r1);
CheckToI32(p1, r1->InputAt(0), R.signedness[k + 1]);
R.CheckInt32Constant(0x1F, r1->InputAt(1));
} else {
CheckToI32(p1, r1, R.signedness[k]);
}
}
}
}
......
......@@ -108,6 +108,105 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumberAndBoolean) {
}
// -----------------------------------------------------------------------------
// JSShiftLeft
TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) {
Node* const lhs = Parameter(Type::Signed32());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FORRANGE(int32_t, rhs, 0, 31) {
Reduction r =
Reduce(graph()->NewNode(javascript()->ShiftLeft(), lhs,
NumberConstant(rhs), context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsWord32Shl(lhs, IsNumberConstant(rhs)));
}
}
TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndUnsigned32) {
Node* const lhs = Parameter(Type::Signed32());
Node* const rhs = Parameter(Type::Unsigned32());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Reduction r = Reduce(graph()->NewNode(javascript()->ShiftLeft(), lhs, rhs,
context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsWord32Shl(lhs, IsWord32And(rhs, IsInt32Constant(0x1f))));
}
// -----------------------------------------------------------------------------
// JSShiftRight
TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) {
Node* const lhs = Parameter(Type::Signed32());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FORRANGE(int32_t, rhs, 0, 31) {
Reduction r =
Reduce(graph()->NewNode(javascript()->ShiftRight(), lhs,
NumberConstant(rhs), context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsWord32Sar(lhs, IsNumberConstant(rhs)));
}
}
TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndUnsigned32) {
Node* const lhs = Parameter(Type::Signed32());
Node* const rhs = Parameter(Type::Unsigned32());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRight(), lhs, rhs,
context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsWord32Sar(lhs, IsWord32And(rhs, IsInt32Constant(0x1f))));
}
// -----------------------------------------------------------------------------
// JSShiftRightLogical
TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithUnsigned32AndConstant) {
Node* const lhs = Parameter(Type::Unsigned32());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FORRANGE(int32_t, rhs, 0, 31) {
Reduction r =
Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs,
NumberConstant(rhs), context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsWord32Shr(lhs, IsNumberConstant(rhs)));
}
}
TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithUnsigned32AndUnsigned32) {
Node* const lhs = Parameter(Type::Unsigned32());
Node* const rhs = Parameter(Type::Unsigned32());
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs,
rhs, context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f))));
}
// -----------------------------------------------------------------------------
// JSLoadProperty
......
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