Modified: trunk/Source/_javascript_Core/b3/B3ReduceStrength.cpp (247389 => 247390)
--- trunk/Source/_javascript_Core/b3/B3ReduceStrength.cpp 2019-07-12 16:59:22 UTC (rev 247389)
+++ trunk/Source/_javascript_Core/b3/B3ReduceStrength.cpp 2019-07-12 17:11:31 UTC (rev 247390)
@@ -651,6 +651,39 @@
break;
}
+ // Turn this: Sub(Neg(value), value2)
+ // Into this: Neg(Add(value, value2))
+ if (m_value->child(0)->opcode() == Neg) {
+ replaceWithNew<Value>(Neg, m_value->origin(),
+ m_insertionSet.insert<Value>(m_index, Add, m_value->origin(), m_value->child(0)->child(0), m_value->child(1)));
+ break;
+ }
+
+ // Turn this: Sub(Sub(a, b), c)
+ // Into this: Sub(a, Add(b, c))
+ if (m_value->child(0)->opcode() == Sub) {
+ replaceWithNew<Value>(Sub, m_value->origin(), m_value->child(0)->child(0),
+ m_insertionSet.insert<Value>(m_index, Add, m_value->origin(), m_value->child(0)->child(1), m_value->child(1)));
+ break;
+ }
+
+ // Turn this: Sub(a, Sub(b, c))
+ // Into this: Add(Sub(a, b), c)
+ if (m_value->child(1)->opcode() == Sub) {
+ replaceWithNew<Value>(Add, m_value->origin(),
+ m_insertionSet.insert<Value>(m_index, Sub, m_value->origin(), m_value->child(0), m_value->child(1)->child(0)),
+ m_value->child(1)->child(1));
+ break;
+ }
+
+ // Turn this: Sub(Add(a, b), c)
+ // Into this: Add(a, Sub(b, c))
+ if (m_value->child(0)->opcode() == Add) {
+ replaceWithNew<Value>(Add, m_value->origin(), m_value->child(0)->child(0),
+ m_insertionSet.insert<Value>(m_index, Sub, m_value->origin(), m_value->child(0)->child(1), m_value->child(1)));
+ break;
+ }
+
if (handleMulDistributivity())
break;
}
Modified: trunk/Source/_javascript_Core/b3/testb3.cpp (247389 => 247390)
--- trunk/Source/_javascript_Core/b3/testb3.cpp 2019-07-12 16:59:22 UTC (rev 247389)
+++ trunk/Source/_javascript_Core/b3/testb3.cpp 2019-07-12 17:11:31 UTC (rev 247390)
@@ -2190,6 +2190,69 @@
CHECK(compileAndRun<int>(proc, a) == -a - 1);
}
+void testSubSub(int a, int b, int c)
+{
+ Procedure proc;
+ BasicBlock* root = proc.addBlock();
+ root->appendNewControlValue(
+ proc, Return, Origin(),
+ root->appendNew<Value>(
+ proc, Sub, Origin(),
+ root->appendNew<Value>(proc, Sub, Origin(),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR2)));
+
+ CHECK(compileAndRun<int>(proc, a, b, c) == (a-b)-c);
+}
+
+void testSubSub2(int a, int b, int c)
+{
+ Procedure proc;
+ BasicBlock* root = proc.addBlock();
+ root->appendNewControlValue(
+ proc, Return, Origin(),
+ root->appendNew<Value>(
+ proc, Sub, Origin(),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
+ root->appendNew<Value>(proc, Sub, Origin(),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR2))));
+
+ CHECK(compileAndRun<int>(proc, a, b, c) == a-(b-c));
+}
+
+void testSubAdd(int a, int b, int c)
+{
+ Procedure proc;
+ BasicBlock* root = proc.addBlock();
+ root->appendNewControlValue(
+ proc, Return, Origin(),
+ root->appendNew<Value>(
+ proc, Sub, Origin(),
+ root->appendNew<Value>(proc, Add, Origin(),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR2)));
+
+ CHECK(compileAndRun<int>(proc, a, b, c) == (a+b)-c);
+}
+
+void testSubFirstNeg(int a, int b)
+{
+ Procedure proc;
+ BasicBlock* root = proc.addBlock();
+ root->appendNewControlValue(
+ proc, Return, Origin(),
+ root->appendNew<Value>(
+ proc, Sub, Origin(),
+ root->appendNew<Value>(proc, Neg, Origin(),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
+ root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)));
+
+ CHECK(compileAndRun<int>(proc, a, b) == (-a)-b);
+}
+
void testSubImmArg(int a, int b)
{
Procedure proc;
@@ -17457,6 +17520,11 @@
RUN_BINARY(testNegMulArgImm, int64Operands(), int64Operands());
RUN_TERNARY(testSubMulMulArgs, int64Operands(), int64Operands(), int64Operands());
+ RUN_TERNARY(testSubSub, int32Operands(), int32Operands(), int32Operands());
+ RUN_TERNARY(testSubSub2, int32Operands(), int32Operands(), int32Operands());
+ RUN_TERNARY(testSubAdd, int32Operands(), int32Operands(), int32Operands());
+ RUN_BINARY(testSubFirstNeg, int32Operands(), int32Operands());
+
RUN(testSubArgs32(1, 1));
RUN(testSubArgs32(1, 2));
RUN(testSubArgs32(13, -42));