diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc index 0f6f38cb0f..2f0497f503 100644 --- a/src/compiler/js-typed-lowering.cc +++ b/src/compiler/js-typed-lowering.cc @@ -388,10 +388,21 @@ Reduction JSTypedLowering::ReduceJSAdd(Node* node) { } +Reduction JSTypedLowering::ReduceJSModulus(Node* node) { + JSBinopReduction r(this, node); + if (r.BothInputsAre(Type::Number())) { + // JSModulus(x:number, x:number) => NumberModulus(x, y) + return r.ChangeToPureOperator(simplified()->NumberModulus(), + Type::Number()); + } + return NoChange(); +} + + Reduction JSTypedLowering::ReduceNumberBinop(Node* node, const Operator* numberOp) { JSBinopReduction r(this, node); - if (r.IsStrong()) { + if (r.IsStrong() || numberOp == simplified()->NumberModulus()) { if (r.BothInputsAre(Type::Number())) { return r.ChangeToPureOperator(numberOp, Type::Number()); } @@ -1469,7 +1480,7 @@ Reduction JSTypedLowering::Reduce(Node* node) { case IrOpcode::kJSDivide: return ReduceNumberBinop(node, simplified()->NumberDivide()); case IrOpcode::kJSModulus: - return ReduceNumberBinop(node, simplified()->NumberModulus()); + return ReduceJSModulus(node); case IrOpcode::kJSUnaryNot: return ReduceJSUnaryNot(node); case IrOpcode::kJSToBoolean: diff --git a/src/compiler/js-typed-lowering.h b/src/compiler/js-typed-lowering.h index fbd5c21422..ae9cbdd7ea 100644 --- a/src/compiler/js-typed-lowering.h +++ b/src/compiler/js-typed-lowering.h @@ -37,6 +37,7 @@ class JSTypedLowering final : public AdvancedReducer { friend class JSBinopReduction; Reduction ReduceJSAdd(Node* node); + Reduction ReduceJSModulus(Node* node); Reduction ReduceJSBitwiseOr(Node* node); Reduction ReduceJSMultiply(Node* node); Reduction ReduceJSComparison(Node* node); diff --git a/test/cctest/compiler/test-js-typed-lowering.cc b/test/cctest/compiler/test-js-typed-lowering.cc index 917deca148..058c0ee903 100644 --- a/test/cctest/compiler/test-js-typed-lowering.cc +++ b/test/cctest/compiler/test-js-typed-lowering.cc @@ -942,8 +942,6 @@ TEST(OrderNumberBinopEffects1) { R.simplified.NumberMultiply(), R.javascript.Divide(LanguageMode::SLOPPY), R.simplified.NumberDivide(), - R.javascript.Modulus(LanguageMode::SLOPPY), - R.simplified.NumberModulus(), }; for (size_t j = 0; j < arraysize(ops); j += 2) { @@ -974,8 +972,6 @@ TEST(OrderNumberBinopEffects2) { R.simplified.NumberMultiply(), R.javascript.Divide(LanguageMode::SLOPPY), R.simplified.NumberDivide(), - R.javascript.Modulus(LanguageMode::SLOPPY), - R.simplified.NumberModulus(), }; for (size_t j = 0; j < arraysize(ops); j += 2) {