jameysharp requested cfallin for a review on PR #8005.
jameysharp requested wasmtime-compiler-reviewers for a review on PR #8005.
jameysharp opened PR #8005 from jameysharp:fix-ireduce-opts
to bytecodealliance:main
:
We had two optimization rules which started off like this:
(rule (simplify (ireduce smallty val@(binary_op _ op x y)))
(if-let _ (reducible_modular_op val))
...)This was intended to check that
x
andy
came from an instruction which not only was a binary op but also matchedreducible_modular_op
.Unfortunately, both
binary_op
andreducible_modular_op
were multi-terms.
- So
binary_op
would search the eclass rooted atval
to find each instruction that uses a binary operator.- Then
reducible_modular_op
would search the entire eclass again to find an instruction which matched its criteria.Nothing ensured that both searches would find the same instruction.
The reason these rules were written this way was because they had additional guards (
will_simplify_with_ireduce
) which made them fairly complex, and it seemed desirable to not have to copy those guards for every operator where we wanted to apply this optimization.However, we've decided that checking whether the rule is actually an improvement is not desirable. In general, that should be the job of the cost function. Blindly adding equivalent expressions gives us more opportunities for other rules to fire, and we have global recursion and growth limits to keep the process from going too wild.
As a result, we can just delete those guards. That allows us to write the rules in a more straightforward way.
cc: @elliottt @cfallin @lpereira
jameysharp updated PR #8005.
jameysharp edited PR #8005:
We had two optimization rules which started off like this:
(rule (simplify (ireduce smallty val@(binary_op _ op x y)))
(if-let _ (reducible_modular_op val))
...)This was intended to check that
x
andy
came from an instruction which not only was a binary op but also matchedreducible_modular_op
.Unfortunately, both
binary_op
andreducible_modular_op
were multi-terms.
- So
binary_op
would search the eclass rooted atval
to find each instruction that uses a binary operator.- Then
reducible_modular_op
would search the entire eclass again to find an instruction which matched its criteria.Nothing ensured that both searches would find the same instruction.
The reason these rules were written this way was because they had additional guards (
will_simplify_with_ireduce
) which made them fairly complex, and it seemed desirable to not have to copy those guards for every operator where we wanted to apply this optimization.However, we've decided that checking whether the rule is actually an improvement is not desirable. In general, that should be the job of the cost function. Blindly adding equivalent expressions gives us more opportunities for other rules to fire, and we have global recursion and growth limits to keep the process from going too wild.
As a result, we can just delete those guards. That allows us to write the rules in a more straightforward way.
Fixes #7999.
cc: @elliottt @cfallin @lpereira
Last updated: Dec 23 2024 at 13:07 UTC