1 ; RUN: opt %s -mtriple amdgcn-- -passes='print<divergence>' -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 ; RUN: opt -mtriple amdgcn-- -passes='print<divergence>' -disable-output %s 2>&1 | FileCheck %s
12 ; This test contains an unstructured loop.
13 ; +-------------- entry ----------------+
16 ; i1 = phi(0, i3) i2 = phi(0, i3)
17 ; j1 = i1 + 1 ---> i3 = phi(j1, j2) <--- j2 = i2 + 2
20 ; +-------- switch (tid / i3) ----------+
23 ; if (i3 == 5) // divergent
24 ; because sync dependent on (tid / i3).
25 define i32 @unstructured_loop(i1 %entry_cond) {
26 ; CHECK-LABEL: Divergence Analysis' for function 'unstructured_loop'
28 %tid = call i32 @llvm.amdgcn.workitem.id.x()
29 br i1 %entry_cond, label %loop_entry_1, label %loop_entry_2
31 %i1 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
35 %i2 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
39 %i3 = phi i32 [ %j1, %loop_entry_1 ], [ %j2, %loop_entry_2 ]
42 %div = sdiv i32 %tid, %i3
43 switch i32 %div, label %branch [ i32 1, label %loop_entry_1
44 i32 2, label %loop_entry_2 ]
46 %cmp = icmp eq i32 %i3, 5
47 br i1 %cmp, label %then, label %else
48 ; CHECK: DIVERGENT: br i1 %cmp,
55 declare i32 @llvm.amdgcn.workitem.id.x() #0
57 attributes #0 = { nounwind readnone }