summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 18fbf6d83..43d0d912f 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1470,30 +1470,21 @@ private:
// First, check for side effects. If there are any, then we can't even
// assume things like local.get's of the same index being identical.
auto passOptions = getPassOptions();
- if (EffectAnalyzer(passOptions, getModule()->features, left)
- .hasSideEffects() ||
- EffectAnalyzer(passOptions, getModule()->features, right)
- .hasSideEffects()) {
+ auto features = getModule()->features;
+ if (EffectAnalyzer(passOptions, features, left).hasSideEffects() ||
+ EffectAnalyzer(passOptions, features, right).hasSideEffects()) {
return false;
}
// Ignore extraneous things and compare them structurally.
- left = Properties::getFallthrough(left, passOptions, getModule()->features);
- right =
- Properties::getFallthrough(right, passOptions, getModule()->features);
+ left = Properties::getFallthrough(left, passOptions, features);
+ right = Properties::getFallthrough(right, passOptions, features);
if (!ExpressionAnalyzer::equal(left, right)) {
return false;
}
- // Reference equality also needs to check for allocation, which is *not* a
- // side effect, but which results in different references:
- // repeatedly calling (struct.new $foo)'s output will return different
- // results (while i32.const etc. of course does not).
- // Note that allocations may have appeared in the original inputs to this
- // function, and skipped when we focused on what falls through; since there
- // are no side effects, any allocations there cannot reach the fallthrough.
- if (left->type.isRef()) {
- if (FindAll<StructNew>(left).has() || FindAll<ArrayNew>(left).has()) {
- return false;
- }
+ // To be equal, they must also be known to return the same result
+ // deterministically.
+ if (Properties::isIntrinsicallyNondeterministic(left, features)) {
+ return false;
}
return true;
}