Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (197651 => 197652)
--- trunk/Source/_javascript_Core/ChangeLog 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-03-07 02:40:16 UTC (rev 197652)
@@ -1,3 +1,95 @@
+2016-03-06 Benjamin Poulain <[email protected]>
+
+ [JSC] Improve codegen of Compare and Test
+ https://bugs.webkit.org/show_bug.cgi?id=155055
+
+ Reviewed by Filip Pizlo.
+
+ This patch introduces a few improvements on how we lower
+ Compare and Test with immediates:
+ -Add certain Immediate forms of ARM64.
+ -Use CBZ/CBNZ when possible on ARM64.
+ -When possible, convert a CMP into a TST
+ On some hardware, we can issue more TST simultaneously.
+
+ On x86, any TST+Jump is candidate for macro-fusion.
+ They are also smaller.
+ (sections 3.4.2.2 and 3.5.1.9)
+ -Do not load the mask immediate of a TST
+ if it only contains ones (mostly useful for ARM64
+ since that would not have been a valid immediate).
+
+ * assembler/MacroAssembler.h:
+ (JSC::MacroAssembler::compare32):
+ * assembler/MacroAssemblerARM64.h:
+ (JSC::MacroAssemblerARM64::moveConditionallyAfterFloatingPointCompare):
+ (JSC::MacroAssemblerARM64::moveDoubleConditionallyAfterFloatingPointCompare):
+ This is somewhat unrelated but I found that out while working
+ on moveDoubleConditionallyTest32:
+ If "thenCase" and "dest" are assigned the same register
+ by the allocator, then the first (f)fcsel would override
+ the "thenCase" and the second fcsel would always be "elseCase".
+
+ This is covered by testb3 but was only uncovered
+ after recent "Move" removals in lowering.
+
+ (JSC::MacroAssemblerARM64::moveConditionally32):
+ (JSC::MacroAssemblerARM64::moveConditionally64):
+ (JSC::MacroAssemblerARM64::moveConditionallyTest32):
+ (JSC::MacroAssemblerARM64::moveDoubleConditionally32):
+ (JSC::MacroAssemblerARM64::moveDoubleConditionally64):
+ (JSC::MacroAssemblerARM64::moveDoubleConditionallyTest32):
+ (JSC::MacroAssemblerARM64::branch32):
+ (JSC::MacroAssemblerARM64::branch64):
+ (JSC::MacroAssemblerARM64::branchTest32):
+ (JSC::MacroAssemblerARM64::test32):
+ The version taking an immediate was guarded by
+ (cond == Zero) || (cond == NonZero). That is overzealous,
+ and only needed for CBZ/CBNZ.
+
+ (JSC::MacroAssemblerARM64::branchTest64):
+ (JSC::MacroAssemblerARM64::compare32):
+ (JSC::MacroAssemblerARM64::compare64):
+ (JSC::MacroAssemblerARM64::commuteCompareToZeroIntoTest):
+ * assembler/MacroAssemblerX86Common.h:
+ (JSC::MacroAssemblerX86Common::moveConditionally32):
+ (JSC::MacroAssemblerX86Common::moveConditionallyTest32):
+ (JSC::MacroAssemblerX86Common::branch32):
+ (JSC::MacroAssemblerX86Common::test32):
+ (JSC::MacroAssemblerX86Common::branchTest32):
+ (JSC::MacroAssemblerX86Common::compare32):
+ (JSC::MacroAssemblerX86Common::commuteCompareToZeroIntoTest):
+ * assembler/MacroAssemblerX86_64.h:
+ (JSC::MacroAssemblerX86_64::compare64):
+ (JSC::MacroAssemblerX86_64::branch64):
+ (JSC::MacroAssemblerX86_64::moveConditionally64):
+ * b3/B3LowerToAir.cpp:
+ (JSC::B3::Air::LowerToAir::createGenericCompare):
+ Unfortunately this cannot be abstracted by the MacroAssembler.
+ Those immediates are not valid, we have to pick the better
+ for right away.
+
+ * b3/air/AirOpcode.opcodes:
+ * b3/testb3.cpp:
+ (JSC::B3::int64Operands):
+ (JSC::B3::modelCompare):
+ (JSC::B3::testCompareImpl):
+ (JSC::B3::testCompare):
+ (JSC::B3::b3Pow):
+ (JSC::B3::testPowDoubleByIntegerLoop):
+ Some versions of pow(double, int) do not return
+ the exact same bits as our integer loop.
+ Added a new version to have the same behavior
+ as the B3 loop.
+
+ (JSC::B3::run):
+ * dfg/DFGSpeculativeJIT.cpp:
+ (JSC::DFG::SpeculativeJIT::compilePeepHoleBooleanBranch):
+ * dfg/DFGSpeculativeJIT64.cpp:
+ (JSC::DFG::SpeculativeJIT::compileInt32Compare):
+ Comparing to an immediate is super common. Do not waste
+ a register for that!
+
2016-03-06 Filip Pizlo <[email protected]>
Unreviewed, fix build. This was a messed up merge.
Modified: trunk/Source/_javascript_Core/assembler/MacroAssembler.h (197651 => 197652)
--- trunk/Source/_javascript_Core/assembler/MacroAssembler.h 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/assembler/MacroAssembler.h 2016-03-07 02:40:16 UTC (rev 197652)
@@ -112,6 +112,7 @@
using MacroAssemblerBase::pop;
using MacroAssemblerBase::jump;
using MacroAssemblerBase::branch32;
+ using MacroAssemblerBase::compare32;
using MacroAssemblerBase::move;
using MacroAssemblerBase::add32;
using MacroAssemblerBase::and32;
@@ -400,6 +401,11 @@
return branch32(commute(cond), right, left);
}
+ void compare32(RelationalCondition cond, Imm32 left, RegisterID right, RegisterID dest)
+ {
+ compare32(commute(cond), right, left, dest);
+ }
+
void branchTestPtr(ResultCondition cond, RegisterID reg, Label target)
{
branchTestPtr(cond, reg).linkTo(target, this);
@@ -1621,6 +1627,29 @@
return branch32(cond, left, right.asTrustedImm32());
}
+ void compare32(RelationalCondition cond, RegisterID left, Imm32 right, RegisterID dest)
+ {
+ if (shouldBlind(right)) {
+ if (left != dest || haveScratchRegisterForBlinding()) {
+ RegisterID blindedConstantReg = dest;
+ if (left == dest)
+ blindedConstantReg = scratchRegisterForBlinding();
+ loadXorBlindedConstant(xorBlindConstant(right), blindedConstantReg);
+ compare32(cond, left, blindedConstantReg, dest);
+ return;
+ }
+ // If we don't have a scratch register available for use, we'll just
+ // place a random number of nops.
+ uint32_t nopCount = random() & 3;
+ while (nopCount--)
+ nop();
+ compare32(cond, left, right.asTrustedImm32(), dest);
+ return;
+ }
+
+ compare32(cond, left, right.asTrustedImm32(), dest);
+ }
+
Jump branchAdd32(ResultCondition cond, RegisterID src, Imm32 imm, RegisterID dest)
{
if (src == dest)
Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h (197651 => 197652)
--- trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h 2016-03-07 02:40:16 UTC (rev 197652)
@@ -31,6 +31,7 @@
#include "ARM64Assembler.h"
#include "AbstractMacroAssembler.h"
#include <wtf/MathExtras.h>
+#include <wtf/Optional.h>
namespace JSC {
@@ -1685,12 +1686,12 @@
return;
}
if (cond == DoubleEqualOrUnordered) {
- // If the compare is unordered, thenCase is copied to dest and the
+ // If the compare is unordered, thenCase is copied to elseCase and the
// next csel has all arguments equal to thenCase.
// If the compare is ordered, dest is unchanged and EQ decides
// what value to set.
- m_assembler.csel<datasize>(dest, thenCase, elseCase, ARM64Assembler::ConditionVS);
- m_assembler.csel<datasize>(dest, thenCase, dest, ARM64Assembler::ConditionEQ);
+ m_assembler.csel<datasize>(elseCase, thenCase, elseCase, ARM64Assembler::ConditionVS);
+ m_assembler.csel<datasize>(dest, thenCase, elseCase, ARM64Assembler::ConditionEQ);
return;
}
m_assembler.csel<datasize>(dest, thenCase, elseCase, ARM64Condition(cond));
@@ -1706,12 +1707,12 @@
return;
}
if (cond == DoubleEqualOrUnordered) {
- // If the compare is unordered, thenCase is copied to dest and the
+ // If the compare is unordered, thenCase is copied to elseCase and the
// next csel has all arguments equal to thenCase.
// If the compare is ordered, dest is unchanged and EQ decides
// what value to set.
- m_assembler.fcsel<datasize>(dest, thenCase, elseCase, ARM64Assembler::ConditionVS);
- m_assembler.fcsel<datasize>(dest, thenCase, dest, ARM64Assembler::ConditionEQ);
+ m_assembler.fcsel<datasize>(elseCase, thenCase, elseCase, ARM64Assembler::ConditionVS);
+ m_assembler.fcsel<datasize>(dest, thenCase, elseCase, ARM64Assembler::ConditionEQ);
return;
}
m_assembler.fcsel<datasize>(dest, thenCase, elseCase, ARM64Condition(cond));
@@ -2003,6 +2004,13 @@
void moveConditionally32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID thenCase, RegisterID elseCase, RegisterID dest)
{
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ moveConditionallyTest32(*resultCondition, left, left, thenCase, elseCase, dest);
+ return;
+ }
+ }
+
if (isUInt12(right.m_value))
m_assembler.cmp<32>(left, UInt12(right.m_value));
else if (isUInt12(-right.m_value))
@@ -2026,6 +2034,26 @@
m_assembler.csel<64>(dest, thenCase, elseCase, ARM64Condition(cond));
}
+ void moveConditionally64(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID thenCase, RegisterID elseCase, RegisterID dest)
+ {
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ moveConditionallyTest64(*resultCondition, left, left, thenCase, elseCase, dest);
+ return;
+ }
+ }
+
+ if (isUInt12(right.m_value))
+ m_assembler.cmp<64>(left, UInt12(right.m_value));
+ else if (isUInt12(-right.m_value))
+ m_assembler.cmn<64>(left, UInt12(-right.m_value));
+ else {
+ moveToCachedReg(right, dataMemoryTempRegister());
+ m_assembler.cmp<64>(left, dataTempRegister);
+ }
+ m_assembler.csel<64>(dest, thenCase, elseCase, ARM64Condition(cond));
+ }
+
void moveConditionallyTest32(ResultCondition cond, RegisterID testReg, RegisterID mask, RegisterID src, RegisterID dest)
{
m_assembler.tst<32>(testReg, mask);
@@ -2038,6 +2066,12 @@
m_assembler.csel<32>(dest, thenCase, elseCase, ARM64Condition(cond));
}
+ void moveConditionallyTest32(ResultCondition cond, RegisterID left, TrustedImm32 right, RegisterID thenCase, RegisterID elseCase, RegisterID dest)
+ {
+ test32(left, right);
+ m_assembler.csel<32>(dest, thenCase, elseCase, ARM64Condition(cond));
+ }
+
void moveConditionallyTest64(ResultCondition cond, RegisterID testReg, RegisterID mask, RegisterID src, RegisterID dest)
{
m_assembler.tst<64>(testReg, mask);
@@ -2058,6 +2092,13 @@
void moveDoubleConditionally32(RelationalCondition cond, RegisterID left, TrustedImm32 right, FPRegisterID thenCase, FPRegisterID elseCase, FPRegisterID dest)
{
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ moveDoubleConditionallyTest32(*resultCondition, left, left, thenCase, elseCase, dest);
+ return;
+ }
+ }
+
if (isUInt12(right.m_value))
m_assembler.cmp<32>(left, UInt12(right.m_value));
else if (isUInt12(-right.m_value))
@@ -2077,6 +2118,13 @@
void moveDoubleConditionally64(RelationalCondition cond, RegisterID left, TrustedImm32 right, FPRegisterID thenCase, FPRegisterID elseCase, FPRegisterID dest)
{
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ moveDoubleConditionallyTest64(*resultCondition, left, left, thenCase, elseCase, dest);
+ return;
+ }
+ }
+
if (isUInt12(right.m_value))
m_assembler.cmp<64>(left, UInt12(right.m_value));
else if (isUInt12(-right.m_value))
@@ -2094,6 +2142,12 @@
m_assembler.fcsel<64>(dest, thenCase, elseCase, ARM64Condition(cond));
}
+ void moveDoubleConditionallyTest32(ResultCondition cond, RegisterID left, TrustedImm32 right, FPRegisterID thenCase, FPRegisterID elseCase, FPRegisterID dest)
+ {
+ test32(left, right);
+ m_assembler.fcsel<64>(dest, thenCase, elseCase, ARM64Condition(cond));
+ }
+
void moveDoubleConditionallyTest64(ResultCondition cond, RegisterID left, RegisterID right, FPRegisterID thenCase, FPRegisterID elseCase, FPRegisterID dest)
{
m_assembler.tst<64>(left, right);
@@ -2126,6 +2180,11 @@
Jump branch32(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond))
+ return branchTest32(*resultCondition, left, left);
+ }
+
if (isUInt12(right.m_value))
m_assembler.cmp<32>(left, UInt12(right.m_value));
else if (isUInt12(-right.m_value))
@@ -2191,6 +2250,11 @@
Jump branch64(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond))
+ return branchTest64(*resultCondition, left, left);
+ }
+
if (isUInt12(right.m_value))
m_assembler.cmp<64>(left, UInt12(right.m_value));
else if (isUInt12(-right.m_value))
@@ -2205,6 +2269,11 @@
Jump branch64(RelationalCondition cond, RegisterID left, TrustedImm64 right)
{
intptr_t immediate = right.m_value;
+ if (!immediate) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond))
+ return branchTest64(*resultCondition, left, left);
+ }
+
if (isUInt12(immediate))
m_assembler.cmp<64>(left, UInt12(static_cast<int32_t>(immediate)));
else if (isUInt12(-immediate))
@@ -2269,25 +2338,22 @@
Jump branchTest32(ResultCondition cond, RegisterID reg, RegisterID mask)
{
+ if (reg == mask && (cond == Zero || cond == NonZero))
+ return Jump(makeCompareAndBranch<32>(static_cast<ZeroCondition>(cond), reg));
m_assembler.tst<32>(reg, mask);
return Jump(makeBranch(cond));
}
- void test32(ResultCondition cond, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
+ void test32(RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
{
if (mask.m_value == -1)
m_assembler.tst<32>(reg, reg);
else {
- bool testedWithImmediate = false;
- if ((cond == Zero) || (cond == NonZero)) {
- LogicalImmediate logicalImm = LogicalImmediate::create32(mask.m_value);
+ LogicalImmediate logicalImm = LogicalImmediate::create32(mask.m_value);
- if (logicalImm.isValid()) {
- m_assembler.tst<32>(reg, logicalImm);
- testedWithImmediate = true;
- }
- }
- if (!testedWithImmediate) {
+ if (logicalImm.isValid())
+ m_assembler.tst<32>(reg, logicalImm);
+ else {
move(mask, getCachedDataTempRegisterIDAndInvalidate());
m_assembler.tst<32>(reg, dataTempRegister);
}
@@ -2308,13 +2374,10 @@
} else if (hasOneBitSet(mask.m_value) && ((cond == Zero) || (cond == NonZero)))
return Jump(makeTestBitAndBranch(reg, getLSBSet(mask.m_value), static_cast<ZeroCondition>(cond)));
else {
- if ((cond == Zero) || (cond == NonZero)) {
- LogicalImmediate logicalImm = LogicalImmediate::create32(mask.m_value);
-
- if (logicalImm.isValid()) {
- m_assembler.tst<32>(reg, logicalImm);
- return Jump(makeBranch(cond));
- }
+ LogicalImmediate logicalImm = LogicalImmediate::create32(mask.m_value);
+ if (logicalImm.isValid()) {
+ m_assembler.tst<32>(reg, logicalImm);
+ return Jump(makeBranch(cond));
}
move(mask, getCachedDataTempRegisterIDAndInvalidate());
@@ -2337,6 +2400,8 @@
Jump branchTest64(ResultCondition cond, RegisterID reg, RegisterID mask)
{
+ if (reg == mask && (cond == Zero || cond == NonZero))
+ return Jump(makeCompareAndBranch<64>(static_cast<ZeroCondition>(cond), reg));
m_assembler.tst<64>(reg, mask);
return Jump(makeBranch(cond));
}
@@ -2350,13 +2415,11 @@
} else if (hasOneBitSet(mask.m_value) && ((cond == Zero) || (cond == NonZero)))
return Jump(makeTestBitAndBranch(reg, getLSBSet(mask.m_value), static_cast<ZeroCondition>(cond)));
else {
- if ((cond == Zero) || (cond == NonZero)) {
- LogicalImmediate logicalImm = LogicalImmediate::create64(mask.m_value);
+ LogicalImmediate logicalImm = LogicalImmediate::create64(mask.m_value);
- if (logicalImm.isValid()) {
- m_assembler.tst<64>(reg, logicalImm);
- return Jump(makeBranch(cond));
- }
+ if (logicalImm.isValid()) {
+ m_assembler.tst<64>(reg, logicalImm);
+ return Jump(makeBranch(cond));
}
signExtend32ToPtr(mask, getCachedDataTempRegisterIDAndInvalidate());
@@ -2773,8 +2836,21 @@
void compare32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
{
- move(right, getCachedDataTempRegisterIDAndInvalidate());
- m_assembler.cmp<32>(left, dataTempRegister);
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ test32(*resultCondition, left, left, dest);
+ return;
+ }
+ }
+
+ if (isUInt12(right.m_value))
+ m_assembler.cmp<32>(left, UInt12(right.m_value));
+ else if (isUInt12(-right.m_value))
+ m_assembler.cmn<32>(left, UInt12(-right.m_value));
+ else {
+ move(right, getCachedDataTempRegisterIDAndInvalidate());
+ m_assembler.cmp<32>(left, dataTempRegister);
+ }
m_assembler.cset<32>(dest, ARM64Condition(cond));
}
@@ -2786,6 +2862,13 @@
void compare64(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
{
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ test64(*resultCondition, left, left, dest);
+ return;
+ }
+ }
+
signExtend32ToPtr(right, getCachedDataTempRegisterIDAndInvalidate());
m_assembler.cmp<64>(left, dataTempRegister);
m_assembler.cset<32>(dest, ARM64Condition(cond));
@@ -2806,12 +2889,7 @@
void test32(ResultCondition cond, RegisterID src, TrustedImm32 mask, RegisterID dest)
{
- if (mask.m_value == -1)
- m_assembler.tst<32>(src, src);
- else {
- signExtend32ToPtr(mask, getCachedDataTempRegisterIDAndInvalidate());
- m_assembler.tst<32>(src, dataTempRegister);
- }
+ test32(src, mask);
m_assembler.cset<32>(dest, ARM64Condition(cond));
}
@@ -2994,6 +3072,23 @@
return static_cast<RelationalCondition>(ARM64Assembler::invert(static_cast<ARM64Assembler::Condition>(cond)));
}
+ static Optional<ResultCondition> commuteCompareToZeroIntoTest(RelationalCondition cond)
+ {
+ switch (cond) {
+ case Equal:
+ return Zero;
+ case NotEqual:
+ return NonZero;
+ case LessThan:
+ return Signed;
+ case GreaterThanOrEqual:
+ return PositiveOrZero;
+ break;
+ default:
+ return Nullopt;
+ }
+ }
+
static FunctionPtr readCallTarget(CodeLocationCall call)
{
return FunctionPtr(reinterpret_cast<void(*)()>(ARM64Assembler::readCallTarget(call.dataLocation())));
Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerARMv7.h (197651 => 197652)
--- trunk/Source/_javascript_Core/assembler/MacroAssemblerARMv7.h 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerARMv7.h 2016-03-07 02:40:16 UTC (rev 197652)
@@ -1343,7 +1343,7 @@
private:
// Should we be using TEQ for equal/not-equal?
- void compare32(RegisterID left, TrustedImm32 right)
+ void compare32AndSetFlags(RegisterID left, TrustedImm32 right)
{
int32_t imm = right.m_value;
ARMThumbImmediate armImm = ARMThumbImmediate::makeEncodedImm(imm);
@@ -1357,7 +1357,8 @@
}
}
- void test32(RegisterID reg, TrustedImm32 mask)
+public:
+ void test32(RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
{
int32_t imm = mask.m_value;
@@ -1381,12 +1382,6 @@
}
}
}
-
-public:
- void test32(ResultCondition, RegisterID reg, TrustedImm32 mask)
- {
- test32(reg, mask);
- }
Jump branch(ResultCondition cond)
{
@@ -1401,7 +1396,7 @@
Jump branch32(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
- compare32(left, right);
+ compare32AndSetFlags(left, right);
return Jump(makeBranch(cond));
}
@@ -1459,7 +1454,7 @@
Jump branch8(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
- compare32(left, right);
+ compare32AndSetFlags(left, right);
return Jump(makeBranch(cond));
}
@@ -1765,7 +1760,7 @@
void compare32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
{
- compare32(left, right);
+ compare32AndSetFlags(left, right);
m_assembler.it(armV7Condition(cond), false);
m_assembler.mov(dest, ARMThumbImmediate::makeUInt16(1));
m_assembler.mov(dest, ARMThumbImmediate::makeUInt16(0));
Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h (197651 => 197652)
--- trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h 2016-03-07 02:40:16 UTC (rev 197652)
@@ -30,6 +30,7 @@
#include "X86Assembler.h"
#include "AbstractMacroAssembler.h"
+#include <wtf/Optional.h>
namespace JSC {
@@ -1779,11 +1780,15 @@
void moveConditionally32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID thenCase, RegisterID elseCase, RegisterID dest)
{
- if (((cond == Equal) || (cond == NotEqual)) && !right.m_value)
- m_assembler.testl_rr(left, left);
- else
- m_assembler.cmpl_ir(right.m_value, left);
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ moveConditionallyTest32(*resultCondition, left, left, thenCase, elseCase, dest);
+ return;
+ }
+ }
+ m_assembler.cmpl_ir(right.m_value, left);
+
if (thenCase != dest && elseCase != dest) {
move(elseCase, dest);
elseCase = dest;
@@ -1821,7 +1826,7 @@
void moveConditionallyTest32(ResultCondition cond, RegisterID testReg, TrustedImm32 mask, RegisterID src, RegisterID dest)
{
- test32(cond, testReg, mask);
+ test32(testReg, mask);
cmov(x86Condition(cond), src, dest);
}
@@ -1830,7 +1835,7 @@
ASSERT(isInvertible(cond));
ASSERT_WITH_MESSAGE(cond != Overflow, "TEST does not set the Overflow Flag.");
- test32(cond, testReg, mask);
+ test32(testReg, mask);
if (thenCase != dest && elseCase != dest) {
move(elseCase, dest);
@@ -1960,10 +1965,12 @@
Jump branch32(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
- if (((cond == Equal) || (cond == NotEqual)) && !right.m_value)
- m_assembler.testl_rr(left, left);
- else
- m_assembler.cmpl_ir(right.m_value, left);
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond))
+ return branchTest32(*resultCondition, left, left);
+ }
+
+ m_assembler.cmpl_ir(right.m_value, left);
return Jump(m_assembler.jCC(x86Condition(cond)));
}
@@ -2002,7 +2009,7 @@
return Jump(m_assembler.jCC(x86Condition(cond)));
}
- void test32(ResultCondition, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
+ void test32(RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
{
if (mask.m_value == -1)
m_assembler.testl_rr(reg, reg);
@@ -2022,7 +2029,7 @@
Jump branchTest32(ResultCondition cond, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
{
- test32(cond, reg, mask);
+ test32(reg, mask);
return branch(cond);
}
@@ -2290,10 +2297,14 @@
void compare32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
{
- if (((cond == Equal) || (cond == NotEqual)) && !right.m_value)
- m_assembler.testl_rr(left, left);
- else
- m_assembler.cmpl_ir(right.m_value, left);
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ test32(*resultCondition, left, left, dest);
+ return;
+ }
+ }
+
+ m_assembler.cmpl_ir(right.m_value, left);
set32(x86Condition(cond), dest);
}
@@ -2323,6 +2334,12 @@
set32(x86Condition(cond), dest);
}
+ void test32(ResultCondition cond, RegisterID reg, TrustedImm32 mask, RegisterID dest)
+ {
+ test32(reg, mask);
+ set32(x86Condition(cond), dest);
+ }
+
void setCarry(RegisterID dest)
{
set32(X86Assembler::ConditionC, dest);
@@ -2396,6 +2413,23 @@
}
}
+ static Optional<ResultCondition> commuteCompareToZeroIntoTest(RelationalCondition cond)
+ {
+ switch (cond) {
+ case Equal:
+ return Zero;
+ case NotEqual:
+ return NonZero;
+ case LessThan:
+ return Signed;
+ case GreaterThanOrEqual:
+ return PositiveOrZero;
+ break;
+ default:
+ return Nullopt;
+ }
+ }
+
void nop()
{
m_assembler.nop();
Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerX86_64.h (197651 => 197652)
--- trunk/Source/_javascript_Core/assembler/MacroAssemblerX86_64.h 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerX86_64.h 2016-03-07 02:40:16 UTC (rev 197652)
@@ -701,19 +701,21 @@
void compare64(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
{
- if (((cond == Equal) || (cond == NotEqual)) && !right.m_value)
- m_assembler.testq_rr(left, left);
- else
- m_assembler.cmpq_ir(right.m_value, left);
- m_assembler.setCC_r(x86Condition(cond), dest);
- m_assembler.movzbl_rr(dest, dest);
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ test64(*resultCondition, left, left, dest);
+ return;
+ }
+ }
+
+ m_assembler.cmpq_ir(right.m_value, left);
+ set32(x86Condition(cond), dest);
}
void compare64(RelationalCondition cond, RegisterID left, RegisterID right, RegisterID dest)
{
m_assembler.cmpq_rr(right, left);
- m_assembler.setCC_r(x86Condition(cond), dest);
- m_assembler.movzbl_rr(dest, dest);
+ set32(x86Condition(cond), dest);
}
void compareDouble(DoubleCondition cond, FPRegisterID left, FPRegisterID right, RegisterID dest)
@@ -758,9 +760,9 @@
Jump branch64(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
- if (((cond == Equal) || (cond == NotEqual)) && !right.m_value) {
- m_assembler.testq_rr(left, left);
- return Jump(m_assembler.jCC(x86Condition(cond)));
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond))
+ return branchTest64(*resultCondition, left, left);
}
m_assembler.cmpq_ir(right.m_value, left);
return Jump(m_assembler.jCC(x86Condition(cond)));
@@ -994,6 +996,28 @@
cmov(x86Condition(invert(cond)), elseCase, dest);
}
+ void moveConditionally64(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID thenCase, RegisterID elseCase, RegisterID dest)
+ {
+ if (!right.m_value) {
+ if (auto resultCondition = commuteCompareToZeroIntoTest(cond)) {
+ moveConditionallyTest64(*resultCondition, left, left, thenCase, elseCase, dest);
+ return;
+ }
+ }
+
+ m_assembler.cmpq_ir(right.m_value, left);
+
+ if (thenCase != dest && elseCase != dest) {
+ move(elseCase, dest);
+ elseCase = dest;
+ }
+
+ if (elseCase == dest)
+ cmov(x86Condition(cond), thenCase, dest);
+ else
+ cmov(x86Condition(invert(cond)), elseCase, dest);
+ }
+
void moveConditionallyTest64(ResultCondition cond, RegisterID testReg, RegisterID mask, RegisterID src, RegisterID dest)
{
m_assembler.testq_rr(testReg, mask);
Modified: trunk/Source/_javascript_Core/b3/B3LowerToAir.cpp (197651 => 197652)
--- trunk/Source/_javascript_Core/b3/B3LowerToAir.cpp 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/b3/B3LowerToAir.cpp 2016-03-07 02:40:16 UTC (rev 197652)
@@ -1374,14 +1374,30 @@
// Now handle test's that involve an immediate and a tmp.
- if (leftImm && leftImm.isRepresentableAs<uint32_t>()) {
- if (Inst result = tryTest(Arg::Width32, leftImm, tmpPromise(right)))
- return result;
+ if (leftImm) {
+ if ((width == Arg::Width32 && leftImm.value() == 0xffffffff)
+ || (width == Arg::Width64 && leftImm.value() == -1)) {
+ ArgPromise argPromise = tmpPromise(right);
+ if (Inst result = tryTest(width, argPromise, argPromise))
+ return result;
+ }
+ if (leftImm.isRepresentableAs<uint32_t>()) {
+ if (Inst result = tryTest(Arg::Width32, leftImm, tmpPromise(right)))
+ return result;
+ }
}
- if (rightImm && rightImm.isRepresentableAs<uint32_t>()) {
- if (Inst result = tryTest(Arg::Width32, tmpPromise(left), rightImm))
- return result;
+ if (rightImm) {
+ if ((width == Arg::Width32 && rightImm.value() == 0xffffffff)
+ || (width == Arg::Width64 && rightImm.value() == -1)) {
+ ArgPromise argPromise = tmpPromise(left);
+ if (Inst result = tryTest(width, argPromise, argPromise))
+ return result;
+ }
+ if (rightImm.isRepresentableAs<uint32_t>()) {
+ if (Inst result = tryTest(Arg::Width32, tmpPromise(left), rightImm))
+ return result;
+ }
}
// Finally, just do tmp's.
Modified: trunk/Source/_javascript_Core/b3/air/AirOpcode.opcodes (197651 => 197652)
--- trunk/Source/_javascript_Core/b3/air/AirOpcode.opcodes 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/b3/air/AirOpcode.opcodes 2016-03-07 02:40:16 UTC (rev 197652)
@@ -613,7 +613,7 @@
Compare32 U:G:32, U:G:32, U:G:32, ZD:G:32
RelCond, Tmp, Tmp, Tmp
- x86: RelCond, Tmp, Imm, Tmp
+ RelCond, Tmp, Imm, Tmp
64: Compare64 U:G:32, U:G:64, U:G:64, ZD:G:32
RelCond, Tmp, Tmp, Tmp
@@ -622,6 +622,7 @@
Test32 U:G:32, U:G:32, U:G:32, ZD:G:32
x86: ResCond, Addr, Imm, Tmp
ResCond, Tmp, Tmp, Tmp
+ ResCond, Tmp, BitImm, Tmp
64: Test64 U:G:32, U:G:64, U:G:64, ZD:G:32
x86: ResCond, Tmp, Imm, Tmp
@@ -662,7 +663,7 @@
BranchTest32 U:G:32, U:G:32, U:G:32 /branch
ResCond, Tmp, Tmp
- x86: ResCond, Tmp, Imm
+ ResCond, Tmp, BitImm
x86: ResCond, Addr, Imm
x86: ResCond, Index, Imm
@@ -670,7 +671,7 @@
# BranchTest32 in most cases where you use an immediate.
64: BranchTest64 U:G:32, U:G:64, U:G:64 /branch
ResCond, Tmp, Tmp
- x86: ResCond, Tmp, Imm
+ ResCond, Tmp, BitImm64
x86: ResCond, Addr, Imm
x86: ResCond, Addr, Tmp
x86: ResCond, Index, Imm
@@ -748,6 +749,7 @@
64: MoveConditionally64 U:G:32, U:G:64, U:G:64, U:G:Ptr, U:G:Ptr, D:G:Ptr
RelCond, Tmp, Tmp, Tmp, Tmp, Tmp
+ RelCond, Tmp, Imm, Tmp, Tmp, Tmp
MoveConditionallyTest32 U:G:32, U:G:32, U:G:32, U:G:Ptr, UD:G:Ptr
ResCond, Tmp, Tmp, Tmp, Tmp
@@ -755,7 +757,7 @@
MoveConditionallyTest32 U:G:32, U:G:32, U:G:32, U:G:Ptr, U:G:Ptr, D:G:Ptr
ResCond, Tmp, Tmp, Tmp, Tmp, Tmp
- x86: ResCond, Tmp, Imm, Tmp, Tmp, Tmp
+ ResCond, Tmp, BitImm, Tmp, Tmp, Tmp
64: MoveConditionallyTest64 U:G:32, U:G:64, U:G:64, U:G:Ptr, UD:G:Ptr
ResCond, Tmp, Tmp, Tmp, Tmp
@@ -795,7 +797,7 @@
MoveDoubleConditionallyTest32 U:G:32, U:G:32, U:G:32, U:F:64, U:F:64, D:F:64
ResCond, Tmp, Tmp, Tmp, Tmp, Tmp
- x86: ResCond, Tmp, Imm, Tmp, Tmp, Tmp
+ ResCond, Tmp, BitImm, Tmp, Tmp, Tmp
x86: ResCond, Addr, Imm, Tmp, Tmp, Tmp
x86: ResCond, Index, Imm, Tmp, Tmp, Tmp
Modified: trunk/Source/_javascript_Core/b3/testb3.cpp (197651 => 197652)
--- trunk/Source/_javascript_Core/b3/testb3.cpp 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/b3/testb3.cpp 2016-03-07 02:40:16 UTC (rev 197652)
@@ -150,10 +150,10 @@
static Vector<Int64Operand> int64Operands()
{
Vector<Int64Operand> operands;
- for (const auto& doubleOperand : floatingPointOperands<double>())
- operands.append({ doubleOperand.name, bitwise_cast<int64_t>(doubleOperand.value) });
operands.append({ "1", 1 });
operands.append({ "-1", -1 });
+ operands.append({ "42", 42 });
+ operands.append({ "-42", -42 });
operands.append({ "int64-max", std::numeric_limits<int64_t>::max() });
operands.append({ "int64-min", std::numeric_limits<int64_t>::min() });
operands.append({ "int32-max", std::numeric_limits<int32_t>::max() });
@@ -8822,7 +8822,8 @@
}
}
-int modelCompare(B3::Opcode opcode, int left, int right)
+template<typename InputType>
+InputType modelCompare(B3::Opcode opcode, InputType left, InputType right)
{
switch (opcode) {
case Equal:
@@ -8838,13 +8839,17 @@
case GreaterEqual:
return left >= right;
case Above:
- return static_cast<unsigned>(left) > static_cast<unsigned>(right);
+ return static_cast<typename std::make_unsigned<InputType>::type>(left) >
+ static_cast<typename std::make_unsigned<InputType>::type>(right);
case Below:
- return static_cast<unsigned>(left) < static_cast<unsigned>(right);
+ return static_cast<typename std::make_unsigned<InputType>::type>(left) <
+ static_cast<typename std::make_unsigned<InputType>::type>(right);
case AboveEqual:
- return static_cast<unsigned>(left) >= static_cast<unsigned>(right);
+ return static_cast<typename std::make_unsigned<InputType>::type>(left) >=
+ static_cast<typename std::make_unsigned<InputType>::type>(right);
case BelowEqual:
- return static_cast<unsigned>(left) <= static_cast<unsigned>(right);
+ return static_cast<typename std::make_unsigned<InputType>::type>(left) <=
+ static_cast<typename std::make_unsigned<InputType>::type>(right);
case BitAnd:
return !!(left & right);
default:
@@ -8939,7 +8944,8 @@
void testCompareImpl(B3::Opcode opcode, int64_t left, int64_t right)
{
- int result = modelCompare(opcode, left, right);
+ int64_t result = modelCompare(opcode, left, right);
+ int32_t int32Result = modelCompare(opcode, static_cast<int32_t>(left), static_cast<int32_t>(right));
// Test tmp-to-tmp.
genericTestCompare(
@@ -8963,7 +8969,7 @@
proc, Trunc, Origin(),
block->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1));
},
- left, right, result);
+ left, right, int32Result);
// Test imm-to-tmp.
genericTestCompare(
@@ -8985,7 +8991,7 @@
proc, Trunc, Origin(),
block->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1));
},
- left, right, result);
+ left, right, int32Result);
// Test tmp-to-imm.
genericTestCompare(
@@ -9007,7 +9013,7 @@
[&] (BasicBlock* block, Procedure& proc) {
return block->appendNew<Const32Value>(proc, Origin(), right);
},
- left, right, result);
+ left, right, int32Result);
// Test imm-to-imm.
genericTestCompare(
@@ -9027,7 +9033,7 @@
[&] (BasicBlock* block, Procedure& proc) {
return block->appendNew<Const32Value>(proc, Origin(), right);
},
- left, right, result);
+ left, right, int32Result);
testCompareLoad<int32_t>(opcode, Load, left, right);
testCompareLoad<int8_t>(opcode, Load8S, left, right);
@@ -9036,37 +9042,11 @@
testCompareLoad<uint16_t>(opcode, Load16Z, left, right);
}
-void testCompare(B3::Opcode opcode, int left, int right)
+void testCompare(B3::Opcode opcode, int64_t left, int64_t right)
{
- auto variants = [&] (int left, int right) {
- testCompareImpl(opcode, left, right);
- testCompareImpl(opcode, left, right + 1);
- testCompareImpl(opcode, left, right - 1);
-
- auto multipliedTests = [&] (int factor) {
- testCompareImpl(opcode, left * factor, right);
- testCompareImpl(opcode, left * factor, right + 1);
- testCompareImpl(opcode, left * factor, right - 1);
-
- testCompareImpl(opcode, left, right * factor);
- testCompareImpl(opcode, left, (right + 1) * factor);
- testCompareImpl(opcode, left, (right - 1) * factor);
-
- testCompareImpl(opcode, left * factor, right * factor);
- testCompareImpl(opcode, left * factor, (right + 1) * factor);
- testCompareImpl(opcode, left * factor, (right - 1) * factor);
- };
-
- multipliedTests(10);
- multipliedTests(100);
- multipliedTests(1000);
- multipliedTests(100000);
- };
-
- variants(left, right);
- variants(-left, right);
- variants(left, -right);
- variants(-left, -right);
+ testCompareImpl(opcode, left, right);
+ testCompareImpl(opcode, left, right + 1);
+ testCompareImpl(opcode, left, right - 1);
}
void testEqualDouble(double left, double right, bool result)
@@ -10899,6 +10879,20 @@
CHECK(invoke<int>(*code, true, false) == 667);
}
+double b3Pow(double x, int y)
+{
+ if (y < 0 || y > 1000)
+ return pow(x, y);
+ double result = 1;
+ while (y) {
+ if (y & 1)
+ result *= x;
+ x *= x;
+ y >>= 1;
+ }
+ return result;
+}
+
void testPowDoubleByIntegerLoop(double xOperand, int32_t yOperand)
{
Procedure proc;
@@ -10911,7 +10905,7 @@
BasicBlock* continuation = result.first;
continuation->appendNew<ControlValue>(proc, Return, Origin(), result.second);
- CHECK(isIdentical(compileAndRun<double>(proc, xOperand, yOperand), pow(xOperand, yOperand)));
+ CHECK(isIdentical(compileAndRun<double>(proc, xOperand, yOperand), b3Pow(xOperand, yOperand)));
}
void testTruncOrHigh()
@@ -12248,20 +12242,18 @@
RUN(testCheckMulArgumentAliasing64());
RUN(testCheckMulArgumentAliasing32());
- RUN(testCompare(Equal, 42, 42));
- RUN(testCompare(NotEqual, 42, 42));
- RUN(testCompare(LessThan, 42, 42));
- RUN(testCompare(GreaterThan, 42, 42));
- RUN(testCompare(LessEqual, 42, 42));
- RUN(testCompare(GreaterEqual, 42, 42));
- RUN(testCompare(Below, 42, 42));
- RUN(testCompare(Above, 42, 42));
- RUN(testCompare(BelowEqual, 42, 42));
- RUN(testCompare(AboveEqual, 42, 42));
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(Equal, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(NotEqual, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(LessThan, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(GreaterThan, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(LessEqual, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(GreaterEqual, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(Below, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(Above, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(BelowEqual, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(AboveEqual, a, b); }, int64Operands(), int64Operands());
+ RUN_BINARY([](int32_t a, int32_t b) { testCompare(BitAnd, a, b); }, int64Operands(), int64Operands());
- RUN(testCompare(BitAnd, 42, 42));
- RUN(testCompare(BitAnd, 42, 0));
-
RUN(testEqualDouble(42, 42, true));
RUN(testEqualDouble(0, -0, true));
RUN(testEqualDouble(42, 43, false));
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (197651 => 197652)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2016-03-07 02:40:16 UTC (rev 197652)
@@ -1293,14 +1293,14 @@
notTaken = tmp;
}
- if (node->child1()->isBooleanConstant()) {
- bool imm = node->child1()->asBoolean();
+ if (node->child1()->isInt32Constant()) {
+ int32_t imm = node->child1()->asInt32();
SpeculateBooleanOperand op2(this, node->child2());
- branch32(condition, JITCompiler::Imm32(static_cast<int32_t>(JSValue::encode(jsBoolean(imm)))), op2.gpr(), taken);
- } else if (node->child2()->isBooleanConstant()) {
+ branch32(condition, JITCompiler::Imm32(imm), op2.gpr(), taken);
+ } else if (node->child2()->isInt32Constant()) {
SpeculateBooleanOperand op1(this, node->child1());
- bool imm = node->child2()->asBoolean();
- branch32(condition, op1.gpr(), JITCompiler::Imm32(static_cast<int32_t>(JSValue::encode(jsBoolean(imm)))), taken);
+ int32_t imm = node->child2()->asInt32();
+ branch32(condition, op1.gpr(), JITCompiler::Imm32(imm), taken);
} else {
SpeculateBooleanOperand op1(this, node->child1());
SpeculateBooleanOperand op2(this, node->child2());
Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp (197651 => 197652)
--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp 2016-03-07 02:40:16 UTC (rev 197652)
@@ -1566,15 +1566,34 @@
void SpeculativeJIT::compileInt32Compare(Node* node, MacroAssembler::RelationalCondition condition)
{
- SpeculateInt32Operand op1(this, node->child1());
- SpeculateInt32Operand op2(this, node->child2());
- GPRTemporary result(this, Reuse, op1, op2);
-
- m_jit.compare32(condition, op1.gpr(), op2.gpr(), result.gpr());
-
- // If we add a DataFormatBool, we should use it here.
- m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
- jsValueResult(result.gpr(), m_currentNode, DataFormatJSBoolean);
+ if (node->child1()->isInt32Constant()) {
+ SpeculateInt32Operand op2(this, node->child2());
+ GPRTemporary result(this, Reuse, op2);
+ int32_t imm = node->child1()->asInt32();
+ m_jit.compare32(condition, JITCompiler::Imm32(imm), op2.gpr(), result.gpr());
+
+ // If we add a DataFormatBool, we should use it here.
+ m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
+ jsValueResult(result.gpr(), m_currentNode, DataFormatJSBoolean);
+ } else if (node->child2()->isInt32Constant()) {
+ SpeculateInt32Operand op1(this, node->child1());
+ GPRTemporary result(this, Reuse, op1);
+ int32_t imm = node->child2()->asInt32();
+ m_jit.compare32(condition, op1.gpr(), JITCompiler::Imm32(imm), result.gpr());
+
+ // If we add a DataFormatBool, we should use it here.
+ m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
+ jsValueResult(result.gpr(), m_currentNode, DataFormatJSBoolean);
+ } else {
+ SpeculateInt32Operand op1(this, node->child1());
+ SpeculateInt32Operand op2(this, node->child2());
+ GPRTemporary result(this, Reuse, op1, op2);
+ m_jit.compare32(condition, op1.gpr(), op2.gpr(), result.gpr());
+
+ // If we add a DataFormatBool, we should use it here.
+ m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
+ jsValueResult(result.gpr(), m_currentNode, DataFormatJSBoolean);
+ }
}
void SpeculativeJIT::compileInt52Compare(Node* node, MacroAssembler::RelationalCondition condition)
Modified: trunk/Source/WebCore/ChangeLog (197651 => 197652)
--- trunk/Source/WebCore/ChangeLog 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/WebCore/ChangeLog 2016-03-07 02:40:16 UTC (rev 197652)
@@ -1,3 +1,13 @@
+2016-03-06 Benjamin Poulain <[email protected]>
+
+ [JSC] Improve codegen of Compare and Test
+ https://bugs.webkit.org/show_bug.cgi?id=155055
+
+ Reviewed by Filip Pizlo.
+
+ * cssjit/FunctionCall.h:
+ (WebCore::FunctionCall::callAndBranchOnCondition):
+
2016-03-06 Saam Barati <[email protected]>
[[GetPrototypeOf]] should be a fully virtual method in the method table
Modified: trunk/Source/WebCore/cssjit/FunctionCall.h (197651 => 197652)
--- trunk/Source/WebCore/cssjit/FunctionCall.h 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/WebCore/cssjit/FunctionCall.h 2016-03-07 02:40:16 UTC (rev 197652)
@@ -87,7 +87,7 @@
JSC::MacroAssembler::Jump callAndBranchOnCondition(JSC::MacroAssembler::ResultCondition condition, JSC::MacroAssembler::TrustedImm32 mask)
{
prepareAndCall();
- m_assembler.test32(condition, JSC::GPRInfo::returnValueGPR, mask);
+ m_assembler.test32(JSC::GPRInfo::returnValueGPR, mask);
cleanupPostCall();
return m_assembler.branch(condition);
}
Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (197651 => 197652)
--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp 2016-03-07 02:40:16 UTC (rev 197651)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp 2016-03-07 02:40:16 UTC (rev 197652)
@@ -2389,7 +2389,7 @@
LocalRegister divisorRegister(m_registerAllocator);
m_assembler.move(Assembler::TrustedImm64(divisor), divisorRegister);
m_assembler.m_assembler.idivl_r(divisorRegister);
- m_assembler.test32(condition, remainder);
+ m_assembler.test32(remainder);
}
// 3) Return RAX and RDX.