cfallin requested alexcrichton for a review on PR #13081.
cfallin opened PR #13081 from cfallin:revert-12926 to bytecodealliance:main:
These rules appear to be correct, but for an as-yet-undiagnosed reason, cause rewrite blowups. The proper fix is probably to use
subsumebut I'd like for us to bottom out why the blowup is happening first (cc @myunbin).In the meantime, this removes the rules so we get back to a workable state on
main. Tests are retained and re-blessed with the now-less-optimized output.Fixes #13068.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin requested wasmtime-compiler-reviewers for a review on PR #13081.
cfallin updated PR #13081.
alexcrichton submitted PR review.
alexcrichton has enabled auto merge for PR #13081.
github-actions[bot] added the label isle on PR #13081.
github-actions[bot] added the label cranelift on PR #13081.
github-actions[bot] commented on PR #13081:
Subscribe to Label Action
cc @cfallin, @fitzgen
<details>
This issue or pull request has been labeled: "cranelift", "isle"Thus the following users have been cc'd because of the following labels:
- cfallin: isle
- fitzgen: isle
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
cfallin requested pchickey for a review on PR #13081.
cfallin requested wasmtime-core-reviewers for a review on PR #13081.
cfallin updated PR #13081.
cfallin unassigned pchickey from PR #13081 Cranelift: revert rules added in #12926..
alexcrichton added PR #13081 Cranelift: revert rules added in #12926. to the merge queue
alexcrichton merged PR #13081.
alexcrichton removed PR #13081 Cranelift: revert rules added in #12926. from the merge queue
MaxGraey submitted PR review.
MaxGraey created PR review comment:
My two cents. Can’t you just decompose this into two simple rules, which I’m sure already exist:
x + y-->y + x
x==x-->true
cfallin submitted PR review.
cfallin created PR review comment:
@MaxGraey
x + y -> y + xis commutativity, which is a valid rewrite but is known to cause huge blowup in rewrite systems in general (at least 2x blowup for all commutative binary operators, combinatorially more when nested).In general we have a philosophy in Cranelift not to have commutativity as a rule, but to explicitly unfold left-hand sides in commutative combinations, because writing more rules is more efficient than doing the commutative rewrites always (just in case something would match) at runtime.
MaxGraey submitted PR review.
MaxGraey created PR review comment:
Yeah, commutative rewrites like
x + y -> y + xcause blow-up in e-graphs because they explicitly generate equivalent forms. Fora1 + a2 + ... + an, commutativity alone gives up ton!permutations, and associativity adds even more shapes like(a + b) + c <-> a + (b + c). This inflates e-nodes and match counts even though the semantics are unchanged.The usual fix is to not encode
a+b <-> b+aas a rewrite at all, but to canonicalize, e.g.add_CT[b, a, ...] -> add_CT[a, b, ...], and for AC ops use flatten+sort:(((c + a) + b) + ...) -> add_AC[a,b,c,..]. add_CT & add_AC are special canonized constructors of e-graph's defs. And during matching, they must already have some canonical form (sorted for instance), or be rearranged very carefully, for example, by grouping constants and rearranging them as a group within an associative expression, limiting the number of rearrangements, and conservatively stopping them if this does not reduce the cost in terms of the new subgraph (e-class), and so on.What’s more, in my view, this will reduce the amount of boilerplate code in your ISLE and the number of isoforms for the same rule and now there’ll be no need to wonder whether it will explode or not.
WDYT?
````
MaxGraey edited PR review comment.
MaxGraey edited PR review comment.
MaxGraey edited PR review comment.
MaxGraey edited PR review comment.
MaxGraey edited PR review comment.
MaxGraey edited PR review comment.
MaxGraey edited PR review comment.
cfallin submitted PR review.
MaxGraey edited PR review comment.
cfallin created PR review comment:
@MaxGraey canonicalization is something we've talked about in the past, but does add a good amount of complexity of course. In the commutativity-of-binary-operator case it's "just" custom hash+eq but for associativity this implies an N-input operator form which is a much much bigger change to the whole Cranelift backend (we could rewrite into this form and then out of it, but (i) that's out-of-line storage for args, (ii) that's a lot of memory traffic churn when the common case doesn't need this). We also have sort of competing notions of canonicity: e.g. the const-folding rules put constants to the right but that conflicts with SSA ordering, so we'd have to get a bit finicky with heuristic engineering here in a way that feels a little brittle.
So: nice in theory and we've thought about it but the details are tricky. If you actually want to play with this in a branch (it's likely none of us have time), measure results, and report back, that'd be very interesting of course!
MaxGraey submitted PR review.
MaxGraey created PR review comment:
If I were a student, I might sign up for such an adventure. Unfortunately, I’m not a student, and my budget constraints doesn’t allow me to spend much free time on anything beyond a few ideas and pull requests to LLVM, mostly focused on improving analysis and optimization in the floating-point domain, which I consider one of the most under-optimized areas in modern compilers, as well as trying to find remote job, which takes a significant amount of time and effort these days.
Last updated: May 03 2026 at 22:13 UTC