-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split continues with convergent calls in some cases (#1439)
* Adds a new transform to FixupStructuredCFG to split a continue (latch) into two blocks under certain circumstances: * The loop header is a conditional branch to the body and latch * The latch has two predecessors * The latch contains a convergent call * This transformation prevents clspv forces (along with the breakConditionalHeader transform in the same pass) to prevent convergent operations from being placed in the loop continue contruct. Instead they end up as a structured selection in the body. This ensures reconvergence more robustly than previously. SPIRV-Cross, for example, inlines continues into the body under the assumption that reconvergence is not expected
- Loading branch information
1 parent
7b4ea7e
commit 85146eb
Showing
5 changed files
with
210 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
42 changes: 42 additions & 0 deletions
42
test/FixupStructuredCFG/split_convergent_continue_branch.ll
This file contains 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,42 @@ | ||
; RUN: clspv-opt --passes=fixup-structured-cfg %s -o %t.ll | ||
; RUN: FileCheck %s < %t.ll | ||
|
||
; CHECK: entry: | ||
; CHECK-NEXT: br label %[[new_header:[a-zA-Z0-9_.]+]] | ||
; CHECK: [[new_header]]: | ||
; CHECK-NEXT: br label %loop | ||
; CHECK: loop: | ||
; CHECK-NEXT: br i1 undef, label %then, label %[[pre_cont:[a-zA-Z0-9_.]+]] | ||
; CHECK: then: | ||
; CHECK-NEXT: br i1 undef, label %[[pre_cont]], label %exit | ||
; CHECK: [[pre_cont]]: | ||
; CHECK: call void @_Z8spirv.op.224 | ||
; CHECK-NEXT: br label %[[cont:[a-zA-Z0-9_.]+]] | ||
; CHECK: [[cont]]: | ||
; CHECK-NEXT: br label %[[new_header]] | ||
|
||
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir-unknown-unknown" | ||
|
||
define spir_kernel void @test() { | ||
entry: | ||
br label %loop | ||
|
||
loop: | ||
br i1 undef, label %then, label %cont | ||
|
||
then: | ||
br i1 undef, label %cont, label %exit | ||
|
||
cont: | ||
tail call void @_Z8spirv.op.224.jjj(i32 224, i32 2, i32 2, i32 264) #0 | ||
br label %loop | ||
|
||
exit: | ||
ret void | ||
} | ||
|
||
attributes #0 = { convergent } | ||
|
||
declare void @_Z8spirv.op.224.jjj(i32, i32, i32, i32) #0 | ||
|
44 changes: 44 additions & 0 deletions
44
test/FixupStructuredCFG/split_convergent_continue_cond_branch.ll
This file contains 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,44 @@ | ||
; RUN: clspv-opt --passes=fixup-structured-cfg %s -o %t.ll | ||
; RUN: FileCheck %s < %t.ll | ||
|
||
; CHECK: entry: | ||
; CHECK-NEXT: br label %[[new_header:[a-zA-Z0-9_.]+]] | ||
; CHECK: [[new_header]]: | ||
; CHECK-NEXT: phi i32 [ 0, %entry ], [ 1, %[[cont:[a-zA-Z0-9_.]+]] ] | ||
; CHECK-NEXT: br label %loop | ||
; CHECK: loop: | ||
; CHECK-NEXT: br i1 undef, label %then, label %[[pre_cont:[a-zA-Z0-9_.]+]] | ||
; CHECK: then: | ||
; CHECK-NEXT: br label %[[pre_cont]] | ||
; CHECK: [[pre_cont]]: | ||
; CHECK: call void @_Z8spirv.op.224 | ||
; CHECK-NEXT: br i1 undef, label %[[cont]], label %exit | ||
; CHECK: [[cont]]: | ||
; CHECK-NEXT: br label %[[new_header]] | ||
|
||
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" | ||
target triple = "spir-unknown-unknown" | ||
|
||
define spir_kernel void @test() { | ||
entry: | ||
br label %loop | ||
|
||
loop: | ||
%0 = phi i32 [ 0, %entry ], [ 1, %cont ] | ||
br i1 undef, label %then, label %cont | ||
|
||
then: | ||
br label %cont | ||
|
||
cont: | ||
tail call void @_Z8spirv.op.224.jjj(i32 224, i32 2, i32 2, i32 264) #0 | ||
br i1 undef, label %loop, label %exit | ||
|
||
exit: | ||
ret void | ||
} | ||
|
||
attributes #0 = { convergent } | ||
|
||
declare void @_Z8spirv.op.224.jjj(i32, i32, i32, i32) #0 | ||
|
This file contains 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