diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-09 10:55:04 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-09 10:55:04 -0700 |
commit | f03404e14317b79e47d11300ab21f8e92036fa85 (patch) | |
tree | 03ad5fb4972551ef7efa6632314d3b9743cb66f2 /src | |
parent | 98a76440fa47c784b3e425aa3ae4d3a3bad05f25 (diff) | |
download | binaryen-f03404e14317b79e47d11300ab21f8e92036fa85.tar.gz binaryen-f03404e14317b79e47d11300ab21f8e92036fa85.tar.bz2 binaryen-f03404e14317b79e47d11300ab21f8e92036fa85.zip |
fold eqz+comparisons
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 638977353..de342b43f 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -36,6 +36,28 @@ struct OptimizeInstructions : public WalkerPass<WasmWalker<OptimizeInstructions> } } } + void visitUnary(Unary* curr) { + if (curr->op == EqZ) { + // fold comparisons that flow into an EqZ + auto* child = curr->value->dyn_cast<Binary>(); + if (child && (child->type == i32 || child->type == i64)) { + switch (child->op) { + case Eq: child->op = Ne; break; + case Ne: child->op = Eq; break; + case LtS: child->op = GeS; break; + case LtU: child->op = GeU; break; + case LeS: child->op = GtS; break; + case LeU: child->op = GtU; break; + case GtS: child->op = LeS; break; + case GtU: child->op = LeU; break; + case GeS: child->op = LtS; break; + case GeU: child->op = LtU; break; + default: return; + } + replaceCurrent(child); + } + } + } }; static RegisterPass<OptimizeInstructions> registerPass("optimize-instructions", "optimizes instruction combinations"); |