diff options
author | Max Graey <maxgraey@gmail.com> | 2022-06-07 21:34:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-07 11:34:23 -0700 |
commit | 82d82f1a4e9aa1ce1b80acbab4a95262ec7782ae (patch) | |
tree | cb552d37428b75738681030291cf65d11e195c97 /src/passes/OptimizeInstructions.cpp | |
parent | ec88ea6df0925ae0e648b26d327239e946de48a6 (diff) | |
download | binaryen-82d82f1a4e9aa1ce1b80acbab4a95262ec7782ae.tar.gz binaryen-82d82f1a4e9aa1ce1b80acbab4a95262ec7782ae.tar.bz2 binaryen-82d82f1a4e9aa1ce1b80acbab4a95262ec7782ae.zip |
[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)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
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; + } + } } } { |