1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=amdgcn -mcpu=bonaire -loop-reduce -S < %s | FileCheck %s
4 ; Test various conditions where OptimizeLoopTermCond doesn't look at a
5 ; memory instruction use and fails to find the address space.
7 target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
9 define amdgpu_kernel void @local_cmp_user(i32 %arg0) nounwind {
10 ; CHECK-LABEL: @local_cmp_user(
12 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG0:%.*]], 1
13 ; CHECK-NEXT: br label [[BB11:%.*]]
15 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i32 [ [[LSR_IV_NEXT2:%.*]], [[BB:%.*]] ], [ -2, [[ENTRY:%.*]] ]
16 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[BB]] ], [ [[TMP0]], [[ENTRY]] ]
17 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add i32 [[LSR_IV]], -1
18 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add i32 [[LSR_IV1]], 2
19 ; CHECK-NEXT: [[C0:%.*]] = icmp eq i32 [[LSR_IV_NEXT]], 0
20 ; CHECK-NEXT: br i1 [[C0]], label [[BB13:%.*]], label [[BB]]
22 ; CHECK-NEXT: [[T:%.*]] = load ptr addrspace(3), ptr addrspace(3) undef, align 4
23 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr addrspace(3) [[T]], i32 [[LSR_IV_NEXT2]]
24 ; CHECK-NEXT: [[C1:%.*]] = icmp ne ptr addrspace(3) [[SCEVGEP]], null
25 ; CHECK-NEXT: br i1 [[C1]], label [[BB11]], label [[BB13]]
27 ; CHECK-NEXT: unreachable
32 bb11: ; preds = %bb, %entry
33 %i = phi i32 [ 0, %entry ], [ %i.next, %bb ]
35 %c0 = icmp eq i32 %i, %arg0
36 br i1 %c0, label %bb13, label %bb
39 %t = load ptr addrspace(3), ptr addrspace(3) undef, align 4
40 %p = getelementptr i8, ptr addrspace(3) %t, i32 %ii
41 %c1 = icmp ne ptr addrspace(3) %p, null
42 %i.next = add i32 %i, 1
43 br i1 %c1, label %bb11, label %bb13
45 bb13: ; preds = %bb, %bb11
49 define amdgpu_kernel void @global_cmp_user(i64 %arg0) nounwind {
50 ; CHECK-LABEL: @global_cmp_user(
52 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[ARG0:%.*]], 1
53 ; CHECK-NEXT: br label [[BB11:%.*]]
55 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ [[LSR_IV_NEXT2:%.*]], [[BB:%.*]] ], [ -2, [[ENTRY:%.*]] ]
56 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[BB]] ], [ [[TMP0]], [[ENTRY]] ]
57 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add i64 [[LSR_IV]], -1
58 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add i64 [[LSR_IV1]], 2
59 ; CHECK-NEXT: [[C0:%.*]] = icmp eq i64 [[LSR_IV_NEXT]], 0
60 ; CHECK-NEXT: br i1 [[C0]], label [[BB13:%.*]], label [[BB]]
62 ; CHECK-NEXT: [[T:%.*]] = load ptr addrspace(1), ptr addrspace(1) undef, align 8
63 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr addrspace(1) [[T]], i64 [[LSR_IV_NEXT2]]
64 ; CHECK-NEXT: [[C1:%.*]] = icmp ne ptr addrspace(1) [[SCEVGEP]], null
65 ; CHECK-NEXT: br i1 [[C1]], label [[BB11]], label [[BB13]]
67 ; CHECK-NEXT: unreachable
72 bb11: ; preds = %bb, %entry
73 %i = phi i64 [ 0, %entry ], [ %i.next, %bb ]
75 %c0 = icmp eq i64 %i, %arg0
76 br i1 %c0, label %bb13, label %bb
79 %t = load ptr addrspace(1), ptr addrspace(1) undef, align 8
80 %p = getelementptr i8, ptr addrspace(1) %t, i64 %ii
81 %c1 = icmp ne ptr addrspace(1) %p, null
82 %i.next = add i64 %i, 1
83 br i1 %c1, label %bb11, label %bb13
85 bb13: ; preds = %bb, %bb11
89 define amdgpu_kernel void @global_gep_user(i32 %arg0) nounwind {
90 ; CHECK-LABEL: @global_gep_user(
92 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG0:%.*]], 1
93 ; CHECK-NEXT: br label [[BB11:%.*]]
95 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i32 [ [[LSR_IV_NEXT2:%.*]], [[BB:%.*]] ], [ 0, [[ENTRY:%.*]] ]
96 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[BB]] ], [ [[TMP0]], [[ENTRY]] ]
97 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add i32 [[LSR_IV]], -1
98 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add i32 [[LSR_IV1]], 2
99 ; CHECK-NEXT: [[C0:%.*]] = icmp eq i32 [[LSR_IV_NEXT]], 0
100 ; CHECK-NEXT: br i1 [[C0]], label [[BB13:%.*]], label [[BB]]
102 ; CHECK-NEXT: [[T:%.*]] = load ptr addrspace(1), ptr addrspace(1) undef, align 8
103 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[LSR_IV1]] to i64
104 ; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr addrspace(1) [[T]], i64 [[IDXPROM]]
105 ; CHECK-NEXT: [[C1:%.*]] = icmp ne ptr addrspace(1) [[P]], null
106 ; CHECK-NEXT: br i1 [[C1]], label [[BB11]], label [[BB13]]
108 ; CHECK-NEXT: unreachable
113 bb11: ; preds = %bb, %entry
114 %i = phi i32 [ 0, %entry ], [ %i.next, %bb ]
116 %c0 = icmp eq i32 %i, %arg0
117 br i1 %c0, label %bb13, label %bb
120 %t = load ptr addrspace(1), ptr addrspace(1) undef, align 8
121 %idxprom = sext i32 %ii to i64
122 %p = getelementptr i8, ptr addrspace(1) %t, i64 %idxprom
123 %c1 = icmp ne ptr addrspace(1) %p, null
124 %i.next = add i32 %i, 1
125 br i1 %c1, label %bb11, label %bb13
127 bb13: ; preds = %bb, %bb11
131 define amdgpu_kernel void @global_sext_scale_user(i32 %arg0) nounwind {
132 ; CHECK-LABEL: @global_sext_scale_user(
134 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG0:%.*]], 1
135 ; CHECK-NEXT: br label [[BB11:%.*]]
137 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i32 [ [[LSR_IV_NEXT2:%.*]], [[BB:%.*]] ], [ 0, [[ENTRY:%.*]] ]
138 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[BB]] ], [ [[TMP0]], [[ENTRY]] ]
139 ; CHECK-NEXT: [[II_EXT:%.*]] = sext i32 [[LSR_IV1]] to i64
140 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add i32 [[LSR_IV]], -1
141 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add i32 [[LSR_IV1]], 2
142 ; CHECK-NEXT: [[C0:%.*]] = icmp eq i32 [[LSR_IV_NEXT]], 0
143 ; CHECK-NEXT: br i1 [[C0]], label [[BB13:%.*]], label [[BB]]
145 ; CHECK-NEXT: [[T:%.*]] = load ptr addrspace(1), ptr addrspace(1) undef, align 8
146 ; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr addrspace(1) [[T]], i64 [[II_EXT]]
147 ; CHECK-NEXT: [[C1:%.*]] = icmp ne ptr addrspace(1) [[P]], null
148 ; CHECK-NEXT: br i1 [[C1]], label [[BB11]], label [[BB13]]
150 ; CHECK-NEXT: unreachable
155 bb11: ; preds = %bb, %entry
156 %i = phi i32 [ 0, %entry ], [ %i.next, %bb ]
158 %ii.ext = sext i32 %ii to i64
159 %c0 = icmp eq i32 %i, %arg0
160 br i1 %c0, label %bb13, label %bb
163 %t = load ptr addrspace(1), ptr addrspace(1) undef, align 8
164 %p = getelementptr i8, ptr addrspace(1) %t, i64 %ii.ext
165 %c1 = icmp ne ptr addrspace(1) %p, null
166 %i.next = add i32 %i, 1
167 br i1 %c1, label %bb11, label %bb13
169 bb13: ; preds = %bb, %bb11