1 ; RUN: opt -mtriple=amdgcn-- -analyze -divergence -use-gpu-divergence-analysis %s | FileCheck %s
3 ; This test contains an unstructured loop.
4 ; +-------------- entry ----------------+
7 ; i1 = phi(0, i3) i2 = phi(0, i3)
8 ; j1 = i1 + 1 ---> i3 = phi(j1, j2) <--- j2 = i2 + 2
11 ; +-------- switch (tid / i3) ----------+
14 ; if (i3 == 5) // divergent
15 ; because sync dependent on (tid / i3).
16 define i32 @unstructured_loop(i1 %entry_cond) {
17 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'unstructured_loop'
19 %tid = call i32 @llvm.amdgcn.workitem.id.x()
20 br i1 %entry_cond, label %loop_entry_1, label %loop_entry_2
22 %i1 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
26 %i2 = phi i32 [ 0, %entry ], [ %i3, %loop_latch ]
30 %i3 = phi i32 [ %j1, %loop_entry_1 ], [ %j2, %loop_entry_2 ]
33 %div = sdiv i32 %tid, %i3
34 switch i32 %div, label %branch [ i32 1, label %loop_entry_1
35 i32 2, label %loop_entry_2 ]
37 %cmp = icmp eq i32 %i3, 5
38 br i1 %cmp, label %then, label %else
39 ; CHECK: DIVERGENT: br i1 %cmp,
46 declare i32 @llvm.amdgcn.workitem.id.x() #0
48 attributes #0 = { nounwind readnone }