-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[LoopUnroll] Structural cost savings analysis for full loop unrolling #114579
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
Open
lucas-rami
wants to merge
6
commits into
llvm:main
Choose a base branch
from
lucas-rami:unroll-thresold-bonus-to-nest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f56c432
Give cond. loop threshold bonus to outer loop in loop nests
lucas-rami 0a72dca
Address reviewers' comments
lucas-rami 30a4827
Moved logic to target-independent analysis and improved it
lucas-rami 271cb46
Fix clang-format
lucas-rami 9cb76b5
Merge branch 'main' into unroll-thresold-bonus-to-nest
lucas-rami 046a9a3
Address feedback, almost NFC
lucas-rami 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
84 changes: 84 additions & 0 deletions
84
llvm/test/Transforms/LoopUnroll/AMDGPU/unroll-dependent-sub.ll
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,84 @@ | ||
| ; RUN: opt -S -mtriple=amdgcn-- -passes=loop-unroll -debug-only=AMDGPUtti < %s 2>&1 | FileCheck %s | ||
lucas-rami marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ; For @dependent_sub_fullunroll, the threshold bonus should apply | ||
| ; CHECK: due to subloop's trip count becoming runtime-independent after unrolling | ||
lucas-rami marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ; For @dependent_sub_no_fullunroll, the threshold bonus should not apply | ||
| ; CHECK-NOT: due to subloop's trip count becoming runtime-independent after unrolling | ||
|
|
||
| ; Check that the outer loop of a double-nested loop where the inner loop's trip | ||
| ; count depends exclusively on constants and the outer IV is fully unrolled | ||
| ; thanks to receiving a threshold bonus in AMDGPU's TTI. | ||
|
|
||
| ; CHECK-LABEL: @dependent_sub_fullunroll | ||
| ; CHECK: inner.header_latch_exiting.7 | ||
| ; CHECK: outer.latch_exiting.7 | ||
|
|
||
| define void @dependent_sub_fullunroll(ptr noundef %mem) { | ||
| entry: | ||
| br label %outer.header | ||
|
|
||
| outer.header: ; preds = %entry, %outer.latch_exiting | ||
| %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv_next, %outer.latch_exiting ] | ||
| br label %inner.header_latch_exiting | ||
|
|
||
| inner.header_latch_exiting: ; preds = %outer.header, %inner.header_latch_exiting | ||
| %inner.iv = phi i32 [ %outer.iv, %outer.header ], [ %inner.iv_next, %inner.header_latch_exiting ] | ||
| %inner.iv_next = add nuw nsw i32 %inner.iv, 1 | ||
| %outer.iv.ext = zext nneg i32 %outer.iv to i64 | ||
| %idx_part = mul nuw nsw i64 %outer.iv.ext, 16 | ||
| %inner.iv.ext = zext nneg i32 %inner.iv to i64 | ||
| %idx = add nuw nsw i64 %idx_part, %inner.iv.ext | ||
| %addr = getelementptr inbounds i8, ptr %mem, i64 %idx | ||
| store i32 0, ptr %addr | ||
| %inner.cond = icmp ult i32 %inner.iv_next, 8 | ||
| br i1 %inner.cond, label %inner.header_latch_exiting, label %outer.latch_exiting, !llvm.loop !1 | ||
|
|
||
| outer.latch_exiting: ; preds = %inner.header_latch_exiting | ||
| %outer.iv_next = add nuw nsw i32 %outer.iv, 1 | ||
| %outer.cond = icmp ult i32 %outer.iv_next, 8 | ||
| br i1 %outer.cond, label %outer.header, label %end, !llvm.loop !1 | ||
|
|
||
| end: ; preds = %outer.latch_exiting | ||
| ret void | ||
| } | ||
|
|
||
| ; Check that the outer loop of the same loop nest as dependent_sub_fullunroll | ||
| ; is not fully unrolled when the inner loop's final IV value depends on a | ||
| ; function argument instead of a combination of the outer IV and constants. | ||
|
|
||
| ; CHECK-LABEL: @dependent_sub_no_fullunroll | ||
| ; CHECK-NOT: outer.latch_exiting.7 | ||
| ; CHECK-NOT: outer.latch_exiting.7 | ||
|
|
||
| define void @dependent_sub_no_fullunroll(ptr noundef %mem, i32 noundef %inner.ub) { | ||
| entry: | ||
| br label %outer.header | ||
|
|
||
| outer.header: ; preds = %entry, %outer.latch_exiting | ||
| %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv_next, %outer.latch_exiting ] | ||
| br label %inner.header_latch_exiting | ||
|
|
||
| inner.header_latch_exiting: ; preds = %outer.header, %inner.header_latch_exiting | ||
| %inner.iv = phi i32 [ %outer.iv, %outer.header ], [ %inner.iv_next, %inner.header_latch_exiting ] | ||
| %inner.iv_next = add nuw nsw i32 %inner.iv, 1 | ||
| %outer.iv.ext = zext nneg i32 %outer.iv to i64 | ||
| %idx_part = mul nuw nsw i64 %outer.iv.ext, 16 | ||
| %inner.iv.ext = zext nneg i32 %inner.iv to i64 | ||
| %idx = add nuw nsw i64 %idx_part, %inner.iv.ext | ||
| %addr = getelementptr inbounds i8, ptr %mem, i64 %idx | ||
| store i32 0, ptr %addr | ||
| %inner.cond = icmp ult i32 %inner.iv_next, %inner.ub | ||
| br i1 %inner.cond, label %inner.header_latch_exiting, label %outer.latch_exiting, !llvm.loop !1 | ||
|
|
||
| outer.latch_exiting: ; preds = %inner.header_latch_exiting | ||
| %outer.iv_next = add nuw nsw i32 %outer.iv, 1 | ||
| %outer.cond = icmp ult i32 %outer.iv_next, 8 | ||
| br i1 %outer.cond, label %outer.header, label %end, !llvm.loop !1 | ||
|
|
||
| end: ; preds = %outer.latch_exiting | ||
| ret void | ||
| } | ||
|
|
||
lucas-rami marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| !1 = !{!1, !2} | ||
| !2 = !{!"amdgpu.loop.unroll.threshold", i32 100} | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.