-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SimplifyCFG] Fix SimplifyCFG pass to skip folding when both blocks contain convergence intrinsics.
#166452
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
luciechoi
wants to merge
3
commits into
llvm:main
Choose a base branch
from
luciechoi:cfgsimplify
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.
+77
−0
Open
[SimplifyCFG] Fix SimplifyCFG pass to skip folding when both blocks contain convergence intrinsics.
#166452
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
68 changes: 68 additions & 0 deletions
68
llvm/test/Transforms/SimplifyCFG/skip-merging-duplicate-convergence-instrinsics.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,68 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
| ; RUN: opt < %s -S -passes=simplifycfg | FileCheck %s | ||
|
|
||
| declare token @llvm.experimental.convergence.entry() #0 | ||
|
|
||
| define void @nested(i32 %tidx, i32 %tidy, ptr %array) #0 { | ||
| ; CHECK-LABEL: @nested( | ||
| ; CHECK-NEXT: entry: | ||
| ; CHECK-NEXT: [[TMP0:%.*]] = tail call token @llvm.experimental.convergence.entry() | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[TIDY:%.*]], [[TIDX:%.*]] | ||
| ; CHECK-NEXT: [[OR_COND_I:%.*]] = icmp eq i32 [[TMP1]], 0 | ||
| ; CHECK-NEXT: br label [[FOR_COND_I:%.*]] | ||
| ; CHECK: for.cond.i: | ||
| ; CHECK-NEXT: [[TMP2:%.*]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token [[TMP0]]) ] | ||
| ; CHECK-NEXT: br label [[FOR_COND1_I:%.*]] | ||
| ; CHECK: for.cond1.i: | ||
| ; CHECK-NEXT: [[CMP2_I:%.*]] = phi i1 [ false, [[FOR_BODY4_I:%.*]] ], [ true, [[FOR_COND_I]] ] | ||
| ; CHECK-NEXT: [[TMP3:%.*]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token [[TMP2]]) ] | ||
| ; CHECK-NEXT: br i1 [[CMP2_I]], label [[FOR_BODY4_I]], label [[EXIT:%.*]] | ||
| ; CHECK: for.body4.i: | ||
| ; CHECK-NEXT: br i1 [[OR_COND_I]], label [[IF_THEN_I:%.*]], label [[FOR_COND1_I]] | ||
| ; CHECK: if.then.i: | ||
| ; CHECK-NEXT: [[TEST_VAL:%.*]] = call spir_func i32 @func_test(i32 0) [ "convergencectrl"(token [[TMP3]]) ] | ||
| ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i32, ptr [[ARRAY:%.*]], i32 0 | ||
| ; CHECK-NEXT: store i32 [[TEST_VAL]], ptr [[TMP4]], align 4 | ||
| ; CHECK-NEXT: br label [[EXIT]] | ||
| ; CHECK: exit: | ||
| ; CHECK-NEXT: ret void | ||
| ; | ||
| entry: | ||
| %0 = tail call token @llvm.experimental.convergence.entry() | ||
| %2 = or i32 %tidy, %tidx | ||
| %or.cond.i = icmp eq i32 %2, 0 | ||
| br label %for.cond.i | ||
|
|
||
| for.cond.i: | ||
| %3 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ] | ||
| br label %for.cond1.i | ||
|
|
||
| for.cond1.i: | ||
| %cmp2.i = phi i1 [ false, %for.body4.i ], [ true, %for.cond.i ] | ||
| %4 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %3) ] | ||
| br i1 %cmp2.i, label %for.body4.i, label %cleanup.i.loopexit | ||
|
|
||
| for.body4.i: | ||
| br i1 %or.cond.i, label %if.then.i, label %for.cond1.i | ||
|
|
||
| if.then.i: | ||
| %test.val = call spir_func i32 @func_test(i32 0) [ "convergencectrl"(token %4) ] | ||
| %5 = getelementptr inbounds i32, ptr %array, i32 0 | ||
| store i32 %test.val, ptr %5, align 4 | ||
| br label %cleanup.i | ||
|
|
||
| cleanup.i.loopexit: | ||
| br label %cleanup.i | ||
|
|
||
| cleanup.i: | ||
| br label %exit | ||
|
|
||
| exit: | ||
| ret void | ||
| } | ||
|
|
||
| declare token @llvm.experimental.convergence.loop() #0 | ||
|
|
||
| declare i32 @func_test(i32) #0 | ||
|
|
||
| attributes #0 = { convergent } |
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.
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.
This is a move expensive check because it has to traverse potentially two basic blocks. We should move it later. I would make it the last check before deciding to merge.
Also the way this is written is a little unclear. First if we know that there can be at most one convergence token per basic block, we could make this two separate checks and take advantage of short-circuit evaluation:
Then the check becomes: