diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-24 16:39:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-24 16:47:52 -0700 |
commit | 97cf0d7bf6f115d44636dd52dc7c0036567ca798 (patch) | |
tree | c6862019f90650140f86c2c5c02377ba2b6ad3ce /src | |
parent | f28bba29833bad06a76c7aabf31cf0257e12f5ba (diff) | |
download | binaryen-97cf0d7bf6f115d44636dd52dc7c0036567ca798.tar.gz binaryen-97cf0d7bf6f115d44636dd52dc7c0036567ca798.tar.bz2 binaryen-97cf0d7bf6f115d44636dd52dc7c0036567ca798.zip |
optimize if(const)
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Vacuum.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 03becb04c..c3fed2328 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -186,6 +186,21 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum, Visitor<Vacuum>> } void visitIf(If* curr) { + // if the condition is a constant, just apply it + // we can just return the ifTrue or ifFalse. + if (auto* value = curr->condition->dynCast<Const>()) { + if (value->value.getInteger()) { + replaceCurrent(curr->ifTrue); + return; + } else { + if (curr->ifFalse) { + replaceCurrent(curr->ifFalse); + } else { + ExpressionManipulator::nop(curr); + } + return; + } + } if (curr->ifFalse) { if (curr->ifFalse->is<Nop>()) { curr->ifFalse = nullptr; |