-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[LoopFusion] Forget loop and block dispositions after latch merge #166233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CongzheUalberta
merged 1 commit into
llvm:main
from
1997alireza:fix-loop-disposition-crash
Nov 4, 2025
+75
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| ; REQUIRES: asserts | ||
| ; RUN: opt -passes=loop-fusion -disable-output -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s | ||
| ; STAT: 1 loop-fusion - Loops fused | ||
|
|
||
| ; C Code | ||
| ; | ||
| ;; for (int i = 0; i < 100; ++i) | ||
| ;; Array[i][i] = -i; | ||
| ;; for (int row = 0; row < 100; ++row) | ||
| ;; for (int col = 0; col < 100; ++col) | ||
| ;; if (col != row) | ||
| ;; Array[row][col] = row + col; | ||
| ; | ||
| ; Loop fusion should not crash anymore as now forgetBlockAndLoopDispositions() | ||
| ; is trigerred after mergeLatch() during the fusion. | ||
|
|
||
| define i32 @forget_dispositions() nounwind { | ||
| entry: | ||
| %Array = alloca [100 x [100 x i32]], align 4 | ||
| br label %for.body | ||
|
|
||
| for.body: ; preds = %for.body, %entry | ||
| %indvars.iv33 = phi i64 [ 0, %entry ], [ %indvars.iv.next34, %for.body ] | ||
| %0 = trunc i64 %indvars.iv33 to i32 | ||
| %sub = sub i32 0, %0 | ||
| %arrayidx2 = getelementptr inbounds [100 x [100 x i32]], ptr %Array, i64 0, i64 %indvars.iv33, i64 %indvars.iv33 | ||
| store i32 %sub, ptr %arrayidx2, align 4 | ||
| %indvars.iv.next34 = add i64 %indvars.iv33, 1 | ||
| %lftr.wideiv35 = trunc i64 %indvars.iv.next34 to i32 | ||
| %exitcond36 = icmp eq i32 %lftr.wideiv35, 100 | ||
| br i1 %exitcond36, label %for.cond6.preheader, label %for.body | ||
|
|
||
| for.cond6.preheader: ; preds = %for.body, %for.inc17 | ||
| %indvars.iv29 = phi i64 [ %indvars.iv.next30, %for.inc17 ], [ 0, %for.body ] | ||
| br label %for.body8 | ||
|
|
||
| for.body8: ; preds = %for.inc14, %for.cond6.preheader | ||
| %indvars.iv = phi i64 [ 0, %for.cond6.preheader ], [ %indvars.iv.next, %for.inc14 ] | ||
| %1 = trunc i64 %indvars.iv to i32 | ||
| %2 = trunc i64 %indvars.iv29 to i32 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you simplify the test IR? For example you may get rid of all
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the IR is generated by the compiler let's leave it as is? |
||
| %cmp9 = icmp eq i32 %1, %2 | ||
| br i1 %cmp9, label %for.inc14, label %if.then | ||
|
|
||
| if.then: ; preds = %for.body8 | ||
| %3 = add i64 %indvars.iv, %indvars.iv29 | ||
| %arrayidx13 = getelementptr inbounds [100 x [100 x i32]], ptr %Array, i64 0, i64 %indvars.iv29, i64 %indvars.iv | ||
| %4 = trunc i64 %3 to i32 | ||
| store i32 %4, ptr %arrayidx13, align 4 | ||
| br label %for.inc14 | ||
|
|
||
| for.inc14: ; preds = %for.body8, %if.then | ||
| %indvars.iv.next = add i64 %indvars.iv, 1 | ||
| %lftr.wideiv27 = trunc i64 %indvars.iv.next to i32 | ||
| %exitcond28 = icmp eq i32 %lftr.wideiv27, 100 | ||
| br i1 %exitcond28, label %for.inc17, label %for.body8 | ||
|
|
||
| for.inc17: ; preds = %for.inc14 | ||
| %indvars.iv.next30 = add i64 %indvars.iv29, 1 | ||
| %lftr.wideiv31 = trunc i64 %indvars.iv.next30 to i32 | ||
| %exitcond32 = icmp eq i32 %lftr.wideiv31, 100 | ||
| br i1 %exitcond32, label %for.exit, label %for.cond6.preheader | ||
|
|
||
| for.exit: ; preds = %for.inc17 | ||
| ret i32 0 | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
; REQUIRES: asserts-stats requires asserts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.