Commit 59efcb5
[IRCE] Check loop clone legality before attempting to do so
Not all loop bodies are safe to clone. For example, they may have
`noduplicate` call in them. Additionally, if the transformation may
cause any of the cloned loop bodies to execute conditionally, we
must also disallow `convergent` calls, as well as any call that
returns a token that is used outside of the loop. The loop unswitching
pass had an appropriate legality check for this, but IRCE did not,
causing issues downstream (JuliaLang/julia#48918).
As a particular example, consider the test case in this commit, where
`opt -passes=irce`, creates invalid IR:
```
opt --passes=irce llvm/test/Transforms/IRCE/pre_post_loops_clone.ll
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.
Instruction does not dominate all uses!
%token = call token @llvm.source_token()
call void @llvm.sink_token(token %token)
Instruction does not dominate all uses!
%token = call token @llvm.source_token()
call void @llvm.sink_token(token %token)
LLVM ERROR: Broken module found, compilation aborted!
```
Fix this by factoring out the legality check from the loop unswitch
pass and using it in IRCE as well. I personally don't have any code
that is `noduplicate` or `convergent`, but I don't see any reason
why IRCE would be different here.
I will also mention llvm#56243 as related, which contains some related
discussion of LCSSA in the presence of tokens.
Fixes llvm#63984
(cherry picked from commit 5b9f963)1 parent 0ac5fe1 commit 59efcb5
File tree
5 files changed
+123
-28
lines changed- llvm
- include/llvm/Analysis
- lib
- Analysis
- Transforms
- Scalar
- Utils
- test/Transforms/IRCE
5 files changed
+123
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
330 | 336 | | |
331 | 337 | | |
332 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
431 | 452 | | |
432 | 453 | | |
433 | 454 | | |
| |||
439 | 460 | | |
440 | 461 | | |
441 | 462 | | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
| 463 | + | |
457 | 464 | | |
458 | 465 | | |
459 | 466 | | |
| |||
499 | 506 | | |
500 | 507 | | |
501 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
502 | 532 | | |
503 | 533 | | |
504 | 534 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3277 | 3277 | | |
3278 | 3278 | | |
3279 | 3279 | | |
3280 | | - | |
3281 | | - | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
3282 | 3283 | | |
3283 | | - | |
3284 | | - | |
3285 | | - | |
3286 | | - | |
3287 | | - | |
3288 | | - | |
3289 | | - | |
3290 | | - | |
3291 | | - | |
3292 | | - | |
3293 | 3284 | | |
3294 | 3285 | | |
3295 | 3286 | | |
| |||
3665 | 3656 | | |
3666 | 3657 | | |
3667 | 3658 | | |
3668 | | - | |
| 3659 | + | |
3669 | 3660 | | |
3670 | 3661 | | |
3671 | 3662 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
753 | 760 | | |
754 | 761 | | |
755 | 762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
0 commit comments