-
Notifications
You must be signed in to change notification settings - Fork 830
[ScopeNestedCFG] Prevent blocks containing convergent instructions from being cloned #8142
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
Changes from all commits
09b83df
04942c0
2dc57f5
d764c88
da3a13e
5a9e0e5
1d7338a
8f3aa16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ enum class BranchKind { | |
| SwitchEnd, | ||
| SwitchNoEnd, | ||
| SwitchBreak, | ||
| SwitchFallthrough, | ||
|
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. This changes the subsequent Since |
||
|
|
||
| LoopBegin, | ||
| LoopExit, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| ; RUN: %opt-exe %s -scopenested -S | FileCheck %s | ||
|
|
||
| ; verify that this pass won't identify fallthrough blocks | ||
| ; as merge points and in turn won't duplicate blocks | ||
| ; which contain convergent operations | ||
|
|
||
| ; previously, blocks with wave operations would be cloned, | ||
| ; violating the principle that wave operations should | ||
| ; only be called by different threads when control flow | ||
| ; is distinct between those threads | ||
|
|
||
| declare float @dx.op.waveActiveOp.f32(i32, float, i8, i8) | ||
|
|
||
| ; CHECK-LABEL: define void @CSMain | ||
|
|
||
| define void @CSMain(i32 %tid, float %v) convergent { | ||
| entry: | ||
| switch i32 %tid, label %exit [ | ||
| i32 0, label %case0 | ||
| i32 1, label %case1 | ||
| ] | ||
|
|
||
| ; CHECK: case0: | ||
| case0: ; switch case 0 | ||
|
|
||
| ; CHECK: call float @dx.op.waveActiveOp.f32(i32 119, float %v, i8 0, i8 0) | ||
| ; CHECK: br label %case1, !dx.BranchKind ![[BK:.*]] | ||
| %w0 = call float @dx.op.waveActiveOp.f32(i32 119, float %v, i8 0, i8 0) | ||
| br label %case1 ; FALLTHROUGH | ||
|
|
||
|
|
||
| ; CHECK: case1: | ||
| case1: ; switch case 1 | ||
| %a = phi float [ %w0, %case0 ], | ||
| [ 0.0, %entry ] | ||
|
|
||
| ; CHECK: call float @dx.op.waveActiveOp.f32(i32 119, float %v, i8 0, i8 0) | ||
| ; CHECK: br label %exit, !dx.BranchKind ![[BK]] | ||
| %w1 = call float @dx.op.waveActiveOp.f32(i32 119, float %v, i8 0, i8 0) | ||
| %sum = fadd float %a, %w1 | ||
| br label %exit | ||
|
|
||
| ; no cloning, so there should be no more waveops after this point | ||
| ; CHECK-NOT: call float @dx.waveActiveOp.f32(i32 119 | ||
|
|
||
| exit: | ||
| %r = phi float [ %sum, %case1 ], | ||
| [ 0.0, %entry ] | ||
| ret void | ||
| } | ||
|
|
||
| ; The BranchKind::SwitchFallthrough Kind ID is 8 | ||
| ; CHECK: ![[BK]] = !{i32 8} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| ; RUN: %opt-exe %s -scopenested -scopenestinfo -analyze -S | FileCheck %s | ||
|
|
||
| ; verify that scope nest info looks correct for fallthrough cases | ||
| ; we expect to see switch fallthrough treated as "Body", so | ||
| ; it should not effect the scope indentation level. | ||
|
|
||
|
|
||
| ; CHECK: @TopLevel_Begin | ||
| ; CHECK: entry | ||
| ; CHECK: @Switch_Begin | ||
| ; CHECK: @Switch_Case | ||
| ; CHECK: exit | ||
| ; CHECK: @Switch_Break | ||
| ; CHECK: @Switch_Case | ||
| ; CHECK: case0 | ||
| ; CHECK: case1 | ||
| ; CHECK: exit | ||
| ; CHECK: @Switch_Break | ||
| ; CHECK: @Switch_Case | ||
| ; CHECK: case1 | ||
|
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. Am I misreading this, or is case1 cloned here? Isn't that supposed to be prevented for blocks containing convergent ops? If this is a printing issue from
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. Or maybe this is a block that wasn't cloned, but is being iterated twice by scope nested iterator? I'm not familiar enough with these and haven't loaded enough context to be sure. Either way, |
||
| ; CHECK: exit | ||
| ; CHECK: @Switch_Break | ||
| ; CHECK: @Switch_End | ||
| ; CHECK: @TopLevel_End | ||
|
|
||
| declare float @dx.op.waveActiveOp.f32(i32, float, i8, i8) | ||
|
|
||
|
|
||
| define void @CSMain(i32 %tid, float %v) convergent { | ||
| entry: | ||
| switch i32 %tid, label %exit [ | ||
| i32 0, label %case0 | ||
| i32 1, label %case1 | ||
| ] | ||
|
|
||
| case0: ; switch case 0 | ||
|
|
||
| %w0 = call float @dx.op.waveActiveOp.f32(i32 119, float %v, i8 0, i8 0) | ||
| br label %case1 ; FALLTHROUGH | ||
|
|
||
|
|
||
| case1: ; switch case 1 | ||
| %a = phi float [ %w0, %case0 ], | ||
| [ 0.0, %entry ] | ||
|
|
||
| %w1 = call float @dx.op.waveActiveOp.f32(i32 119, float %v, i8 0, i8 0) | ||
| %sum = fadd float %a, %w1 | ||
| br label %exit | ||
|
|
||
| exit: | ||
| %r = phi float [ %sum, %case1 ], | ||
| [ 0.0, %entry ] | ||
| ret void | ||
| } | ||
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 generated pattern shouldn't be hand-written. You really want to include all gradient ops (derivative ops and ops that use derivatives). It turns out there's already a
IsDxilOpGradientwith the op set generated fromhctdb.py. You can call that here instead.