ConstraintAnalysis: Add OR fusing of { x == C || x > C } => x >= C#8936
Conversation
| checkOr(left7, right, right); | ||
|
|
||
| // Change 5 on the left to 99: | ||
| // { x == 99 } || { x > 5 && x <= 42 } ==> { x > 5 } |
There was a problem hiding this comment.
Can have a TODO for adding x <= 99 to the result.
| checkOr(left99, right, rightOnly5); | ||
|
|
||
| // Change 5 on the left to 4: | ||
| // { x == 4 } || { x > 5 && x <= 42 } ==> { x <= 42 } |
There was a problem hiding this comment.
Similarly, we can have a TODO for adding x >= 4.
|
|
||
| // Changes to operations: | ||
|
|
||
| // Change the Eq on the left to Ne. We fail to find anything for the OR. |
There was a problem hiding this comment.
TODO the result could be x != 5.
| checkOr(leftNe, right, empty); | ||
|
|
||
| // Change the GtS on the right to GtU: | ||
| // { x == 5 } || { x >U 5 && x <= 42 } ==> { x <= 42 } |
There was a problem hiding this comment.
I assume this will be improved in the next PR?
There was a problem hiding this comment.
Eventually, yes, though maybe not the next PR. I'm trying to prove out the path to getting some specific Kotlin code working. I'll fill out related cases later.
Co-authored-by: Thomas Lively <tlively123@gmail.com>
Co-authored-by: Thomas Lively <tlively123@gmail.com>
|
In general it seems profitable to "lift" pairs of greater-than and less-than bounds on constants as well as equality bounds with constants to intervals, do the join on the intervals, then lower them back to individual bounds. |
|
Agreed, lifting to intervals internally may make sense here. |
This is common in loops, where there is an initial value + a backedge that
has an incremented but bounded value.
To implement this, add full expansion of the OR of two AndedConstraintSets
into ANDs of the ORs of all their elements, and thorough checking there.