Changeset 229513 in webkit for trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp
- Timestamp:
- Mar 10, 2018, 11:16:15 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp
r221954 r229513 1667 1667 1668 1668 case LessThan: 1669 // FIXME: We could do a better job of canonicalizing integer comparisons.1670 // https://bugs.webkit.org/show_bug.cgi?id=1509581671 1672 replaceWithNewValue(1673 m_proc.addBoolConstant(1674 m_value->origin(),1675 m_value->child(0)->lessThanConstant(m_value->child(1))));1676 break;1677 1678 1669 case GreaterThan: 1679 replaceWithNewValue(1680 m_proc.addBoolConstant(1681 m_value->origin(),1682 m_value->child(0)->greaterThanConstant(m_value->child(1))));1683 break;1684 1685 1670 case LessEqual: 1686 replaceWithNewValue(1687 m_proc.addBoolConstant(1688 m_value->origin(),1689 m_value->child(0)->lessEqualConstant(m_value->child(1))));1690 break;1691 1692 1671 case GreaterEqual: 1693 replaceWithNewValue(1694 m_proc.addBoolConstant(1695 m_value->origin(),1696 m_value->child(0)->greaterEqualConstant(m_value->child(1))));1697 break;1698 1699 1672 case Above: 1700 replaceWithNewValue(1701 m_proc.addBoolConstant(1702 m_value->origin(),1703 m_value->child(0)->aboveConstant(m_value->child(1))));1704 break;1705 1706 1673 case Below: 1707 replaceWithNewValue(1708 m_proc.addBoolConstant(1709 m_value->origin(),1710 m_value->child(0)->belowConstant(m_value->child(1))));1711 break;1712 1713 1674 case AboveEqual: 1714 replaceWithNewValue( 1715 m_proc.addBoolConstant( 1716 m_value->origin(), 1717 m_value->child(0)->aboveEqualConstant(m_value->child(1)))); 1718 break; 1719 1720 case BelowEqual: 1721 replaceWithNewValue( 1722 m_proc.addBoolConstant( 1723 m_value->origin(), 1724 m_value->child(0)->belowEqualConstant(m_value->child(1)))); 1725 break; 1675 case BelowEqual: { 1676 auto* value = newComparisonVaueIfNecessary(); 1677 TriState result = MixedTriState; 1678 switch (value->opcode()) { 1679 case LessThan: 1680 result = value->child(1)->greaterThanConstant(value->child(0)); 1681 break; 1682 case GreaterThan: 1683 result = value->child(1)->lessThanConstant(value->child(0)); 1684 break; 1685 case LessEqual: 1686 result = value->child(1)->greaterEqualConstant(value->child(0)); 1687 break; 1688 case GreaterEqual: 1689 result = value->child(1)->lessEqualConstant(value->child(0)); 1690 break; 1691 case Above: 1692 result = value->child(1)->belowConstant(value->child(0)); 1693 break; 1694 case Below: 1695 result = value->child(1)->aboveConstant(value->child(0)); 1696 break; 1697 case AboveEqual: 1698 result = value->child(1)->belowEqualConstant(value->child(0)); 1699 break; 1700 case BelowEqual: 1701 result = value->child(1)->aboveEqualConstant(value->child(0)); 1702 break; 1703 default: 1704 RELEASE_ASSERT_NOT_REACHED(); 1705 break; 1706 } 1707 1708 if (auto* constant = m_proc.addBoolConstant(value->origin(), result)) { 1709 replaceWithNewValue(constant); 1710 break; 1711 } 1712 1713 // Replace with newly created "value". Its opcode is flipped and operands are swapped from m_value. 1714 if (m_value != value) 1715 replaceWithNewValue(value); 1716 break; 1717 } 1726 1718 1727 1719 case EqualOrUnordered: … … 2135 2127 } 2136 2128 2129 static bool shouldSwapBinaryOperands(Value* value) 2130 { 2131 // Note that we have commutative operations that take more than two children. Those operations may 2132 // commute their first two children while leaving the rest unaffected. 2133 ASSERT(value->numChildren() >= 2); 2134 2135 // Leave it alone if the right child is a constant. 2136 if (value->child(1)->isConstant() 2137 || value->child(0)->opcode() == AtomicStrongCAS) 2138 return false; 2139 2140 if (value->child(0)->isConstant()) 2141 return true; 2142 2143 if (value->child(1)->opcode() == AtomicStrongCAS) 2144 return true; 2145 2146 // Sort the operands. This is an important canonicalization. We use the index instead of 2147 // the address to make this at least slightly deterministic. 2148 if (value->child(0)->index() > value->child(1)->index()) 2149 return true; 2150 2151 return false; 2152 } 2153 2137 2154 // Turn this: Add(constant, value) 2138 2155 // Into this: Add(value, constant) … … 2144 2161 void handleCommutativity() 2145 2162 { 2146 // Note that we have commutative operations that take more than two children. Those operations may 2147 // commute their first two children while leaving the rest unaffected. 2148 ASSERT(m_value->numChildren() >= 2); 2149 2150 // Leave it alone if the right child is a constant. 2151 if (m_value->child(1)->isConstant() 2152 || m_value->child(0)->opcode() == AtomicStrongCAS) 2153 return; 2154 2155 auto swap = [&] () { 2163 if (shouldSwapBinaryOperands(m_value)) { 2156 2164 std::swap(m_value->child(0), m_value->child(1)); 2157 2165 m_changed = true; 2166 } 2167 } 2168 2169 Value* newComparisonVaueIfNecessary() 2170 { 2171 auto flip = [] (Opcode opcode) { 2172 switch (opcode) { 2173 case LessThan: 2174 return GreaterThan; 2175 case GreaterThan: 2176 return LessThan; 2177 case LessEqual: 2178 return GreaterEqual; 2179 case GreaterEqual: 2180 return LessEqual; 2181 case Above: 2182 return Below; 2183 case Below: 2184 return Above; 2185 case AboveEqual: 2186 return BelowEqual; 2187 case BelowEqual: 2188 return AboveEqual; 2189 default: 2190 return opcode; 2191 } 2158 2192 }; 2159 2160 if (m_value->child(0)->isConstant()) 2161 return swap(); 2162 2163 if (m_value->child(1)->opcode() == AtomicStrongCAS) 2164 return swap(); 2165 2166 // Sort the operands. This is an important canonicalization. We use the index instead of 2167 // the address to make this at least slightly deterministic. 2168 if (m_value->child(0)->index() > m_value->child(1)->index()) 2169 return swap(); 2193 if (shouldSwapBinaryOperands(m_value)) { 2194 m_changed = true; 2195 return m_proc.add<Value>(flip(m_value->opcode()), m_value->origin(), m_value->child(1), m_value->child(0)); 2196 } 2197 return m_value; 2170 2198 } 2171 2199
Note:
See TracChangeset
for help on using the changeset viewer.