xref: /aosp_15_r20/external/llvm/test/CodeGen/NVPTX/branch-fold.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=nvptx64 -mcpu=sm_35 -disable-cgp | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; Disable CGP which also folds branches, so that only BranchFolding is under
3*9880d681SAndroid Build Coastguard Worker; the spotlight.
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
6*9880d681SAndroid Build Coastguard Workertarget triple = "nvptx64-nvidia-cuda"
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Workerdefine void @foo(i32 %x, float* %output) {
9*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: .visible .func foo(
10*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: bra.uni
11*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: LBB0_
12*9880d681SAndroid Build Coastguard Worker  %1 = icmp eq i32 %x, 1
13*9880d681SAndroid Build Coastguard Worker  br i1 %1, label %then, label %else
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerthen:
16*9880d681SAndroid Build Coastguard Worker  br label %merge
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Workerelse:
19*9880d681SAndroid Build Coastguard Worker  br label %merge
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Workermerge:
22*9880d681SAndroid Build Coastguard Worker  store float 2.0, float* %output
23*9880d681SAndroid Build Coastguard Worker  ret void
24*9880d681SAndroid Build Coastguard Worker}
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker; PR24299. no crash
27*9880d681SAndroid Build Coastguard Workerdefine ptx_kernel void @hoge() #0 {
28*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: .visible .entry hoge(
29*9880d681SAndroid Build Coastguard Workerbb:
30*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb1, label %bb4
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Workerbb1:                                              ; preds = %bb1, %bb
33*9880d681SAndroid Build Coastguard Worker  %tmp = phi i64 [ %tmp2, %bb1 ], [ undef, %bb ]
34*9880d681SAndroid Build Coastguard Worker  %tmp2 = add nsw i64 %tmp, 1
35*9880d681SAndroid Build Coastguard Worker  %tmp3 = icmp sle i64 %tmp, 0
36*9880d681SAndroid Build Coastguard Worker  br i1 %tmp3, label %bb1, label %bb4
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workerbb4:                                              ; preds = %bb4, %bb1, %bb
39*9880d681SAndroid Build Coastguard Worker  br label %bb4
40*9880d681SAndroid Build Coastguard Worker}
41