summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeCasts.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-08-08 16:04:25 -0700
committerGitHub <noreply@github.com>2023-08-08 16:04:25 -0700
commit0fc7b883d373924717ceccf71a6a759c97a8fb08 (patch)
tree610dc2ca3dd656f3ff5aa8cfa2ce7135099c67fa /src/passes/OptimizeCasts.cpp
parentef17febfd7106ee5330c01c66fbf8d3f6fdc0e03 (diff)
downloadbinaryen-0fc7b883d373924717ceccf71a6a759c97a8fb08.tar.gz
binaryen-0fc7b883d373924717ceccf71a6a759c97a8fb08.tar.bz2
binaryen-0fc7b883d373924717ceccf71a6a759c97a8fb08.zip
OptimizeCasts: Connect adjacent blocks in LinearExecutionWalker (#5866)
Followup to #5860, this does the same for (part of) OptimizeCasts. As there, this is valid because it's ok if we branch away. This part of the pass picks a different local to get when it knows locals have the same values but one is more refined. It is ok to add a tee earlier even if it isn't used later.
Diffstat (limited to 'src/passes/OptimizeCasts.cpp')
-rw-r--r--src/passes/OptimizeCasts.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/passes/OptimizeCasts.cpp b/src/passes/OptimizeCasts.cpp
index e4d7b1647..599e403ff 100644
--- a/src/passes/OptimizeCasts.cpp
+++ b/src/passes/OptimizeCasts.cpp
@@ -423,6 +423,16 @@ struct BestCastFinder : public LinearExecutionWalker<BestCastFinder> {
self->mostCastedGets.clear();
}
+ // It is ok to look at adjacent blocks together, as if a later part of a block
+ // is not reached that is fine - changes we make there would not be reached in
+ // that case.
+ //
+ // Note that we *cannot* do the same in EarlyCastFinder, as it modifies the
+ // earlier code in a dangerous way: it may move a trap to an earlier position.
+ // We cannot move a trap before a branch, as perhaps the branch is all that
+ // prevented us from trapping.
+ bool connectAdjacentBlocks = true;
+
void visitLocalSet(LocalSet* curr) {
// Clear any information about this local; it has a new value here.
mostCastedGets.erase(curr->index);