summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Vacuum.cpp15
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;