diff options
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 9b47f6a0f..ecd30d711 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -170,16 +170,19 @@ struct OptimizeInstructions } void visitExpression(Expression* curr) { + // if this contains dead code, don't bother trying to optimize it, the type + // might change (if might not be unreachable if just one arm is, for + // example). this optimization pass focuses on actually executing code. the + // only exceptions are control flow changes + if (curr->is<Const>() || curr->is<Call>() || curr->is<Nop>() || + (curr->type == Type::unreachable && !curr->is<Break>() && + !curr->is<Switch>() && !curr->is<If>())) { + return; + } // we may be able to apply multiple patterns, one may open opportunities // that look deeper NB: patterns must not have cycles - while (1) { - auto* handOptimized = handOptimize(curr); - if (handOptimized) { - curr = handOptimized; - replaceCurrent(curr); - continue; - } - break; + while ((curr = handOptimize(curr))) { + replaceCurrent(curr); } } @@ -200,15 +203,12 @@ struct OptimizeInstructions // Optimizations that don't yet fit in the pattern DSL, but could be // eventually maybe Expression* handOptimize(Expression* curr) { - FeatureSet features = getModule()->features; - // if this contains dead code, don't bother trying to optimize it, the type - // might change (if might not be unreachable if just one arm is, for - // example). this optimization pass focuses on actually executing code. the - // only exceptions are control flow changes - if (curr->type == Type::unreachable && !curr->is<Break>() && - !curr->is<Switch>() && !curr->is<If>()) { + if (curr->is<Const>()) { return nullptr; } + + FeatureSet features = getModule()->features; + if (auto* binary = curr->dynCast<Binary>()) { if (isSymmetricOrRelational(binary)) { canonicalize(binary); |