Ignore:
Timestamp:
Mar 11, 2018, 12:52:24 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

[B3] Above/Below should be strength-reduced for comparison with 0
https://bugs.webkit.org/show_bug.cgi?id=183543

Reviewed by Filip Pizlo.

Above(0, x) and BelowEqual(0, x) can be converted to constants false and true respectively.
This can be seen in ArraySlice(0) case: Select(Above(0, length), length, 0) this should
be converted to 0. This patch adds such a folding to comparisons.

We also fix B3ReduceStrength issue creating an orphan value. If a flipped value is folded to
a constant, we do not insert flipped value and make it an orphan. This issue causes JSC test
failure with this B3Const32/64Value change. With this patch, we create a flipped value only
when we fail to fold it to a constant.

  • b3/B3Const32Value.cpp:

(JSC::B3::Const32Value::lessThanConstant const):
(JSC::B3::Const32Value::greaterThanConstant const):
(JSC::B3::Const32Value::lessEqualConstant const):
(JSC::B3::Const32Value::greaterEqualConstant const):
(JSC::B3::Const32Value::aboveConstant const):
(JSC::B3::Const32Value::belowConstant const):
(JSC::B3::Const32Value::aboveEqualConstant const):
(JSC::B3::Const32Value::belowEqualConstant const):

  • b3/B3Const64Value.cpp:

(JSC::B3::Const64Value::lessThanConstant const):
(JSC::B3::Const64Value::greaterThanConstant const):
(JSC::B3::Const64Value::lessEqualConstant const):
(JSC::B3::Const64Value::greaterEqualConstant const):
(JSC::B3::Const64Value::aboveConstant const):
(JSC::B3::Const64Value::belowConstant const):
(JSC::B3::Const64Value::aboveEqualConstant const):
(JSC::B3::Const64Value::belowEqualConstant const):

  • b3/B3ReduceStrength.cpp:
  • b3/testb3.cpp:

(JSC::B3::int64Operands):
(JSC::B3::int32Operands):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp

    r229513 r229517  
    16741674        case AboveEqual:
    16751675        case BelowEqual: {
    1676             auto* value = newComparisonVaueIfNecessary();
     1676            CanonicalizedComparison comparison = canonicalizeComparison(m_value);
    16771677            TriState result = MixedTriState;
    1678             switch (value->opcode()) {
     1678            switch (comparison.opcode) {
    16791679            case LessThan:
    1680                 result = value->child(1)->greaterThanConstant(value->child(0));
     1680                result = comparison.operands[1]->greaterThanConstant(comparison.operands[0]);
    16811681                break;
    16821682            case GreaterThan:
    1683                 result = value->child(1)->lessThanConstant(value->child(0));
     1683                result = comparison.operands[1]->lessThanConstant(comparison.operands[0]);
    16841684                break;
    16851685            case LessEqual:
    1686                 result = value->child(1)->greaterEqualConstant(value->child(0));
     1686                result = comparison.operands[1]->greaterEqualConstant(comparison.operands[0]);
    16871687                break;
    16881688            case GreaterEqual:
    1689                 result = value->child(1)->lessEqualConstant(value->child(0));
     1689                result = comparison.operands[1]->lessEqualConstant(comparison.operands[0]);
    16901690                break;
    16911691            case Above:
    1692                 result = value->child(1)->belowConstant(value->child(0));
     1692                result = comparison.operands[1]->belowConstant(comparison.operands[0]);
    16931693                break;
    16941694            case Below:
    1695                 result = value->child(1)->aboveConstant(value->child(0));
     1695                result = comparison.operands[1]->aboveConstant(comparison.operands[0]);
    16961696                break;
    16971697            case AboveEqual:
    1698                 result = value->child(1)->belowEqualConstant(value->child(0));
     1698                result = comparison.operands[1]->belowEqualConstant(comparison.operands[0]);
    16991699                break;
    17001700            case BelowEqual:
    1701                 result = value->child(1)->aboveEqualConstant(value->child(0));
     1701                result = comparison.operands[1]->aboveEqualConstant(comparison.operands[0]);
    17021702                break;
    17031703            default:
     
    17061706            }
    17071707
    1708             if (auto* constant = m_proc.addBoolConstant(value->origin(), result)) {
     1708            if (auto* constant = m_proc.addBoolConstant(m_value->origin(), result)) {
    17091709                replaceWithNewValue(constant);
    17101710                break;
    17111711            }
    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);
     1712            if (comparison.opcode != m_value->opcode()) {
     1713                replaceWithNew<Value>(comparison.opcode, m_value->origin(), comparison.operands[0], comparison.operands[1]);
     1714                break;
     1715            }
    17161716            break;
    17171717        }
     
    21672167    }
    21682168
    2169     Value* newComparisonVaueIfNecessary()
     2169    struct CanonicalizedComparison {
     2170        Opcode opcode;
     2171        Value* operands[2];
     2172    };
     2173    static CanonicalizedComparison canonicalizeComparison(Value* value)
    21702174    {
    21712175        auto flip = [] (Opcode opcode) {
     
    21912195            }
    21922196        };
    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;
     2197        if (shouldSwapBinaryOperands(value))
     2198            return { flip(value->opcode()), { value->child(1), value->child(0) } };
     2199        return { value->opcode(), { value->child(0), value->child(1) } };
    21982200    }
    21992201
Note: See TracChangeset for help on using the changeset viewer.