Title: [193436] trunk/Source/_javascript_Core
Revision
193436
Author
commit-qu...@webkit.org
Date
2015-12-04 12:31:14 -0800 (Fri, 04 Dec 2015)

Log Message

[JSC] Extend the strength reduction of B3's BitAnd with booleans
https://bugs.webkit.org/show_bug.cgi?id=151852

Patch by Benjamin Poulain <bpoul...@apple.com> on 2015-12-04
Reviewed by Saam Barati.

1) Masking a boolean with any pattern that has the lsb set
   remains a boolean.
2) ReduceStrength on that particular pattern of BitAnd.

* b3/B3ReduceStrength.cpp:
* b3/B3Value.cpp:
(JSC::B3::Value::returnsBool):
* b3/testb3.cpp:
(JSC::B3::testBitAndWithMaskReturnsBooleans):
(JSC::B3::run):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (193435 => 193436)


--- trunk/Source/_javascript_Core/ChangeLog	2015-12-04 20:29:49 UTC (rev 193435)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-12-04 20:31:14 UTC (rev 193436)
@@ -1,5 +1,23 @@
 2015-12-04  Benjamin Poulain  <bpoul...@apple.com>
 
+        [JSC] Extend the strength reduction of B3's BitAnd with booleans
+        https://bugs.webkit.org/show_bug.cgi?id=151852
+
+        Reviewed by Saam Barati.
+
+        1) Masking a boolean with any pattern that has the lsb set
+           remains a boolean.
+        2) ReduceStrength on that particular pattern of BitAnd.
+
+        * b3/B3ReduceStrength.cpp:
+        * b3/B3Value.cpp:
+        (JSC::B3::Value::returnsBool):
+        * b3/testb3.cpp:
+        (JSC::B3::testBitAndWithMaskReturnsBooleans):
+        (JSC::B3::run):
+
+2015-12-04  Benjamin Poulain  <bpoul...@apple.com>
+
         [JSC] Add doubleRem() to FTLB3Output
         https://bugs.webkit.org/show_bug.cgi?id=151851
 

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/B3Value.cpp (193435 => 193436)


--- trunk/Source/_javascript_Core/b3/B3Value.cpp	2015-12-04 20:29:49 UTC (rev 193435)
+++ trunk/Source/_javascript_Core/b3/B3Value.cpp	2015-12-04 20:31:14 UTC (rev 193436)
@@ -266,7 +266,7 @@
     case Const32:
         return asInt32() == 0 || asInt32() == 1;
     case BitAnd:
-        return child(1)->isInt32(1);
+        return child(1)->hasInt() && child(1)->asInt() & 1;
     case Equal:
     case NotEqual:
     case LessThan:

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));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to