Sanjay Patel | b653de1 | 2014-09-10 17:58:16 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -march=r600 -mcpu=cayman -basicaa -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine < %s | FileCheck %s |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 2 | |
| 3 | ; Check vectorization that would ordinarily require a runtime bounds |
| 4 | ; check on the pointers when mixing address spaces. For now we cannot |
| 5 | ; assume address spaces do not alias, and we can't assume that |
| 6 | ; different pointers are directly comparable. |
| 7 | ; |
| 8 | ; These all test this basic loop for different combinations of address |
| 9 | ; spaces, and swapping in globals or adding noalias. |
| 10 | ; |
| 11 | ;void foo(int addrspace(N)* [noalias] a, int addrspace(M)* [noalias] b, int n) |
| 12 | ;{ |
| 13 | ; for (int i = 0; i < n; ++i) |
| 14 | ; { |
| 15 | ; a[i] = 3 * b[i]; |
| 16 | ; } |
| 17 | ;} |
| 18 | |
| 19 | ; Artificial datalayout |
| 20 | target datalayout = "e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-v2048:2048:2048-n32:64" |
| 21 | |
| 22 | |
| 23 | @g_as1 = common addrspace(1) global [1024 x i32] zeroinitializer, align 16 |
| 24 | @q_as2 = common addrspace(2) global [1024 x i32] zeroinitializer, align 16 |
| 25 | |
| 26 | ; Both parameters are unidentified objects with the same address |
| 27 | ; space, so this should vectorize normally. |
| 28 | define void @foo(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 %n) #0 { |
| 29 | ; CHECK-LABEL: @foo( |
| 30 | ; CHECK: <4 x i32> |
| 31 | ; CHECK: ret |
| 32 | |
| 33 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 34 | %cmp1 = icmp slt i32 0, %n |
| 35 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 36 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 37 | for.body: ; preds = %entry, %for.body |
| 38 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 39 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 40 | %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 41 | %0 = load i32, i32 addrspace(1)* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 42 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 43 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 44 | %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 45 | store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 46 | %inc = add nsw i32 %i.02, 1 |
| 47 | %cmp = icmp slt i32 %inc, %n |
| 48 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 49 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 50 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 51 | ret void |
| 52 | } |
| 53 | |
| 54 | ; Parameters are unidentified and different address spaces, so cannot vectorize. |
| 55 | define void @bar0(i32* %a, i32 addrspace(1)* %b, i32 %n) #0 { |
| 56 | ; CHECK-LABEL: @bar0( |
| 57 | ; CHECK-NOT: <4 x i32> |
| 58 | ; CHECK: ret |
| 59 | |
| 60 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 61 | %cmp1 = icmp slt i32 0, %n |
| 62 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 63 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 64 | for.body: ; preds = %entry, %for.body |
| 65 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 66 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 67 | %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 68 | %0 = load i32, i32 addrspace(1)* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 69 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 70 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 71 | %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 72 | store i32 %mul, i32* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 73 | %inc = add nsw i32 %i.02, 1 |
| 74 | %cmp = icmp slt i32 %inc, %n |
| 75 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 76 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 77 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 78 | ret void |
| 79 | } |
| 80 | |
| 81 | ; Swapped arguments should be the same |
| 82 | define void @bar1(i32 addrspace(1)* %a, i32* %b, i32 %n) #0 { |
| 83 | ; CHECK-LABEL: @bar1( |
| 84 | ; CHECK-NOT: <4 x i32> |
| 85 | ; CHECK: ret |
| 86 | |
| 87 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 88 | %cmp1 = icmp slt i32 0, %n |
| 89 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 90 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 91 | for.body: ; preds = %entry, %for.body |
| 92 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 93 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 94 | %arrayidx = getelementptr inbounds i32, i32* %b, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 95 | %0 = load i32, i32* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 96 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 97 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 98 | %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 99 | store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 100 | %inc = add nsw i32 %i.02, 1 |
| 101 | %cmp = icmp slt i32 %inc, %n |
| 102 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 103 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 104 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 105 | ret void |
| 106 | } |
| 107 | |
| 108 | ; We should still be able to vectorize with noalias even if the |
| 109 | ; address spaces are different. |
| 110 | define void @bar2(i32* noalias %a, i32 addrspace(1)* noalias %b, i32 %n) #0 { |
| 111 | ; CHECK-LABEL: @bar2( |
| 112 | ; CHECK: <4 x i32> |
| 113 | ; CHECK: ret |
| 114 | |
| 115 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 116 | %cmp1 = icmp slt i32 0, %n |
| 117 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 118 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 119 | for.body: ; preds = %entry, %for.body |
| 120 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 121 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 122 | %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 123 | %0 = load i32, i32 addrspace(1)* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 124 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 125 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 126 | %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 127 | store i32 %mul, i32* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 128 | %inc = add nsw i32 %i.02, 1 |
| 129 | %cmp = icmp slt i32 %inc, %n |
| 130 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 131 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 132 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 133 | ret void |
| 134 | } |
| 135 | |
| 136 | ; Store to identified global with different address space. This isn't |
| 137 | ; generally safe and shouldn't be vectorized. |
| 138 | define void @arst0(i32* %b, i32 %n) #0 { |
| 139 | ; CHECK-LABEL: @arst0( |
| 140 | ; CHECK-NOT: <4 x i32> |
| 141 | ; CHECK: ret |
| 142 | |
| 143 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 144 | %cmp1 = icmp slt i32 0, %n |
| 145 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 146 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 147 | for.body: ; preds = %entry, %for.body |
| 148 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 149 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 150 | %arrayidx = getelementptr inbounds i32, i32* %b, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 151 | %0 = load i32, i32* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 152 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 153 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 154 | %arrayidx2 = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 155 | store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 156 | %inc = add nsw i32 %i.02, 1 |
| 157 | %cmp = icmp slt i32 %inc, %n |
| 158 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 159 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 160 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 161 | ret void |
| 162 | } |
| 163 | |
| 164 | |
| 165 | ; Load from identified global with different address space. |
| 166 | ; This isn't generally safe and shouldn't be vectorized. |
| 167 | define void @arst1(i32* %b, i32 %n) #0 { |
| 168 | ; CHECK-LABEL: @arst1( |
| 169 | ; CHECK-NOT: <4 x i32> |
| 170 | ; CHECK: ret |
| 171 | |
| 172 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 173 | %cmp1 = icmp slt i32 0, %n |
| 174 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 175 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 176 | for.body: ; preds = %entry, %for.body |
| 177 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 178 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 179 | %arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 180 | %0 = load i32, i32 addrspace(1)* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 181 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 182 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 183 | %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 184 | store i32 %mul, i32* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 185 | %inc = add nsw i32 %i.02, 1 |
| 186 | %cmp = icmp slt i32 %inc, %n |
| 187 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 188 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 189 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 190 | ret void |
| 191 | } |
| 192 | |
| 193 | ; Read and write to 2 identified globals in different address |
| 194 | ; spaces. This should be vectorized. |
| 195 | define void @aoeu(i32 %n) #0 { |
| 196 | ; CHECK-LABEL: @aoeu( |
| 197 | ; CHECK: <4 x i32> |
| 198 | ; CHECK: ret |
| 199 | |
| 200 | entry: |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 201 | %cmp1 = icmp slt i32 0, %n |
| 202 | br i1 %cmp1, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 203 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 204 | for.body: ; preds = %entry, %for.body |
| 205 | %i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 206 | %idxprom = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 207 | %arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(2)* @q_as2, i64 0, i64 %idxprom |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame^] | 208 | %0 = load i32, i32 addrspace(2)* %arrayidx, align 4 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 209 | %mul = mul nsw i32 %0, 3 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 210 | %idxprom1 = sext i32 %i.02 to i64 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 211 | %arrayidx2 = getelementptr inbounds [1024 x i32], [1024 x i32] addrspace(1)* @g_as1, i64 0, i64 %idxprom1 |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 212 | store i32 %mul, i32 addrspace(1)* %arrayidx2, align 4 |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 213 | %inc = add nsw i32 %i.02, 1 |
| 214 | %cmp = icmp slt i32 %inc, %n |
| 215 | br i1 %cmp, label %for.body, label %for.end |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 216 | |
Michael Zolotukhin | 540580c | 2014-12-02 22:59:02 +0000 | [diff] [blame] | 217 | for.end: ; preds = %for.body, %entry |
Matt Arsenault | 0be1cb1 | 2013-10-02 22:38:17 +0000 | [diff] [blame] | 218 | ret void |
| 219 | } |
| 220 | |
| 221 | attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |