diff options
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index b50f99fbc..9379d8588 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -2370,21 +2370,6 @@ private: // order using a temp local, which would be bad } { - // Flip select to remove eqz if we can reorder - Select* s; - Expression *ifTrue, *ifFalse, *c; - if (matches( - curr, - select( - &s, any(&ifTrue), any(&ifFalse), unary(EqZInt32, any(&c)))) && - canReorder(ifTrue, ifFalse)) { - s->ifTrue = ifFalse; - s->ifFalse = ifTrue; - s->condition = c; - return s; - } - } - { // TODO: Remove this after landing SCCP pass. See: #4161 // i32(x) ? i32(x) : 0 ==> x @@ -2436,6 +2421,25 @@ private: return curr->type == Type::i64 ? builder.makeUnary(ExtendUInt32, c) : c; } } + if (curr->type == Type::i32 && + Bits::getMaxBits(curr->condition, this) <= 1 && + Bits::getMaxBits(curr->ifTrue, this) <= 1 && + Bits::getMaxBits(curr->ifFalse, this) <= 1) { + // The condition and both arms are i32 booleans, which allows us to do + // boolean optimizations. + Expression* x; + Expression* y; + + // x ? y : 0 ==> x & y + if (matches(curr, select(any(&y), ival(0), any(&x)))) { + return builder.makeBinary(AndInt32, y, x); + } + + // x ? 1 : y ==> x | y + if (matches(curr, select(ival(1), any(&y), any(&x)))) { + return builder.makeBinary(OrInt32, y, x); + } + } { // Simplify x < 0 ? -1 : 1 or x >= 0 ? 1 : -1 to // i32(x) >> 31 | 1 @@ -2459,23 +2463,19 @@ private: } } } - if (curr->type == Type::i32 && - Bits::getMaxBits(curr->condition, this) <= 1 && - Bits::getMaxBits(curr->ifTrue, this) <= 1 && - Bits::getMaxBits(curr->ifFalse, this) <= 1) { - // The condition and both arms are i32 booleans, which allows us to do - // boolean optimizations. - Expression* x; - Expression* y; - - // x ? y : 0 ==> x & y - if (matches(curr, select(any(&y), ival(0), any(&x)))) { - return builder.makeBinary(AndInt32, y, x); - } - - // x ? 1 : y ==> x | y - if (matches(curr, select(ival(1), any(&y), any(&x)))) { - return builder.makeBinary(OrInt32, y, x); + { + // Flip select to remove eqz if we can reorder + Select* s; + Expression *ifTrue, *ifFalse, *c; + if (matches( + curr, + select( + &s, any(&ifTrue), any(&ifFalse), unary(EqZInt32, any(&c)))) && + canReorder(ifTrue, ifFalse)) { + s->ifTrue = ifFalse; + s->ifFalse = ifTrue; + s->condition = c; + return s; } } { |