Fix NonNegativeResultAnalysis square rule to compare Values not defining ops#2649
Open
kimjune01 wants to merge 1 commit into
Open
Fix NonNegativeResultAnalysis square rule to compare Values not defining ops#2649kimjune01 wants to merge 1 commit into
kimjune01 wants to merge 1 commit into
Conversation
…ing ops The (mul a a) non-negativity rule compared the operands' defining ops. Two distinct block arguments both have a null defining op, so null == null wrongly proved mul(%arg0, %arg1) non-negative even when the product can be negative. Compare the operand Values directly instead, and add a regression test. Fixes EnzymeAD#2648
wsmoses
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2648.
NonNegativeResultAnalysis's "(mul a a) is always non-negative" rule compared the operands' defining ops rather than the operands themselves:Two distinct block arguments both have a
nullptrdefining op, sonull == nullwrongly provedmul(%arg0, %arg1)non-negative -- even though the product is negative whenever the args have opposite signs. Any consumer ofguaranteedNonNegativeResultcould then mis-fire (e.g.AbsPositiveSimplifydropping anabsthat is actually load-bearing).The fix compares the operand
Values directly, which is what "same value squared" actually means:This is strictly stricter -- it only removes unsound proofs, never adds new ones. The existing
mul(%arg0, %arg0)cases inabspositive.mlir(test3/4/7) still fold, since%arg0 == %arg0.Added
test9inabspositive.mlir:abs(mul(%arg0, %arg1))of two distinct block args must keep itsabs(fails on the pre-fix analysis, passes after).Found while implementing the non-negativity gate in #2576.