Modified: trunk/Source/_javascript_Core/b3/B3ReduceStrength.cpp (193435 => 193436)
--- trunk/Source/_javascript_Core/b3/B3ReduceStrength.cpp 2015-12-04 20:29:49 UTC (rev 193435)
+++ trunk/Source/_javascript_Core/b3/B3ReduceStrength.cpp 2015-12-04 20:31:14 UTC (rev 193436)
@@ -571,6 +571,17 @@
break;
}
+ // Turn this: Select(BitAnd(bool, xyz1), a, b)
+ // Into this: Select(bool, a, b)
+ if (m_value->child(0)->opcode() == BitAnd
+ && m_value->child(0)->child(1)->hasInt()
+ && m_value->child(0)->child(1)->asInt() & 1
+ && m_value->child(0)->child(0)->returnsBool()) {
+ m_value->child(0) = m_value->child(0)->child(0);
+ m_changed = true;
+ break;
+ }
+
// Turn this: Select(stuff, x, x)
// Into this: x
if (m_value->child(1) == m_value->child(2)) {
@@ -845,7 +856,17 @@
std::swap(branch->taken(), branch->notTaken());
m_changed = true;
}
-
+
+ // Turn this: Branch(BitAnd(bool, xyb1), then, else)
+ // Into this: Branch(bool, then, else)
+ if (branch->child(0)->opcode() == BitAnd
+ && branch->child(0)->child(1)->hasInt()
+ && branch->child(0)->child(1)->asInt() & 1
+ && branch->child(0)->child(0)->returnsBool()) {
+ branch->child(0) = branch->child(0)->child(0);
+ m_changed = true;
+ }
+
TriState triState = branch->child(0)->asTriState();
// Turn this: Branch(0, then, else)
Modified: trunk/Source/_javascript_Core/b3/testb3.cpp (193435 => 193436)
--- trunk/Source/_javascript_Core/b3/testb3.cpp 2015-12-04 20:29:49 UTC (rev 193435)
+++ trunk/Source/_javascript_Core/b3/testb3.cpp 2015-12-04 20:31:14 UTC (rev 193436)
@@ -998,6 +998,29 @@
CHECK(compileAndRun<int>(proc, b) == (a & (b & c)));
}
+void testBitAndWithMaskReturnsBooleans(int64_t a, int64_t b)
+{
+ Procedure proc;
+ BasicBlock* root = proc.addBlock();
+ Value* arg0 = root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0);
+ Value* arg1 = root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1);
+ Value* equal = root->appendNew<Value>(proc, Equal, Origin(), arg0, arg1);
+ Value* maskedEqual = root->appendNew<Value>(proc, BitAnd, Origin(),
+ root->appendNew<Const32Value>(proc, Origin(), 0x5),
+ equal);
+ Value* inverted = root->appendNew<Value>(proc, BitXor, Origin(),
+ root->appendNew<Const32Value>(proc, Origin(), 0x1),
+ maskedEqual);
+ Value* select = root->appendNew<Value>(proc, Select, Origin(), inverted,
+ root->appendNew<Const64Value>(proc, Origin(), 42),
+ root->appendNew<Const64Value>(proc, Origin(), -5));
+
+ root->appendNew<ControlValue>(proc, Return, Origin(), select);
+
+ int64_t expected = (a == b) ? -5 : 42;
+ CHECK(compileAndRun<int64_t>(proc, a, b) == expected);
+}
+
void testBitOrArgs(int64_t a, int64_t b)
{
Procedure proc;
@@ -5781,6 +5804,7 @@
RUN(testBitAndImmBitAndArgImm32(7, 2, 3));
RUN(testBitAndImmBitAndArgImm32(6, 1, 6));
RUN(testBitAndImmBitAndArgImm32(24, 0xffff, 7));
+ RUN_BINARY(testBitAndWithMaskReturnsBooleans, int64Operands(), int64Operands());
RUN(testBitOrArgs(43, 43));
RUN(testBitOrArgs(43, 0));