Stanislav Mekhanoshin | ee2dd78 | 2017-03-17 17:13:41 +0000 | [diff] [blame] | 1 | ; RUN: opt -mtriple=amdgcn-- -O3 -S %s | FileCheck %s |
| 2 | |
| 3 | ; Check that loop unswitch happened and condition hoisted out of the loop. |
| 4 | ; Condition is uniform so all targets should perform unswitching. |
| 5 | |
Matt Arsenault | 3dbeefa | 2017-03-21 21:39:51 +0000 | [diff] [blame^] | 6 | ; CHECK-LABEL: {{^}}define amdgpu_kernel void @uniform_unswitch |
Stanislav Mekhanoshin | ee2dd78 | 2017-03-17 17:13:41 +0000 | [diff] [blame] | 7 | ; CHECK: entry: |
| 8 | ; CHECK-NEXT: [[LOOP_COND:%[a-z0-9]+]] = icmp |
| 9 | ; CHECK-NEXT: [[IF_COND:%[a-z0-9]+]] = icmp eq i32 %x, 123456 |
| 10 | ; CHECK-NEXT: and i1 [[LOOP_COND]], [[IF_COND]] |
| 11 | ; CHECK-NEXT: br i1 |
| 12 | |
Matt Arsenault | 3dbeefa | 2017-03-21 21:39:51 +0000 | [diff] [blame^] | 13 | define amdgpu_kernel void @uniform_unswitch(i32 * nocapture %out, i32 %n, i32 %x) { |
Stanislav Mekhanoshin | ee2dd78 | 2017-03-17 17:13:41 +0000 | [diff] [blame] | 14 | entry: |
| 15 | %cmp6 = icmp sgt i32 %n, 0 |
| 16 | br i1 %cmp6, label %for.body.lr.ph, label %for.cond.cleanup |
| 17 | |
| 18 | for.body.lr.ph: ; preds = %entry |
| 19 | %cmp1 = icmp eq i32 %x, 123456 |
| 20 | br label %for.body |
| 21 | |
| 22 | for.cond.cleanup.loopexit: ; preds = %for.inc |
| 23 | br label %for.cond.cleanup |
| 24 | |
| 25 | for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry |
| 26 | ret void |
| 27 | |
| 28 | for.body: ; preds = %for.inc, %for.body.lr.ph |
| 29 | %i.07 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] |
| 30 | br i1 %cmp1, label %if.then, label %for.inc |
| 31 | |
| 32 | if.then: ; preds = %for.body |
| 33 | %arrayidx = getelementptr inbounds i32, i32 * %out, i32 %i.07 |
| 34 | store i32 %i.07, i32 * %arrayidx, align 4 |
| 35 | br label %for.inc |
| 36 | |
| 37 | for.inc: ; preds = %for.body, %if.then |
| 38 | %inc = add nuw nsw i32 %i.07, 1 |
| 39 | %exitcond = icmp eq i32 %inc, %n |
| 40 | br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body |
| 41 | } |
| 42 | |
| 43 | ; Check that loop unswitch does not happen if condition is divergent. |
| 44 | |
Matt Arsenault | 3dbeefa | 2017-03-21 21:39:51 +0000 | [diff] [blame^] | 45 | ; CHECK-LABEL: {{^}}define amdgpu_kernel void @divergent_unswitch |
Stanislav Mekhanoshin | ee2dd78 | 2017-03-17 17:13:41 +0000 | [diff] [blame] | 46 | ; CHECK: entry: |
| 47 | ; CHECK: icmp |
| 48 | ; CHECK: [[IF_COND:%[a-z0-9]+]] = icmp {{.*}} 567890 |
| 49 | ; CHECK: br label |
| 50 | ; CHECK: br i1 [[IF_COND]] |
| 51 | |
Matt Arsenault | 3dbeefa | 2017-03-21 21:39:51 +0000 | [diff] [blame^] | 52 | define amdgpu_kernel void @divergent_unswitch(i32 * nocapture %out, i32 %n) { |
Stanislav Mekhanoshin | ee2dd78 | 2017-03-17 17:13:41 +0000 | [diff] [blame] | 53 | entry: |
| 54 | %cmp9 = icmp sgt i32 %n, 0 |
| 55 | br i1 %cmp9, label %for.body.lr.ph, label %for.cond.cleanup |
| 56 | |
| 57 | for.body.lr.ph: ; preds = %entry |
| 58 | %call = tail call i32 @llvm.amdgcn.workitem.id.x() #0 |
| 59 | %cmp2 = icmp eq i32 %call, 567890 |
| 60 | br label %for.body |
| 61 | |
| 62 | for.cond.cleanup.loopexit: ; preds = %for.inc |
| 63 | br label %for.cond.cleanup |
| 64 | |
| 65 | for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry |
| 66 | ret void |
| 67 | |
| 68 | for.body: ; preds = %for.inc, %for.body.lr.ph |
| 69 | %i.010 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] |
| 70 | br i1 %cmp2, label %if.then, label %for.inc |
| 71 | |
| 72 | if.then: ; preds = %for.body |
| 73 | %arrayidx = getelementptr inbounds i32, i32 * %out, i32 %i.010 |
| 74 | store i32 %i.010, i32 * %arrayidx, align 4 |
| 75 | br label %for.inc |
| 76 | |
| 77 | for.inc: ; preds = %for.body, %if.then |
| 78 | %inc = add nuw nsw i32 %i.010, 1 |
| 79 | %exitcond = icmp eq i32 %inc, %n |
| 80 | br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body |
| 81 | } |
| 82 | |
| 83 | declare i32 @llvm.amdgcn.workitem.id.x() #0 |
| 84 | |
| 85 | attributes #0 = { nounwind readnone } |