diff options
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 828b2fdc9..e3a5774b1 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -875,11 +875,26 @@ struct OptimizeInstructions if (matches(curr, unary(EqZInt32, unary(&inner, WrapInt64, any(&x)))) && Bits::getMaxBits(x, this) <= 32) { inner->op = EqZInt64; - inner->value = x; return replaceCurrent(inner); } } { + // i32.eqz(i32.eqz(x)) => i32(x) != 0 + // i32.eqz(i64.eqz(x)) => i64(x) != 0 + // iff shinkLevel == 0 + // (1 instruction instead of 2, but 1 more byte) + if (getPassRunner()->options.shrinkLevel == 0) { + Expression* x; + if (matches(curr, unary(EqZInt32, unary(EqZ, any(&x))))) { + Builder builder(*getModule()); + return replaceCurrent(builder.makeBinary( + getBinary(x->type, Ne), + x, + builder.makeConst(Literal::makeZero(x->type)))); + } + } + } + { // i64.extend_i32_s(i32.wrap_i64(x)) => x // where maxBits(x) <= 31 // @@ -900,12 +915,10 @@ struct OptimizeInstructions if (getModule()->features.hasSignExt()) { // i64.extend_i32_s(i32.wrap_i64(x)) => i64.extend32_s(x) Unary* inner; - Expression* x; if (matches(curr, - unary(ExtendSInt32, unary(&inner, WrapInt64, any(&x))))) { + unary(ExtendSInt32, unary(&inner, WrapInt64, any())))) { inner->op = ExtendS32Int64; inner->type = Type::i64; - inner->value = x; return replaceCurrent(inner); } } |