|
| 1 | +; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S < %s | FileCheck %s --check-prefix=CHECK |
| 2 | +; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=4 -S < %s | FileCheck %s --check-prefix=CHECK |
| 3 | +; RUN: opt -passes=loop-vectorize -force-vector-interleave=4 -force-vector-width=1 -S < %s | FileCheck %s --check-prefix=CHECK |
| 4 | + |
| 5 | +define i64 @select_icmp_const_1(ptr nocapture readonly %a, i64 %n) { |
| 6 | +; CHECK-LABEL: define i64 @select_icmp_const_1 |
| 7 | +; CHECK-NOT: vector.body: |
| 8 | +; |
| 9 | +entry: |
| 10 | + br label %for.body |
| 11 | + |
| 12 | +for.body: ; preds = %entry, %for.body |
| 13 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 14 | + %rdx = phi i64 [ %cond, %for.body ], [ 3, %entry ] |
| 15 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 16 | + %0 = load i64, ptr %arrayidx, align 8 |
| 17 | + %cmp2 = icmp eq i64 %0, 3 |
| 18 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 19 | + %inc = add nuw nsw i64 %iv, 1 |
| 20 | + %exitcond.not = icmp eq i64 %inc, %n |
| 21 | + br i1 %exitcond.not, label %exit, label %for.body |
| 22 | + |
| 23 | +exit: ; preds = %for.body |
| 24 | + ret i64 %cond |
| 25 | +} |
| 26 | + |
| 27 | +define i64 @select_icmp_const_2(ptr nocapture readonly %a, i64 %n) { |
| 28 | +; CHECK-LABEL: define i64 @select_icmp_const_2 |
| 29 | +; CHECK-NOT: vector.body: |
| 30 | +; |
| 31 | +entry: |
| 32 | + br label %for.body |
| 33 | + |
| 34 | +for.body: ; preds = %entry, %for.body |
| 35 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 36 | + %rdx = phi i64 [ %cond, %for.body ], [ 3, %entry ] |
| 37 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 38 | + %0 = load i64, ptr %arrayidx, align 8 |
| 39 | + %cmp2 = icmp eq i64 %0, 3 |
| 40 | + %cond = select i1 %cmp2, i64 %rdx, i64 %iv |
| 41 | + %inc = add nuw nsw i64 %iv, 1 |
| 42 | + %exitcond.not = icmp eq i64 %inc, %n |
| 43 | + br i1 %exitcond.not, label %exit, label %for.body |
| 44 | + |
| 45 | +exit: ; preds = %for.body |
| 46 | + ret i64 %cond |
| 47 | +} |
| 48 | + |
| 49 | +define i64 @select_icmp_const_3_variable_rdx_start(ptr nocapture readonly %a, i64 %rdx.start, i64 %n) { |
| 50 | +; CHECK-LABEL: define i64 @select_icmp_const_3_variable_rdx_start |
| 51 | +; CHECK-NOT: vector.body: |
| 52 | +; |
| 53 | +entry: |
| 54 | + br label %for.body |
| 55 | + |
| 56 | +for.body: ; preds = %entry, %for.body |
| 57 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 58 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 59 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 60 | + %0 = load i64, ptr %arrayidx, align 8 |
| 61 | + %cmp2 = icmp eq i64 %0, 3 |
| 62 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 63 | + %inc = add nuw nsw i64 %iv, 1 |
| 64 | + %exitcond.not = icmp eq i64 %inc, %n |
| 65 | + br i1 %exitcond.not, label %exit, label %for.body |
| 66 | + |
| 67 | +exit: ; preds = %for.body |
| 68 | + ret i64 %cond |
| 69 | +} |
| 70 | + |
| 71 | +define i64 @select_fcmp_const_fast(ptr nocapture readonly %a, i64 %n) { |
| 72 | +; CHECK-LABEL: define i64 @select_fcmp_const_fast |
| 73 | +; CHECK-NOT: vector.body: |
| 74 | +; |
| 75 | +entry: |
| 76 | + br label %for.body |
| 77 | + |
| 78 | +for.body: ; preds = %entry, %for.body |
| 79 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 80 | + %rdx = phi i64 [ %cond, %for.body ], [ 2, %entry ] |
| 81 | + %arrayidx = getelementptr inbounds float, ptr %a, i64 %iv |
| 82 | + %0 = load float, ptr %arrayidx, align 4 |
| 83 | + %cmp2 = fcmp fast ueq float %0, 3.0 |
| 84 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 85 | + %inc = add nuw nsw i64 %iv, 1 |
| 86 | + %exitcond.not = icmp eq i64 %inc, %n |
| 87 | + br i1 %exitcond.not, label %exit, label %for.body |
| 88 | + |
| 89 | +exit: ; preds = %for.body |
| 90 | + ret i64 %cond |
| 91 | +} |
| 92 | + |
| 93 | +define i64 @select_fcmp_const(ptr nocapture readonly %a, i64 %n) { |
| 94 | +; CHECK-LABEL: define i64 @select_fcmp_const |
| 95 | +; CHECK-NOT: vector.body: |
| 96 | +; |
| 97 | +entry: |
| 98 | + br label %for.body |
| 99 | + |
| 100 | +for.body: ; preds = %entry, %for.body |
| 101 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 102 | + %rdx = phi i64 [ %cond, %for.body ], [ 2, %entry ] |
| 103 | + %arrayidx = getelementptr inbounds float, ptr %a, i64 %iv |
| 104 | + %0 = load float, ptr %arrayidx, align 4 |
| 105 | + %cmp2 = fcmp ueq float %0, 3.0 |
| 106 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 107 | + %inc = add nuw nsw i64 %iv, 1 |
| 108 | + %exitcond.not = icmp eq i64 %inc, %n |
| 109 | + br i1 %exitcond.not, label %exit, label %for.body |
| 110 | + |
| 111 | +exit: ; preds = %for.body |
| 112 | + ret i64 %cond |
| 113 | +} |
| 114 | + |
| 115 | +define i64 @select_icmp(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %rdx.start, i64 %n) { |
| 116 | +; CHECK-LABEL: define i64 @select_icmp |
| 117 | +; CHECK-NOT: vector.body: |
| 118 | +; |
| 119 | +entry: |
| 120 | + br label %for.body |
| 121 | + |
| 122 | +for.body: ; preds = %entry, %for.body |
| 123 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 124 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 125 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 126 | + %0 = load i64, ptr %arrayidx, align 8 |
| 127 | + %arrayidx1 = getelementptr inbounds i64, ptr %b, i64 %iv |
| 128 | + %1 = load i64, ptr %arrayidx1, align 8 |
| 129 | + %cmp2 = icmp sgt i64 %0, %1 |
| 130 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 131 | + %inc = add nuw nsw i64 %iv, 1 |
| 132 | + %exitcond.not = icmp eq i64 %inc, %n |
| 133 | + br i1 %exitcond.not, label %exit, label %for.body |
| 134 | + |
| 135 | +exit: ; preds = %for.body |
| 136 | + ret i64 %cond |
| 137 | +} |
| 138 | + |
| 139 | +define i64 @select_fcmp(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %rdx.start, i64 %n) { |
| 140 | +; CHECK-LABEL: define i64 @select_fcmp |
| 141 | +; CHECK-NOT: vector.body: |
| 142 | +; |
| 143 | +entry: |
| 144 | + br label %for.body |
| 145 | + |
| 146 | +for.body: ; preds = %entry, %for.body |
| 147 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 148 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 149 | + %arrayidx = getelementptr inbounds float, ptr %a, i64 %iv |
| 150 | + %0 = load float, ptr %arrayidx, align 4 |
| 151 | + %arrayidx1 = getelementptr inbounds float, ptr %b, i64 %iv |
| 152 | + %1 = load float, ptr %arrayidx1, align 4 |
| 153 | + %cmp2 = fcmp ogt float %0, %1 |
| 154 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 155 | + %inc = add nuw nsw i64 %iv, 1 |
| 156 | + %exitcond.not = icmp eq i64 %inc, %n |
| 157 | + br i1 %exitcond.not, label %exit, label %for.body |
| 158 | + |
| 159 | +exit: ; preds = %for.body |
| 160 | + ret i64 %cond |
| 161 | +} |
| 162 | + |
| 163 | +define i64 @select_icmp_min_valid_iv_start(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %rdx.start, i64 %n) { |
| 164 | +; CHECK-LABEL: define i64 @select_icmp_min_valid_iv_start |
| 165 | +; CHECK-NOT: vector.body: |
| 166 | +; |
| 167 | +entry: |
| 168 | + br label %for.body |
| 169 | + |
| 170 | +for.body: ; preds = %entry, %for.body |
| 171 | + %iv.j = phi i64 [ %inc3, %for.body ], [ -9223372036854775807, %entry] |
| 172 | + %iv.i = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 173 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 174 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv.i |
| 175 | + %0 = load i64, ptr %arrayidx, align 8 |
| 176 | + %arrayidx1 = getelementptr inbounds i64, ptr %b, i64 %iv.i |
| 177 | + %1 = load i64, ptr %arrayidx1, align 8 |
| 178 | + %cmp2 = icmp sgt i64 %0, %1 |
| 179 | + %cond = select i1 %cmp2, i64 %iv.j, i64 %rdx |
| 180 | + %inc = add nuw nsw i64 %iv.i, 1 |
| 181 | + %inc3 = add nsw i64 %iv.j, 1 |
| 182 | + %exitcond.not = icmp eq i64 %inc, %n |
| 183 | + br i1 %exitcond.not, label %exit, label %for.body |
| 184 | + |
| 185 | +exit: ; preds = %for.body |
| 186 | + ret i64 %cond |
| 187 | +} |
| 188 | + |
| 189 | +; Negative tests |
| 190 | + |
| 191 | +define float @not_vectorized_select_float_induction_icmp(ptr nocapture readonly %a, ptr nocapture readonly %b, float %rdx.start, i64 %n) { |
| 192 | +; CHECK-LABEL: @not_vectorized_select_float_induction_icmp |
| 193 | +; CHECK-NOT: vector.body: |
| 194 | +; |
| 195 | +entry: |
| 196 | + br label %for.body |
| 197 | + |
| 198 | +for.body: ; preds = %entry, %for.body |
| 199 | + %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 200 | + %fiv = phi float [ %conv3, %for.body ], [ 0.000000e+00, %entry ] |
| 201 | + %rdx = phi float [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 202 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 203 | + %0 = load i64, ptr %arrayidx, align 8 |
| 204 | + %arrayidx1 = getelementptr inbounds i64, ptr %b, i64 %iv |
| 205 | + %1 = load i64, ptr %arrayidx1, align 8 |
| 206 | + %cmp2 = icmp sgt i64 %0, %1 |
| 207 | + %cond = select i1 %cmp2, float %fiv, float %rdx |
| 208 | + %conv3 = fadd float %fiv, 1.000000e+00 |
| 209 | + %inc = add nuw nsw i64 %iv, 1 |
| 210 | + %exitcond.not = icmp eq i64 %inc, %n |
| 211 | + br i1 %exitcond.not, label %exit, label %for.body |
| 212 | + |
| 213 | +exit: ; preds = %for.body |
| 214 | + ret float %cond |
| 215 | +} |
| 216 | + |
| 217 | +define i64 @not_vectorized_select_decreasing_induction_icmp(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %rdx.start, i64 %n) { |
| 218 | +; CHECK-LABEL: @not_vectorized_select_decreasing_induction_icmp |
| 219 | +; CHECK-NOT: vector.body: |
| 220 | +; |
| 221 | +entry: |
| 222 | + br label %for.body |
| 223 | + |
| 224 | +for.body: ; preds = %entry, %for.body |
| 225 | + %i.0.in10 = phi i64 [ %iv, %for.body ], [ %n, %entry ] |
| 226 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 227 | + %iv = add nsw i64 %i.0.in10, -1 |
| 228 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 229 | + %0 = load i64, ptr %arrayidx, align 8 |
| 230 | + %arrayidx1 = getelementptr inbounds i64, ptr %b, i64 %iv |
| 231 | + %1 = load i64, ptr %arrayidx1, align 8 |
| 232 | + %cmp2 = icmp sgt i64 %0, %1 |
| 233 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 234 | + %cmp = icmp ugt i64 %i.0.in10, 1 |
| 235 | + br i1 %cmp, label %for.body, label %exit |
| 236 | + |
| 237 | +exit: ; preds = %for.body |
| 238 | + ret i64 %cond |
| 239 | +} |
| 240 | + |
| 241 | +define i64 @not_vectorized_select_icmp_iv_out_of_bound(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %rdx.start, i64 %n) { |
| 242 | +; CHECK-LABEL: @not_vectorized_select_icmp_iv_out_of_bound |
| 243 | +; CHECK-NOT: vector.body: |
| 244 | +; |
| 245 | +entry: |
| 246 | + br label %for.body |
| 247 | + |
| 248 | +for.body: ; preds = %entry, %for.body |
| 249 | + %iv.j = phi i64 [ %inc3, %for.body ], [ -9223372036854775808, %entry] |
| 250 | + %iv.i = phi i64 [ %inc, %for.body ], [ 0, %entry ] |
| 251 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 252 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv.i |
| 253 | + %0 = load i64, ptr %arrayidx, align 8 |
| 254 | + %arrayidx1 = getelementptr inbounds i64, ptr %b, i64 %iv.i |
| 255 | + %1 = load i64, ptr %arrayidx1, align 8 |
| 256 | + %cmp2 = icmp sgt i64 %0, %1 |
| 257 | + %cond = select i1 %cmp2, i64 %iv.j, i64 %rdx |
| 258 | + %inc = add nuw nsw i64 %iv.i, 1 |
| 259 | + %inc3 = add nsw i64 %iv.j, 1 |
| 260 | + %exitcond.not = icmp eq i64 %inc, %n |
| 261 | + br i1 %exitcond.not, label %exit, label %for.body |
| 262 | + |
| 263 | +exit: ; preds = %for.body |
| 264 | + ret i64 %cond |
| 265 | +} |
| 266 | + |
| 267 | +define i64 @not_vectorized_select_icmp_non_const_iv_start_value(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %ivstart, i64 %rdx.start, i64 %n) { |
| 268 | +; CHECK-LABEL: define i64 @not_vectorized_select_icmp_non_const_iv_start_value |
| 269 | +; CHECK-NOT: vector.body: |
| 270 | +; |
| 271 | +entry: |
| 272 | + br label %for.body |
| 273 | + |
| 274 | +for.body: ; preds = %entry, %for.body |
| 275 | + %iv = phi i64 [ %inc, %for.body ], [ %ivstart, %entry ] |
| 276 | + %rdx = phi i64 [ %cond, %for.body ], [ %rdx.start, %entry ] |
| 277 | + %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv |
| 278 | + %0 = load i64, ptr %arrayidx, align 8 |
| 279 | + %arrayidx1 = getelementptr inbounds i64, ptr %b, i64 %iv |
| 280 | + %1 = load i64, ptr %arrayidx1, align 8 |
| 281 | + %cmp2 = icmp sgt i64 %0, %1 |
| 282 | + %cond = select i1 %cmp2, i64 %iv, i64 %rdx |
| 283 | + %inc = add nuw nsw i64 %iv, 1 |
| 284 | + %exitcond.not = icmp eq i64 %inc, %n |
| 285 | + br i1 %exitcond.not, label %exit, label %for.body |
| 286 | + |
| 287 | +exit: ; preds = %for.body |
| 288 | + ret i64 %cond |
| 289 | +} |
0 commit comments