From 111902d98ac2eb1e903af8ec2f2eab8e9bc66cdf Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 11 Apr 2024 16:41:22 -0700 Subject: Fix isGenerative on calls and test via improving OptimizeInstructions::areConsecutiveInputsEqual() (#6481) "Generative" is what we call something like a struct.new that may be syntactically identical to another struct.new, but each time a new value is generated. The same is true for calls, which can do anything, including return a different value for syntactically identical calls. This was not a bug because the main user of isGenerative, areConsecutiveInputsEqual(), was too weak to notice, that is, it gave up sooner, for other reasons. This PR improves that function to do a much better check, which makes the fix necessary to prevent regressions. This is not terribly important for itself, but will help a later PR that will add code that depends more heavily on areConsecutiveInputsEqual(). --- src/ir/properties.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/ir/properties.cpp') diff --git a/src/ir/properties.cpp b/src/ir/properties.cpp index 63b7cedd1..05dae897e 100644 --- a/src/ir/properties.cpp +++ b/src/ir/properties.cpp @@ -20,14 +20,18 @@ namespace wasm::Properties { bool isGenerative(Expression* curr, FeatureSet features) { - // Practically no wasm instructions are generative. Exceptions occur only in - // GC atm. - if (!features.hasGC()) { - return false; - } - struct Scanner : public PostWalker { bool generative = false; + + void visitCall(Call* curr) { + // TODO: We could in principle look at the called function to see if it is + // generative. To do that we'd need to compute generativity like we + // compute global effects (we can't just peek from here, as the + // other function might be modified in parallel). + generative = true; + } + void visitCallIndirect(CallIndirect* curr) { generative = true; } + void visitCallRef(CallRef* curr) { generative = true; } void visitStructNew(StructNew* curr) { generative = true; } void visitArrayNew(ArrayNew* curr) { generative = true; } void visitArrayNewFixed(ArrayNewFixed* curr) { generative = true; } -- cgit v1.2.3