Commit 29a925a
authored
[mlir][affine][Analysis] Add conservative bounds for semi-affine mods (llvm#93576)
This patch adds support for computing bounds for semi-affine mod
expression to FlatLinearConstraints. This is then enabled within the
ScalableValueBoundsConstraintSet to allow computing the bounds of
scalable remainder loops.
E.g. computing the bound of something like:
```
// `1000 mod s0` is a semi-affine.
#remainder_start_index = affine_map<()[s0] -> (-(1000 mod s0) + 1000)>
#remaining_iterations = affine_map<(d0) -> (-d0 + 1000)>
%0 = affine.apply #remainder_start_index()[%c8_vscale]
scf.for %i = %0 to %c1000 step %c8_vscale {
%remaining_iterations = affine.apply #remaining_iterations(%i)
// The upper bound for the remainder loop iterations should be:
// %c8_vscale - 1 (expressed as an affine map,
// affine_map<()[s0] -> (s0 * 8 - 1)>, where s0 is vscale)
%bound = "test.reify_bound"(%remaining_iterations) <{scalable, ...}>
}
```
There are caveats to this implementation. To be able to add a bound for
a `mod` we need to assume the rhs is positive (> 0). This may not be
known when adding the bounds for the `mod` expression. So to handle this
a constraint is added for `rhs > 0`, this may later be found not to hold
(in which case the constraints set becomes empty/invalid).
This is not a problem for computing scalable bounds where it's safe to
assume `s0` is vscale (or some positive multiple of it). But this may
need to be considered when enabling this feature elsewhere (to ensure
correctness).1 parent 2c31bc7 commit 29a925a
File tree
9 files changed
+275
-86
lines changed- mlir
- include/mlir
- Analysis
- Dialect/Vector/IR
- IR
- Interfaces
- lib
- Analysis
- Dialect/Vector/IR
- IR
- Interfaces
- test/Dialect/Vector
9 files changed
+275
-86
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
80 | 91 | | |
81 | 92 | | |
82 | | - | |
83 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
84 | 97 | | |
85 | 98 | | |
86 | 99 | | |
87 | 100 | | |
88 | 101 | | |
89 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
90 | 111 | | |
91 | 112 | | |
92 | 113 | | |
93 | | - | |
94 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
95 | 117 | | |
96 | 118 | | |
97 | 119 | | |
| |||
193 | 215 | | |
194 | 216 | | |
195 | 217 | | |
196 | | - | |
| 218 | + | |
| 219 | + | |
197 | 220 | | |
198 | 221 | | |
199 | 222 | | |
| |||
468 | 491 | | |
469 | 492 | | |
470 | 493 | | |
471 | | - | |
| 494 | + | |
472 | 495 | | |
473 | 496 | | |
474 | 497 | | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
479 | 503 | | |
480 | 504 | | |
481 | 505 | | |
482 | | - | |
| 506 | + | |
483 | 507 | | |
484 | 508 | | |
485 | 509 | | |
| |||
490 | 514 | | |
491 | 515 | | |
492 | 516 | | |
493 | | - | |
| 517 | + | |
| 518 | + | |
494 | 519 | | |
495 | 520 | | |
496 | 521 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
417 | 419 | | |
418 | 420 | | |
419 | | - | |
| 421 | + | |
420 | 422 | | |
421 | | - | |
| 423 | + | |
422 | 424 | | |
423 | 425 | | |
424 | 426 | | |
425 | | - | |
426 | | - | |
427 | | - | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
428 | 432 | | |
429 | 433 | | |
430 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
| 317 | + | |
317 | 318 | | |
318 | 319 | | |
319 | 320 | | |
| |||
404 | 405 | | |
405 | 406 | | |
406 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
| |||
0 commit comments