From 183d4b0385ba97cdf607743ae2b6e1a7453ef33e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 14 Sep 2023 07:30:35 -0700 Subject: 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. --- src/passes/OptimizeInstructions.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') 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()) { + 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; -- cgit v1.2.3