yagehu opened PR #14226 from yagehu:opt to bytecodealliance:main:
This commit adds these arithmetic mid-end optimization rules and their commutative variants. I've also added at least one filetest for each rule.
(x & y) - (x | y) --> -(x ^ y) (x ^ y) - (x | y) --> -(x & y) (x ^ y) + 2 * (x & y) --> x + y (x - y) + (y - x) --> 0
yagehu requested wasmtime-compiler-reviewers for a review on PR #14226.
yagehu requested cfallin for a review on PR #14226.
yagehu edited PR #14226:
This commit adds these arithmetic mid-end optimization rules and their commutative variants. I've also added at least one filetest for each rule that failed to optimize in main.
(x & y) - (x | y) --> -(x ^ y) (x ^ y) - (x | y) --> -(x & y) (x ^ y) + 2 * (x & y) --> x + y (x - y) + (y - x) --> 0
:thumbs_up: cfallin submitted PR review:
LGTM, thanks!
As an aside: rules like
(x ^ y) + 2 * (x & y) --> x + ymake my head hurt to think about (that's a full adder, I guess?? XOR for the sum and AND for the carry, shifted up one bit?) but now that we have formal verification in CI, we get to see this Just Work(tm) (logs:============================= Verification summary ============================ Total expansions: 1377 In scope expansions: 1096 Type instantiations: 5370 Applicable: 5356 Verification passed: 5356 Verification failed: 0 Verification unknown: 0 =============================================================================== ========================== Cache statistics =========================== Mode: read-write Source: cranelift/isle/veri/cache Destination: cranelift/isle/veri/cache.rebuild Hits: 10626 (99.1%) Misses: 100 (0.9%) New entries: 100 Retained: 10562 Source entries: 12128 Dropped (unused):1566or in other words, everything here verifies, and we have some new entries in the cache ("New entries: 100") meaning something new did actually get processed. Very cool! (cc @avanhatt @mmcloughlin)
:thumbs_up: cfallin submitted PR review:
LGTM, thanks!
As an aside: rules like
(x ^ y) + 2 * (x & y) --> x + ymake my head hurt to think about (that's a full adder, I guess?? XOR for the sum and AND for the carry, shifted up one bit?) but now that we have formal verification in CI, we get to see this Just Work(tm) (logs):============================= Verification summary ============================ Total expansions: 1377 In scope expansions: 1096 Type instantiations: 5370 Applicable: 5356 Verification passed: 5356 Verification failed: 0 Verification unknown: 0 =============================================================================== ========================== Cache statistics =========================== Mode: read-write Source: cranelift/isle/veri/cache Destination: cranelift/isle/veri/cache.rebuild Hits: 10626 (99.1%) Misses: 100 (0.9%) New entries: 100 Retained: 10562 Source entries: 12128 Dropped (unused):1566or in other words, everything here verifies, and we have some new entries in the cache ("New entries: 100") meaning something new did actually get processed. Very cool! (cc @avanhatt @mmcloughlin)
cfallin added PR #14226 Cranelift arithmetic mid-end optimization rules to the merge queue.
:check: cfallin merged PR #14226.
cfallin removed PR #14226 Cranelift arithmetic mid-end optimization rules from the merge queue.
Last updated: Aug 30 2026 at 09:07 UTC