summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-05-15 15:00:49 -0700
committerGitHub <noreply@github.com>2023-05-15 15:00:49 -0700
commit44cd751d9feda7c4b4b6c9d6af1e71541b90abac (patch)
treeb0a05fc26f027714ce0d45752ee44812768e0658
parent71a151240241fd50c42d88fe0ba9800c03527387 (diff)
downloadbinaryen-44cd751d9feda7c4b4b6c9d6af1e71541b90abac.tar.gz
binaryen-44cd751d9feda7c4b4b6c9d6af1e71541b90abac.tar.bz2
binaryen-44cd751d9feda7c4b4b6c9d6af1e71541b90abac.zip
[NFC] Optimize ArrayNew zero construction (#5722)
All array elements have the same type, so we can construct a single zero and just copy it. This makes ArrayNew of large arrays 2x faster. I also experimented with putting Literal::makeZero in a header, in hopes of inlining leading to licm helping here, but that did not help at all unfortunately, at least not in gcc.
-rw-r--r--src/wasm-interpreter.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 955671dcc..0e74af02a 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1642,8 +1642,9 @@ public:
}
Literals data(num);
if (curr->isWithDefault()) {
+ auto zero = Literal::makeZero(element.type);
for (Index i = 0; i < num; i++) {
- data[i] = Literal::makeZero(element.type);
+ data[i] = zero;
}
} else {
auto field = curr->type.getHeapType().getArray().element;