jameysharp added the bug label to Issue #8004.
jameysharp added the cranelift label to Issue #8004.
jameysharp opened issue #8004:
In
cranelift/codegen/src/egraph.rs,OptimizeCtx::subsume_valuesis shared among all the recursive invocations ofoptimize_pure_enodeand thesimplifyconstructor. That means usingsubsumein one rule can cause a rule applied to a different instruction to behave as if it usedsubsumeas well, if the latter happens to return the same value as the former.This is not a correctness bug: it does not cause rules to apply when they shouldn't. It just means we're pruning the e-graph more aggressively than I think we intended to, which means we may be missing optimizations.
I noticed this while investigating #7999 but that is an overly complicated reproducer for this issue.
A too-simple test case is
imul v0, (iconst 1).
- This should get rewritten to
ishl v0, (iconst 0)because 1 is a power of two (though that's another thing we might want to change).- When that new
ishlis recursively optimized, it should be subsumed tov0because a shift by 0 is a no-op.- Then we return to optimizing the
imuland see that the result of theishlrule has been returned asv0, which is already subsumed because of this bug, and we ignore any otherimuloptimization rules as a result.That isn't a great test case because frankly that's a desirable outcome in that case. But I think we should discuss this more generally because I don't think this is how
subsumewas intended to work.cc: @elliottt @cfallin @lpereira
Last updated: Dec 13 2025 at 19:03 UTC