diff options
author | Alon Zakai <azakai@google.com> | 2023-09-14 07:30:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 07:30:35 -0700 |
commit | 183d4b0385ba97cdf607743ae2b6e1a7453ef33e (patch) | |
tree | e9795b71c8b1b15cf4a8592aaab08618b548d637 /src | |
parent | 2cbe448eb4df17010f0e5f360a8e705da710f3e0 (diff) | |
download | binaryen-183d4b0385ba97cdf607743ae2b6e1a7453ef33e.tar.gz binaryen-183d4b0385ba97cdf607743ae2b6e1a7453ef33e.tar.bz2 binaryen-183d4b0385ba97cdf607743ae2b6e1a7453ef33e.zip |
OptimizeInstructions: Simplify tuple.extract of tuple.make (#5938)
E.g.
(tuple.extract 1
(tuple.make (A) (B) (C))
=>
(B)
Modify some existing tests to not be in this trivial form, so that they do not
stop testing what they should.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 0b787105e..feaee4d44 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -2266,6 +2266,25 @@ struct OptimizeInstructions } } + void visitTupleExtract(TupleExtract* curr) { + if (curr->type == Type::unreachable) { + return; + } + + if (auto* make = curr->tuple->dynCast<TupleMake>()) { + Builder builder(*getModule()); + + // Store the value of the lane we want in a tee, and return that after a + // drop of the tuple (which might have side effects). + auto valueType = make->type[curr->index]; + Index tempLocal = builder.addVar(getFunction(), valueType); + make->operands[curr->index] = + builder.makeLocalTee(tempLocal, make->operands[curr->index], valueType); + auto* get = builder.makeLocalGet(tempLocal, valueType); + replaceCurrent(getDroppedChildrenAndAppend(make, get)); + } + } + Index getMaxBitsForLocal(LocalGet* get) { // check what we know about the local return localInfo[get->index].maxBits; |