summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-07-09 03:01:56 +0300
committerGitHub <noreply@github.com>2020-07-08 17:01:56 -0700
commitec5a88c12bea053200c4529758cf1f5ce916e455 (patch)
tree443c09caf8bb6e6cb025d8171c7bdc5b30c2d9bf /src/passes/OptimizeInstructions.cpp
parent18095a6c6030fb157f89889b8094eca0b3f654cb (diff)
downloadbinaryen-ec5a88c12bea053200c4529758cf1f5ce916e455.tar.gz
binaryen-ec5a88c12bea053200c4529758cf1f5ce916e455.tar.bz2
binaryen-ec5a88c12bea053200c4529758cf1f5ce916e455.zip
Optimize booleans when argument is negative integer (#2930)
bool(-x) ==> bool(x)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index cbd8c9323..2e59775c0 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -982,6 +982,14 @@ private:
}
}
} else if (auto* binary = boolean->dynCast<Binary>()) {
+ if (binary->op == SubInt32) {
+ if (auto* num = binary->left->dynCast<Const>()) {
+ if (num->value.geti32() == 0) {
+ // bool(0 - x) ==> bool(x)
+ return binary->right;
+ }
+ }
+ }
if (binary->op == OrInt32) {
// an or flowing into a boolean context can consider each input as
// boolean