summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-09-10 09:29:41 -0700
committerGitHub <noreply@github.com>2017-09-10 09:29:41 -0700
commit9fafcef2c3dfe18b119b11fa527514835a4371ce (patch)
tree33fedffc002bdb1ac0ad057d3e0e7134971f3404 /src/passes/OptimizeInstructions.cpp
parenta9bf3a323837c366b7d467b720495d08e46d2e32 (diff)
parent67133b57486339249f65872b5959873fef390455 (diff)
downloadbinaryen-9fafcef2c3dfe18b119b11fa527514835a4371ce.tar.gz
binaryen-9fafcef2c3dfe18b119b11fa527514835a4371ce.tar.bz2
binaryen-9fafcef2c3dfe18b119b11fa527514835a4371ce.zip
Merge pull request #1175 from WebAssembly/fuzz
Fuzzer improvements + fixes
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 1f2f07110..ad667f888 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -622,16 +622,33 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
std::swap(iff->ifTrue, iff->ifFalse);
}
}
- if (ExpressionAnalyzer::equal(iff->ifTrue, iff->ifFalse)) {
+ if (iff->condition->type != unreachable && ExpressionAnalyzer::equal(iff->ifTrue, iff->ifFalse)) {
// sides are identical, fold
- if (!EffectAnalyzer(getPassOptions(), iff->condition).hasSideEffects()) {
+ // if we can replace the if with one arm, and no side effects in the condition, do that
+ auto needCondition = EffectAnalyzer(getPassOptions(), iff->condition).hasSideEffects();
+ auto typeIsIdentical = iff->ifTrue->type == iff->type;
+ if (typeIsIdentical && !needCondition) {
return iff->ifTrue;
} else {
Builder builder(*getModule());
- return builder.makeSequence(
- builder.makeDrop(iff->condition),
- iff->ifTrue
- );
+ if (typeIsIdentical) {
+ return builder.makeSequence(
+ builder.makeDrop(iff->condition),
+ iff->ifTrue
+ );
+ } else {
+ // the types diff. as the condition is reachable, that means the if must be
+ // concrete while the arm is not
+ assert(isConcreteWasmType(iff->type) && iff->ifTrue->type == unreachable);
+ // emit a block with a forced type
+ auto* ret = builder.makeBlock();
+ if (needCondition) {
+ ret->list.push_back(builder.makeDrop(iff->condition));
+ }
+ ret->list.push_back(iff->ifTrue);
+ ret->finalize(iff->type);
+ return ret;
+ }
}
}
}