summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-10-02 03:12:44 +0300
committerGitHub <noreply@github.com>2020-10-01 17:12:44 -0700
commit2959218552a202b2b1d983ffcff68b015b9a94bd (patch)
tree3b8a56ca2f0cfc197e90fc26643d99c87d9bf617 /src/passes/OptimizeInstructions.cpp
parentf703a3a3c9021e1ae2cb009a37786210d3fcf870 (diff)
downloadbinaryen-2959218552a202b2b1d983ffcff68b015b9a94bd.tar.gz
binaryen-2959218552a202b2b1d983ffcff68b015b9a94bd.tar.bz2
binaryen-2959218552a202b2b1d983ffcff68b015b9a94bd.zip
Optimize "clear bit mask" combination to cyclic rotation over preinverted mask (#3184)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 3b7a9dc6d..869512774 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1397,6 +1397,20 @@ private:
return right;
}
{
+ // ~(1 << x) aka (1 << x) ^ -1 ==> rotl(-2, x)
+ Expression* x;
+ if (matches(curr,
+ binary(Abstract::Xor,
+ binary(Abstract::Shl, ival(1), any(&x)),
+ ival(-1)))) {
+ curr->op = Abstract::getBinary(type, Abstract::RotL);
+ right->value = Literal::makeFromInt32(-2, type);
+ curr->left = right;
+ curr->right = x;
+ return curr;
+ }
+ }
+ {
// Wasm binary encoding uses signed LEBs, which slightly favor negative
// numbers: -64 is more efficient than +64 etc., as well as other powers
// of two 7 bits etc. higher. we therefore prefer x - -64 over x + 64. in