1 ; RUN: opt %s -analyze -divergence -use-gpu-divergence-analysis | FileCheck %s
3 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
4 target triple = "nvptx64-nvidia-cuda"
6 ; This test contains an unstructured loop.
7 ; +-------------- entry ----------------+
10 ; i1 = phi(0, i3) i2 = phi(0, i3)
11 ; j1 = i1 + 1 ---> i3 = phi(j1, j2) <--- j2 = i2 + 2
14 ; +-------- switch (tid / i3) ----------+
17 ; if (i3 == 5) // divergent
18 ; because sync dependent on (tid / i3).
19 define i32 @unstructured_loop(i1 %entry_cond) {
20 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'unstructured_loop'
22 %tid = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
23 br i1 %entry_cond, label %loop_entry_1, label %loop_entry_2
25 %i1 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
29 %i2 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
33 %i3 = phi i32 [ %j1, %loop_entry_1 ], [ %j2, %loop_entry_2 ]
36 %div = sdiv i32 %tid, %i3
37 switch i32 %div, label %branch [ i32 1, label %loop_entry_1
38 i32 2, label %loop_entry_2 ]
40 %cmp = icmp eq i32 %i3, 5
41 br i1 %cmp, label %then, label %else
42 ; CHECK: DIVERGENT: br i1 %cmp,
49 declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
50 declare i32 @llvm.nvvm.read.ptx.sreg.tid.y()
51 declare i32 @llvm.nvvm.read.ptx.sreg.tid.z()
52 declare i32 @llvm.nvvm.read.ptx.sreg.laneid()
54 !nvvm.annotations = !{!0}
55 !0 = !{i32 (i1)* @unstructured_loop, !"kernel", i32 1}