1 ; RUN: opt -mtriple=amdgcn-- -O3 -S %s | FileCheck %s
3 ; Check that loop unswitch does not happen if condition is divergent.
5 ; CHECK-LABEL: {{^}}define amdgpu_kernel void @divergent_unswitch
8 ; CHECK: [[IF_COND:%[a-z0-9]+]] = icmp {{.*}} 567890
10 ; CHECK: br i1 [[IF_COND]]
12 define amdgpu_kernel void @divergent_unswitch(i32 * nocapture %out, i32 %n) {
14 %cmp9 = icmp sgt i32 %n, 0
15 br i1 %cmp9, label %for.body.lr.ph, label %for.cond.cleanup
17 for.body.lr.ph: ; preds = %entry
18 %call = tail call i32 @llvm.amdgcn.workitem.id.x() #0
19 %cmp2 = icmp eq i32 %call, 567890
22 for.cond.cleanup.loopexit: ; preds = %for.inc
23 br label %for.cond.cleanup
25 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
28 for.body: ; preds = %for.inc, %for.body.lr.ph
29 %i.010 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
30 br i1 %cmp2, label %if.then, label %for.inc
32 if.then: ; preds = %for.body
33 %arrayidx = getelementptr inbounds i32, i32 * %out, i32 %i.010
34 store i32 %i.010, i32 * %arrayidx, align 4
37 for.inc: ; preds = %for.body, %if.then
38 %inc = add nuw nsw i32 %i.010, 1
39 %exitcond = icmp eq i32 %inc, %n
40 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body
43 declare i32 @llvm.amdgcn.workitem.id.x() #0
45 attributes #0 = { nounwind readnone }