[JSC] Use Div and ChillDiv in FTL(B3)Output
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Dec 2015 20:32:21 +0000 (20:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Dec 2015 20:32:21 +0000 (20:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151844

Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-12-04
Reviewed by Geoffrey Garen.

I copied part of the code of compileArithDiv()
to create a new function FTLOutput::childDiv().

With childDiv() being a concept of FTLOutput,
FTLB3Output was updated accordingly.

* ftl/FTLB3Output.h:
(JSC::FTL::Output::div):
(JSC::FTL::Output::chillDiv):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::DFG::LowerDFGToLLVM::compileArithDiv):
* ftl/FTLOutput.cpp:
(JSC::FTL::Output::chillDiv):
* ftl/FTLOutput.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@193437 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/ftl/FTLB3Output.h
Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp
Source/JavaScriptCore/ftl/FTLOutput.cpp
Source/JavaScriptCore/ftl/FTLOutput.h

index d9ea2e4..fb2abaa 100644 (file)
@@ -1,5 +1,27 @@
 2015-12-04  Benjamin Poulain  <bpoulain@apple.com>
 
+        [JSC] Use Div and ChillDiv in FTL(B3)Output
+        https://bugs.webkit.org/show_bug.cgi?id=151844
+
+        Reviewed by Geoffrey Garen.
+
+        I copied part of the code of compileArithDiv()
+        to create a new function FTLOutput::childDiv().
+
+        With childDiv() being a concept of FTLOutput,
+        FTLB3Output was updated accordingly.
+
+        * ftl/FTLB3Output.h:
+        (JSC::FTL::Output::div):
+        (JSC::FTL::Output::chillDiv):
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::DFG::LowerDFGToLLVM::compileArithDiv):
+        * ftl/FTLOutput.cpp:
+        (JSC::FTL::Output::chillDiv):
+        * ftl/FTLOutput.h:
+
+2015-12-04  Benjamin Poulain  <bpoulain@apple.com>
+
         [JSC] Extend the strength reduction of B3's BitAnd with booleans
         https://bugs.webkit.org/show_bug.cgi?id=151852
 
index 792a190..e41b250 100644 (file)
@@ -121,7 +121,8 @@ public:
     LValue add(LValue left, LValue right) { return m_block->appendNew<B3::Value>(m_proc, B3::Add, origin(), left, right); }
     LValue sub(LValue left, LValue right) { return m_block->appendNew<B3::Value>(m_proc, B3::Sub, origin(), left, right); }
     LValue mul(LValue left, LValue right) { return m_block->appendNew<B3::Value>(m_proc, B3::Mul, origin(), left, right); }
-    LValue div(LValue left, LValue right) { CRASH(); }
+    LValue div(LValue left, LValue right) { return m_block->appendNew<B3::Value>(m_proc, B3::Div, origin(), left, right); }
+    LValue chillDiv(LValue left, LValue right) { return m_block->appendNew<B3::Value>(m_proc, B3::ChillDiv, origin(), left, right); }
     LValue rem(LValue left, LValue right) { CRASH(); }
     LValue neg(LValue value)
     {
index f7a5db5..1886120 100644 (file)
@@ -1875,88 +1875,49 @@ private:
         case Int32Use: {
             LValue numerator = lowInt32(m_node->child1());
             LValue denominator = lowInt32(m_node->child2());
-            
-            LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, ("ArithDiv unsafe denominator"));
-            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArithDiv continuation"));
-            LBasicBlock done = FTL_NEW_BLOCK(m_out, ("ArithDiv done"));
-            
-            Vector<ValueFromBlock, 3> results;
-            
-            LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
-            
-            m_out.branch(
-                m_out.above(adjustedDenominator, m_out.int32One),
-                usually(continuation), rarely(unsafeDenominator));
-            
-            LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
-            
-            LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
-            
-            if (shouldCheckOverflow(m_node->arithMode())) {
-                LValue cond = m_out.bitOr(m_out.isZero32(denominator), m_out.equal(numerator, neg2ToThe31));
-                speculate(Overflow, noValue(), 0, cond);
-                m_out.jump(continuation);
-            } else {
-                // This is the case where we convert the result to an int after we're done. So,
-                // if the denominator is zero, then the result should be zero.
-                // If the denominator is not zero (i.e. it's -1 because we're guarded by the
-                // check above) and the numerator is -2^31 then the result should be -2^31.
-                
-                LBasicBlock divByZero = FTL_NEW_BLOCK(m_out, ("ArithDiv divide by zero"));
-                LBasicBlock notDivByZero = FTL_NEW_BLOCK(m_out, ("ArithDiv not divide by zero"));
-                LBasicBlock neg2ToThe31ByNeg1 = FTL_NEW_BLOCK(m_out, ("ArithDiv -2^31/-1"));
-                
-                m_out.branch(
-                    m_out.isZero32(denominator), rarely(divByZero), usually(notDivByZero));
-                
-                m_out.appendTo(divByZero, notDivByZero);
-                results.append(m_out.anchor(m_out.int32Zero));
-                m_out.jump(done);
-                
-                m_out.appendTo(notDivByZero, neg2ToThe31ByNeg1);
-                m_out.branch(
-                    m_out.equal(numerator, neg2ToThe31),
-                    rarely(neg2ToThe31ByNeg1), usually(continuation));
-                
-                m_out.appendTo(neg2ToThe31ByNeg1, continuation);
-                results.append(m_out.anchor(neg2ToThe31));
-                m_out.jump(done);
-            }
-            
-            m_out.appendTo(continuation, done);
-            
+
             if (shouldCheckNegativeZero(m_node->arithMode())) {
                 LBasicBlock zeroNumerator = FTL_NEW_BLOCK(m_out, ("ArithDiv zero numerator"));
                 LBasicBlock numeratorContinuation = FTL_NEW_BLOCK(m_out, ("ArithDiv numerator continuation"));
-                
+
                 m_out.branch(
                     m_out.isZero32(numerator),
                     rarely(zeroNumerator), usually(numeratorContinuation));
-                
+
                 LBasicBlock innerLastNext = m_out.appendTo(zeroNumerator, numeratorContinuation);
-                
+
                 speculate(
                     NegativeZero, noValue(), 0, m_out.lessThan(denominator, m_out.int32Zero));
-                
+
                 m_out.jump(numeratorContinuation);
-                
+
                 m_out.appendTo(numeratorContinuation, innerLastNext);
             }
             
-            LValue result = m_out.div(numerator, denominator);
-            
             if (shouldCheckOverflow(m_node->arithMode())) {
+                LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, ("ArithDiv unsafe denominator"));
+                LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArithDiv continuation"));
+
+                LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
+                m_out.branch(
+                    m_out.above(adjustedDenominator, m_out.int32One),
+                    usually(continuation), rarely(unsafeDenominator));
+
+                LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
+                LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
+                LValue cond = m_out.bitOr(m_out.isZero32(denominator), m_out.equal(numerator, neg2ToThe31));
+                speculate(Overflow, noValue(), 0, cond);
+                m_out.jump(continuation);
+
+                m_out.appendTo(continuation, lastNext);
+                LValue result = m_out.div(numerator, denominator);
                 speculate(
                     Overflow, noValue(), 0,
                     m_out.notEqual(m_out.mul(result, denominator), numerator));
-            }
-            
-            results.append(m_out.anchor(result));
-            m_out.jump(done);
-            
-            m_out.appendTo(done, lastNext);
-            
-            setInt32(m_out.phi(m_out.int32, results));
+                setInt32(result);
+            } else
+                setInt32(m_out.chillDiv(numerator, denominator));
+
             break;
         }
             
index 261cfb5..b921026 100644 (file)
@@ -75,6 +75,47 @@ LBasicBlock Output::newBlock(const char* name)
     return insertBasicBlock(m_context, m_nextBlock, name);
 }
 
+LValue Output::chillDiv(LValue numerator, LValue denominator)
+{
+    LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(*this, ("ChillDiv unsafe denominator"));
+    LBasicBlock continuation = FTL_NEW_BLOCK(*this, ("ChillDiv continuation"));
+    LBasicBlock done = FTL_NEW_BLOCK(*this, ("ChillDiv done"));
+    LBasicBlock divByZero = FTL_NEW_BLOCK(*this, ("ChillDiv divide by zero"));
+    LBasicBlock notDivByZero = FTL_NEW_BLOCK(*this, ("ChillDiv not divide by zero"));
+    LBasicBlock neg2ToThe31ByNeg1 = FTL_NEW_BLOCK(*this, ("ArithDiv -2^31/-1"));
+
+    LValue adjustedDenominator = add(denominator, int32One);
+    branch(
+        above(adjustedDenominator, int32One),
+        usually(continuation), rarely(unsafeDenominator));
+
+    Vector<ValueFromBlock, 3> results;
+    LBasicBlock lastNext = appendTo(unsafeDenominator, continuation);
+
+    LValue neg2ToThe31 = constInt32(-2147483647-1);
+    branch(isZero32(denominator), rarely(divByZero), usually(notDivByZero));
+
+    appendTo(divByZero, notDivByZero);
+    results.append(anchor(int32Zero));
+    jump(done);
+
+    appendTo(notDivByZero, neg2ToThe31ByNeg1);
+    branch(equal(numerator, neg2ToThe31),
+        rarely(neg2ToThe31ByNeg1), usually(continuation));
+
+    appendTo(neg2ToThe31ByNeg1, continuation);
+    results.append(anchor(neg2ToThe31));
+    jump(done);
+
+    appendTo(continuation, done);
+    LValue result = div(numerator, denominator);
+    results.append(anchor(result));
+    jump(done);
+
+    appendTo(done, lastNext);
+    return phi(int32, results);
+}
+
 LValue Output::sensibleDoubleToInt(LValue value)
 {
     RELEASE_ASSERT(isX86());
index 9a53f42..f79d6d6 100644 (file)
@@ -123,6 +123,7 @@ public:
     LValue sub(LValue left, LValue right) { return buildSub(m_builder, left, right); }
     LValue mul(LValue left, LValue right) { return buildMul(m_builder, left, right); }
     LValue div(LValue left, LValue right) { return buildDiv(m_builder, left, right); }
+    LValue chillDiv(LValue left, LValue right);
     LValue rem(LValue left, LValue right) { return buildRem(m_builder, left, right); }
     LValue neg(LValue value) { return buildNeg(m_builder, value); }