Stream: git-wasmtime

Topic: wasmtime / PR #8005 cranelift: Fix ireduce rules (fixes #...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 28 2024 at 01:25):

jameysharp requested cfallin for a review on PR #8005.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 28 2024 at 01:25):

jameysharp requested wasmtime-compiler-reviewers for a review on PR #8005.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 28 2024 at 01:25):

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 and y came from an instruction which not only was a binary op but also matched reducible_modular_op.

Unfortunately, both binary_op and reducible_modular_op were multi-terms.

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

view this post on Zulip Wasmtime GitHub notifications bot (Feb 28 2024 at 01:26):

jameysharp updated PR #8005.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 28 2024 at 01:27):

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 and y came from an instruction which not only was a binary op but also matched reducible_modular_op.

Unfortunately, both binary_op and reducible_modular_op were multi-terms.

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: Nov 22 2024 at 17:03 UTC