diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-06 17:01:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 18:42:46 -0700 |
commit | e9dfbe4de951ff6c3f3830fbcd1229d3d31a1190 (patch) | |
tree | 3cd1e66e38d2aa9542484feec436e029f4a2a477 /src/passes/OptimizeInstructions.cpp | |
parent | 96ae0dda155b47299245a89e6a68fbb97ccda33f (diff) | |
download | binaryen-e9dfbe4de951ff6c3f3830fbcd1229d3d31a1190.tar.gz binaryen-e9dfbe4de951ff6c3f3830fbcd1229d3d31a1190.tar.bz2 binaryen-e9dfbe4de951ff6c3f3830fbcd1229d3d31a1190.zip |
flip select-eqz when possible
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 2315b9e8e..cd0610634 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -173,7 +173,6 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, if (handOptimized) { curr = handOptimized; replaceCurrent(curr); - continue; } auto iter = database->patternMap.find(curr->_id); if (iter == database->patternMap.end()) return; @@ -214,10 +213,22 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions, auto* get = set->value->dynCast<GetGlobal>(); if (get && get->name == set->name) { ExpressionManipulator::nop(curr); - return curr; + } + } else if (auto* select = curr->dynCast<Select>()) { + // flip select if eqz input and flippable + auto* condition = select->condition->dynCast<Unary>(); + if (condition && condition->op == EqZInt32) { + EffectAnalyzer ifTrue(select->ifTrue); + EffectAnalyzer ifFalse(select->ifFalse); + if (!ifTrue.invalidates(ifFalse)) { + select->condition = condition->value; + std::swap(select->ifTrue, select->ifFalse); + } } } return nullptr; + // TODO: + // * eqz^2 can be removed if flowing into a boolean context (we handle if, but need also br_if and select) } }; |