summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-10-04 12:46:03 -0700
committerGitHub <noreply@github.com>2021-10-04 12:46:03 -0700
commitdebc9ef887869406ed9fcaf53d758ca7529c53bc (patch)
tree50791fb0ee58e1cb93821e7415396f5fc54d43ab /src
parent1183a7ddef3f0597b4547da0af6b6d1a8393f290 (diff)
downloadbinaryen-debc9ef887869406ed9fcaf53d758ca7529c53bc.tar.gz
binaryen-debc9ef887869406ed9fcaf53d758ca7529c53bc.tar.bz2
binaryen-debc9ef887869406ed9fcaf53d758ca7529c53bc.zip
Optimize call_ref+table.get => call_indirect (#4207)
Rather than load from the table and call that reference, call using the table.
Diffstat (limited to 'src')
-rw-r--r--src/passes/OptimizeInstructions.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index cb656ceaf..3153af200 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1190,6 +1190,19 @@ struct OptimizeInstructions
return;
}
+ if (auto* get = curr->target->dynCast<TableGet>()) {
+ // (call_ref ..args.. (table.get $table (index))
+ // =>
+ // (call_indirect $table ..args.. (index))
+ replaceCurrent(Builder(*getModule())
+ .makeCallIndirect(get->table,
+ get->index,
+ curr->operands,
+ get->type.getHeapType().getSignature(),
+ curr->isReturn));
+ return;
+ }
+
auto features = getModule()->features;
// It is possible the target is not a function reference, but we can infer