diff options
author | Max Graey <maxgraey@gmail.com> | 2020-10-26 22:52:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 13:52:32 -0700 |
commit | 514a6c5eb339b67db852643405428f3add7d0e39 (patch) | |
tree | 128f0ece583b4397f5a23a751b210ac49a31ddaf /src/passes/OptimizeInstructions.cpp | |
parent | c8eeeeaed96d7753efe1b597c1b6b68098d82c79 (diff) | |
download | binaryen-514a6c5eb339b67db852643405428f3add7d0e39.tar.gz binaryen-514a6c5eb339b67db852643405428f3add7d0e39.tar.bz2 binaryen-514a6c5eb339b67db852643405428f3add7d0e39.zip |
Drop RHS of shift if effective shift is zero (#3209)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 0ce1f5f95..b11df3276 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -346,6 +346,7 @@ struct OptimizeInstructions { // x <<>> (C & (31 | 63)) ==> x <<>> C' // x <<>> (y & (31 | 63)) ==> x <<>> y + // x <<>> (y & (32 | 64)) ==> x // where '<<>>': // '<<', '>>', '>>>'. 'rotl' or 'rotr' BinaryOp op; @@ -375,6 +376,13 @@ struct OptimizeInstructions curr->cast<Binary>()->right = y; return curr; } + // i32(x) <<>> (y & 32) ==> x + // i64(x) <<>> (y & 64) ==> x + if (((c->type == Type::i32 && (c->value.geti32() & 31) == 0) || + (c->type == Type::i64 && (c->value.geti64() & 63LL) == 0LL)) && + !effects(y).hasSideEffects()) { + return x; + } } } { |