Changeset 241126 in webkit
- Timestamp:
- Feb 7, 2019 10:36:36 AM (5 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r241117 r241126 1 2019-02-07 Robin Morisset <rmorisset@apple.com> 2 3 B3ReduceStrength: missing peephole optimizations for Neg and Sub 4 https://bugs.webkit.org/show_bug.cgi?id=194250 5 6 Reviewed by Saam Barati. 7 8 Adds the following optimizations for integers: 9 - Sub(x, x) => 0 10 Already covered by the test testSubArg 11 - Sub(x1, Neg(x2)) => Add (x1, x2) 12 Added test: testSubNeg 13 - Neg(Sub(x1, x2)) => Sub(x2, x1) 14 Added test: testNegSub 15 - Add(Neg(x1), x2) => Sub(x2, x1) 16 Added test: testAddNeg1 17 - Add(x1, Neg(x2)) => Sub(x1, x2) 18 Added test: testAddNeg2 19 Adds the following optimization for floating point values: 20 - Abs(Neg(x)) => Abs(x) 21 Added test: testAbsNegArg 22 Adds the following optimization: 23 24 Also did some trivial refactoring, using m_value->isInteger() everywhere instead of isInt(m_value->type()), and using replaceWithNew<Value> instead of replaceWithNewValue(m_proc.add<Value(..)) 25 26 * b3/B3ReduceStrength.cpp: 27 * b3/testb3.cpp: 28 (JSC::B3::testAddNeg1): 29 (JSC::B3::testAddNeg2): 30 (JSC::B3::testSubNeg): 31 (JSC::B3::testNegSub): 32 (JSC::B3::testAbsAbsArg): 33 (JSC::B3::testAbsNegArg): 34 (JSC::B3::run): 35 1 36 2019-02-06 Yusuke Suzuki <ysuzuki@apple.com> 2 37 -
trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp
r230098 r241126 500 500 handleCommutativity(); 501 501 502 if (m_value->child(0)->opcode() == Add && isInt(m_value->type())) {502 if (m_value->child(0)->opcode() == Add && m_value->isInteger()) { 503 503 // Turn this: Add(Add(value, constant1), constant2) 504 504 // Into this: Add(value, constant1 + constant2) … … 533 533 // Turn this: Add(otherValue, Add(value, constant)) 534 534 // Into this: Add(Add(value, otherValue), constant) 535 if ( isInt(m_value->type())535 if (m_value->isInteger() 536 536 && !m_value->child(0)->hasInt() 537 537 && m_value->child(1)->opcode() == Add … … 580 580 } 581 581 582 // Turn this: Integer Add(Sub(0, value), -1) 583 // Into this: BitXor(value, -1) 584 if (m_value->isInteger() 585 && m_value->child(0)->opcode() == Sub 586 && m_value->child(1)->isInt(-1) 587 && m_value->child(0)->child(0)->isInt(0)) { 588 replaceWithNewValue(m_proc.add<Value>(BitXor, m_value->origin(), m_value->child(0)->child(1), m_value->child(1))); 589 break; 582 if (m_value->isInteger()) { 583 // Turn this: Integer Add(value, Neg(otherValue)) 584 // Into this: Sub(value, otherValue) 585 if (m_value->child(1)->opcode() == Neg) { 586 replaceWithNew<Value>(Sub, m_value->origin(), m_value->child(0), m_value->child(1)->child(0)); 587 break; 588 } 589 590 // Turn this: Integer Add(Neg(value), otherValue) 591 // Into this: Sub(otherValue, value) 592 if (m_value->child(0)->opcode() == Neg) { 593 replaceWithNew<Value>(Sub, m_value->origin(), m_value->child(1), m_value->child(0)->child(0)); 594 break; 595 } 596 597 // Turn this: Integer Add(Sub(0, value), -1) 598 // Into this: BitXor(value, -1) 599 if (m_value->child(0)->opcode() == Sub 600 && m_value->child(1)->isInt(-1) 601 && m_value->child(0)->child(0)->isInt(0)) { 602 replaceWithNew<Value>(BitXor, m_value->origin(), m_value->child(0)->child(1), m_value->child(1)); 603 break; 604 } 590 605 } 591 606 … … 600 615 } 601 616 602 if ( isInt(m_value->type())) {617 if (m_value->isInteger()) { 603 618 // Turn this: Sub(value, constant) 604 619 // Into this: Add(value, -constant) … … 616 631 break; 617 632 } 633 634 // Turn this: Sub(value, value) 635 // Into this: 0 636 if (m_value->child(0) == m_value->child(1)) { 637 replaceWithNewValue(m_proc.addIntConstant(m_value, 0)); 638 break; 639 } 640 641 // Turn this: Sub(value, Neg(otherValue)) 642 // Into this: Add(value, otherValue) 643 if (m_value->child(1)->opcode() == Neg) { 644 replaceWithNew<Value>(Add, m_value->origin(), m_value->child(0), m_value->child(1)->child(0)); 645 break; 646 } 618 647 } 619 648 … … 635 664 } 636 665 666 // Turn this: Integer Neg(Sub(value, otherValue)) 667 // Into this: Sub(otherValue, value) 668 if (m_value->isInteger() && m_value->child(0)->opcode() == Sub) { 669 replaceWithNew<Value>(Sub, m_value->origin(), m_value->child(0)->child(1), m_value->child(0)->child(0)); 670 break; 671 } 672 637 673 break; 638 674 … … 1200 1236 if (m_value->child(0)->opcode() == Abs) { 1201 1237 replaceWithIdentity(m_value->child(0)); 1238 break; 1239 } 1240 1241 // Turn this: Abs(Neg(value)) 1242 // Into this: Abs(value) 1243 if (m_value->child(0)->opcode() == Neg) { 1244 replaceWithIdentity(m_value->child(0)->child(0)); 1202 1245 break; 1203 1246 } -
trunk/Source/JavaScriptCore/b3/testb3.cpp
r239187 r241126 610 610 } 611 611 612 void testAddNeg1(int a, int b) 613 { 614 Procedure proc; 615 BasicBlock* root = proc.addBlock(); 616 root->appendNewControlValue( 617 proc, Return, Origin(), 618 root->appendNew<Value>( 619 proc, Add, Origin(), 620 root->appendNew<Value>(proc, Neg, Origin(), 621 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)), 622 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1))); 623 624 CHECK(compileAndRun<int>(proc, a, b) == (- a) + b); 625 } 626 627 void testAddNeg2(int a, int b) 628 { 629 Procedure proc; 630 BasicBlock* root = proc.addBlock(); 631 root->appendNewControlValue( 632 proc, Return, Origin(), 633 root->appendNew<Value>( 634 proc, Add, Origin(), 635 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0), 636 root->appendNew<Value>(proc, Neg, Origin(), 637 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)))); 638 639 CHECK(compileAndRun<int>(proc, a, b) == a + (- b)); 640 } 641 612 642 void testAddArgZeroImmZDef() 613 643 { … … 1898 1928 } 1899 1929 1930 void testSubNeg(int a, int b) 1931 { 1932 Procedure proc; 1933 BasicBlock* root = proc.addBlock(); 1934 root->appendNewControlValue( 1935 proc, Return, Origin(), 1936 root->appendNew<Value>( 1937 proc, Sub, Origin(), 1938 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0), 1939 root->appendNew<Value>(proc, Neg, Origin(), 1940 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)))); 1941 1942 CHECK(compileAndRun<int>(proc, a, b) == a - (- b)); 1943 } 1944 1945 void testNegSub(int a, int b) 1946 { 1947 Procedure proc; 1948 BasicBlock* root = proc.addBlock(); 1949 root->appendNewControlValue( 1950 proc, Return, Origin(), 1951 root->appendNew<Value>( 1952 proc, Neg, Origin(), 1953 root->appendNew<Value>(proc, Sub, Origin(), 1954 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0), 1955 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)))); 1956 1957 CHECK(compileAndRun<int>(proc, a, b) == -(a - b)); 1958 } 1959 1900 1960 void testNegValueSubOne(int a) 1901 1961 { … … 3918 3978 root->appendNewControlValue(proc, Return, Origin(), secondAbs); 3919 3979 3920 CHECK(isIdentical(compileAndRun<double>(proc, a), fabs(a))); 3980 CHECK(isIdentical(compileAndRun<double>(proc, a), fabs(fabs(a)))); 3981 } 3982 3983 void testAbsNegArg(double a) 3984 { 3985 Procedure proc; 3986 BasicBlock* root = proc.addBlock(); 3987 Value* neg = root->appendNew<Value>(proc, Abs, Origin(), 3988 root->appendNew<ArgumentRegValue>(proc, Origin(), FPRInfo::argumentFPR0)); 3989 Value* abs = root->appendNew<Value>(proc, Abs, Origin(), neg); 3990 root->appendNewControlValue(proc, Return, Origin(), abs); 3991 3992 CHECK(isIdentical(compileAndRun<double>(proc, a), fabs(- a))); 3921 3993 } 3922 3994 … … 3998 4070 root->appendNewControlValue(proc, Return, Origin(), secondAbs); 3999 4071 4000 CHECK(isIdentical(compileAndRun<float>(proc, bitwise_cast<int32_t>(a)), static_cast<float>(fabs(a)))); 4072 CHECK(isIdentical(compileAndRun<float>(proc, bitwise_cast<int32_t>(a)), static_cast<float>(fabs(fabs(a))))); 4073 } 4074 4075 void testAbsNegArg(float a) 4076 { 4077 Procedure proc; 4078 BasicBlock* root = proc.addBlock(); 4079 Value* argument32 = root->appendNew<Value>(proc, Trunc, Origin(), 4080 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)); 4081 Value* argument = root->appendNew<Value>(proc, BitwiseCast, Origin(), argument32); 4082 Value* neg = root->appendNew<Value>(proc, Neg, Origin(), argument); 4083 Value* abs = root->appendNew<Value>(proc, Abs, Origin(), neg); 4084 root->appendNewControlValue(proc, Return, Origin(), abs); 4085 4086 CHECK(isIdentical(compileAndRun<float>(proc, bitwise_cast<int32_t>(a)), static_cast<float>(fabs(- a)))); 4001 4087 } 4002 4088 … … 16383 16469 RUN_BINARY(testAddMemArg32, int32Operands(), int32Operands()); 16384 16470 RUN_BINARY(testAddImmMem32, int32Operands(), int32Operands()); 16471 RUN_BINARY(testAddNeg1, int32Operands(), int32Operands()); 16472 RUN_BINARY(testAddNeg2, int32Operands(), int32Operands()); 16385 16473 RUN(testAddArgZeroImmZDef()); 16386 16474 RUN(testAddLoadTwice()); … … 16550 16638 RUN_BINARY(testSubImmMem, int32Operands(), int32Operands()); 16551 16639 RUN_BINARY(testSubMemImm, int32Operands(), int32Operands()); 16640 RUN_BINARY(testSubNeg, int32Operands(), int32Operands()); 16641 RUN_BINARY(testNegSub, int32Operands(), int32Operands()); 16552 16642 RUN_UNARY(testNegValueSubOne, int32Operands()); 16553 16643 … … 16906 16996 RUN_UNARY(testAbsMem, floatingPointOperands<double>()); 16907 16997 RUN_UNARY(testAbsAbsArg, floatingPointOperands<double>()); 16998 RUN_UNARY(testAbsNegArg, floatingPointOperands<double>()); 16908 16999 RUN_UNARY(testAbsBitwiseCastArg, floatingPointOperands<double>()); 16909 17000 RUN_UNARY(testBitwiseCastAbsBitwiseCastArg, floatingPointOperands<double>()); … … 16912 17003 RUN_UNARY(testAbsMem, floatingPointOperands<float>()); 16913 17004 RUN_UNARY(testAbsAbsArg, floatingPointOperands<float>()); 17005 RUN_UNARY(testAbsNegArg, floatingPointOperands<float>()); 16914 17006 RUN_UNARY(testAbsBitwiseCastArg, floatingPointOperands<float>()); 16915 17007 RUN_UNARY(testBitwiseCastAbsBitwiseCastArg, floatingPointOperands<float>());
Note: See TracChangeset
for help on using the changeset viewer.