forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NVPTX] support switch statement with brx.idx (llvm#102400)
Add custom lowering for `BR_JT` DAG nodes to the `brx.idx` PTX instruction ([PTX ISA 9.7.13.4. Control Flow Instructions: brx.idx] (https://docs.nvidia.com/cuda/parallel-thread-execution/#control-flow-instructions-brx-idx)). Depending on the heuristics in DAG selection, `switch` statements may now be lowered using `brx.idx`
- Loading branch information
1 parent
8c3b6bd
commit ba97697
Showing
6 changed files
with
169 additions
and
8 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s | FileCheck %s | ||
; RUN: %if ptxas %{ llc < %s | %ptxas-verify %} | ||
|
||
target triple = "nvptx64-nvidia-cuda" | ||
|
||
@out = addrspace(1) global i32 0, align 4 | ||
|
||
define void @foo(i32 %i) { | ||
; CHECK-LABEL: foo( | ||
; CHECK: { | ||
; CHECK-NEXT: .reg .pred %p<2>; | ||
; CHECK-NEXT: .reg .b32 %r<7>; | ||
; CHECK-EMPTY: | ||
; CHECK-NEXT: // %bb.0: // %entry | ||
; CHECK-NEXT: ld.param.u32 %r2, [foo_param_0]; | ||
; CHECK-NEXT: setp.gt.u32 %p1, %r2, 3; | ||
; CHECK-NEXT: @%p1 bra $L__BB0_6; | ||
; CHECK-NEXT: // %bb.1: // %entry | ||
; CHECK-NEXT: $L_brx_0: .branchtargets | ||
; CHECK-NEXT: $L__BB0_2, | ||
; CHECK-NEXT: $L__BB0_3, | ||
; CHECK-NEXT: $L__BB0_4, | ||
; CHECK-NEXT: $L__BB0_5; | ||
; CHECK-NEXT: brx.idx %r2, $L_brx_0; | ||
; CHECK-NEXT: $L__BB0_2: // %case0 | ||
; CHECK-NEXT: mov.b32 %r6, 0; | ||
; CHECK-NEXT: st.global.u32 [out], %r6; | ||
; CHECK-NEXT: bra.uni $L__BB0_6; | ||
; CHECK-NEXT: $L__BB0_4: // %case2 | ||
; CHECK-NEXT: mov.b32 %r4, 2; | ||
; CHECK-NEXT: st.global.u32 [out], %r4; | ||
; CHECK-NEXT: bra.uni $L__BB0_6; | ||
; CHECK-NEXT: $L__BB0_5: // %case3 | ||
; CHECK-NEXT: mov.b32 %r3, 3; | ||
; CHECK-NEXT: st.global.u32 [out], %r3; | ||
; CHECK-NEXT: bra.uni $L__BB0_6; | ||
; CHECK-NEXT: $L__BB0_3: // %case1 | ||
; CHECK-NEXT: mov.b32 %r5, 1; | ||
; CHECK-NEXT: st.global.u32 [out], %r5; | ||
; CHECK-NEXT: $L__BB0_6: // %end | ||
; CHECK-NEXT: ret; | ||
entry: | ||
switch i32 %i, label %end [ | ||
i32 0, label %case0 | ||
i32 1, label %case1 | ||
i32 2, label %case2 | ||
i32 3, label %case3 | ||
] | ||
|
||
case0: | ||
store i32 0, ptr addrspace(1) @out, align 4 | ||
br label %end | ||
|
||
case1: | ||
store i32 1, ptr addrspace(1) @out, align 4 | ||
br label %end | ||
|
||
case2: | ||
store i32 2, ptr addrspace(1) @out, align 4 | ||
br label %end | ||
|
||
case3: | ||
store i32 3, ptr addrspace(1) @out, align 4 | ||
br label %end | ||
|
||
end: | ||
ret void | ||
} |