From 82d82f1a4e9aa1ce1b80acbab4a95262ec7782ae Mon Sep 17 00:00:00 2001 From: Max Graey Date: Tue, 7 Jun 2022 21:34:23 +0300 Subject: [Optimize Instructions] Simplify sign extentions (Part 2) (#4382) Similar to #4004 but for 32-bit integers i32(x) << 24 >> 24 ==> i32.extend8_s(x) i32(x) << 16 >> 16 ==> i32.extend16_s(x) --- src/passes/OptimizeInstructions.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/passes/OptimizeInstructions.cpp') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index c4a5b2ed4..c4ce8c239 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -476,6 +476,22 @@ struct OptimizeInstructions break; } } + // i32(x) << 24 >> 24 ==> i32.extend8_s(x) + // i32(x) << 16 >> 16 ==> i32.extend16_s(x) + if (matches(curr, + binary(ShrSInt32, + binary(ShlInt32, any(&x), i32(&c1)), + i32(&c2))) && + Bits::getEffectiveShifts(c1) == Bits::getEffectiveShifts(c2)) { + switch (32 - Bits::getEffectiveShifts(c1)) { + case 8: + return replaceCurrent(builder.makeUnary(ExtendS8Int32, x)); + case 16: + return replaceCurrent(builder.makeUnary(ExtendS16Int32, x)); + default: + break; + } + } } } { -- cgit v1.2.3