summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2022-06-07 21:34:23 +0300
committerGitHub <noreply@github.com>2022-06-07 11:34:23 -0700
commit82d82f1a4e9aa1ce1b80acbab4a95262ec7782ae (patch)
treecb552d37428b75738681030291cf65d11e195c97 /src/passes/OptimizeInstructions.cpp
parentec88ea6df0925ae0e648b26d327239e946de48a6 (diff)
downloadbinaryen-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.cpp16
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;
+ }
+ }
}
}
{