[TIR] Canonical simplify the intset before region cover proof#9941
Conversation
|
I will leave @Hzfengsy to coordinate the change |
a79ee11 to
f0c0478
Compare
|
ping @spectrometerHBH |
f0c0478 to
f076822
Compare
| TVM_TRY_REWRITE(max(x, y - z) + z, max(x + z, y)); | ||
| TVM_TRY_REWRITE(max(x - z, y) + z, max(x, y + z)); | ||
|
|
||
| TVM_TRY_REWRITE(min(c1, x - c2) + c3, min(c1 + c3, x + (c3 - c2))); |
There was a problem hiding this comment.
These rules look quite ad-hoc to me since in general, I think it would be more simplified to keep common sub expressions out of min/max to avoid duplicate calculation unless it can cancel some items like the rules above max(x-z, y) + z, max(x, y+z).
There was a problem hiding this comment.
Background: after process region only use canonical_simplify and intersect with buffer shape bound, the region max to compare now are (after #9880). The issue is to cancel hh_0*8 in min.
min(0, ((hh_0*8) - 215)) + 223)min(((hh_0*8) + 9), 224) - 1)
My thought for the rule is it would do reduce the expression depth, because c1, c2, c3 are PVar<IntImm> and get immediately folded. Other possible rule replacements I can imagine could be:
-
(make min to a "canonical" form)
min(c1, x-c2)=>min(0, x-(c1+c2)) + c1 -
(specifically match things to cancel)
min(c1, x-c2) - min(c3, x-c4)=> c4-c2 if c1+c2=c3+c4
|
Also I have question on whether there are solid ways to avoid patch codes at all. For example, can we prefer to cancel all common terms in summation before any other rewrites? |
|
Great discussions. The min/max cancelation was not a topic that come up before but indeed worth thinking a bit more.
|
d62ff36 to
07d5c6a
Compare
|
Finally I found there are existing rules can cover pattern like
However, to make these rules work, I have to call |
07d5c6a to
2fca571
Compare
…#9941) * canonical simplify the intset before region cover proof * add more rewrite rule for intimms to fix the issue after rebase * remove rewrite rules, there are existing rule can work after canonical simplify
Hi, this is a simple modification for region cover check, which I believe can fix the region cover failure of #9527.
However, I believe it could not eliminate all possible failures to prove the region cover property. Why the case of #9527 can be fixed is described below:
(((1 + ((min((225 - (hh_0*8)), 10) - max((1 - (hh_0*8)), 0)) - 1)) + (((hh_0*8) - 1) + max((1 - (hh_0*8)), 0))) - 1)a + b - b => apattern to simplify, and so withcanonical_simplify:(((hh_0*8) + (225 - max((hh_0*8), 215))) - 2)analyzer.Simplify(), specially, in it's invocation torewrite_simplify, the original expr is transform to((((225 - max((hh_0*8), 215)) + max((hh_0*8), 1)) - max((1 - (hh_0*8)), 0)) - 2)canonical_simplifybefore any general simplification (analyzer.Simplifyis invoked in many places, for example, in a intset intersection call) works for this particular problem.CanProveinterface also invoke simplifications, actually we do not need to manually callanalyzer.Simplifytwice.So the root cause should be rule conflictions in
canonical_simplifyandrewrite_simplify, andanalyzer.Simplifywill always userewrite_simplifyfirst. The pr is not aimed to resolve this general issue.