1 ; RUN: opt %s -passes='print<uniformity>' -disable-output 2>&1 | FileCheck %s
3 ; NOTE: The new pass manager does not fall back on legacy divergence
4 ; analysis even when the function contains an irreducible loop. The
5 ; (new) divergence analysis conservatively reports all values as
6 ; divergent. This test does not check for this conservative
7 ; behaviour. Instead, it only checks for the values that are known to
8 ; be divergent according to the legacy analysis.
10 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
11 target triple = "nvptx64-nvidia-cuda"
13 ; This test contains an unstructured loop.
14 ; +-------------- entry ----------------+
17 ; i1 = phi(0, i3) i2 = phi(0, i3)
18 ; j1 = i1 + 1 ---> i3 = phi(j1, j2) <--- j2 = i2 + 2
21 ; +-------- switch (tid / i3) ----------+
24 ; if (i3 == 5) // divergent
25 ; because sync dependent on (tid / i3).
26 define i32 @unstructured_loop(i1 %entry_cond) {
27 ; CHECK-LABEL: for function 'unstructured_loop'
29 %tid = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
30 br i1 %entry_cond, label %loop_entry_1, label %loop_entry_2
32 %i1 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
36 %i2 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
40 %i3 = phi i32 [ %j1, %loop_entry_1 ], [ %j2, %loop_entry_2 ]
43 %div = sdiv i32 %tid, %i3
44 switch i32 %div, label %branch [ i32 1, label %loop_entry_1
45 i32 2, label %loop_entry_2 ]
47 %cmp = icmp eq i32 %i3, 5
48 br i1 %cmp, label %then, label %else
49 ; CHECK: DIVERGENT: %cmp =
50 ; CHECK: DIVERGENT: br i1 %cmp,
57 declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
58 declare i32 @llvm.nvvm.read.ptx.sreg.tid.y()
59 declare i32 @llvm.nvvm.read.ptx.sreg.tid.z()
60 declare i32 @llvm.nvvm.read.ptx.sreg.laneid()
62 !nvvm.annotations = !{!0}
63 !0 = !{ptr @unstructured_loop, !"kernel", i32 1}