1; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -fixup-byte-word-insts=1 < %s | FileCheck -check-prefix=CHECK -check-prefix=BWON %s 2; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -fixup-byte-word-insts=0 < %s | FileCheck -check-prefix=CHECK -check-prefix=BWOFF %s 3; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx -addr-sink-using-gep=1 < %s | FileCheck %s 4 5%struct.A = type { i8, i8, i8, i8, i8, i8, i8, i8 } 6%struct.B = type { i32, i32, i32, i32, i32, i32, i32, i32 } 7 8; CHECK-LABEL: merge_const_store: 9; save 1,2,3 ... as one big integer. 10; CHECK: movabsq $578437695752307201 11; CHECK: ret 12define void @merge_const_store(i32 %count, %struct.A* nocapture %p) nounwind uwtable noinline ssp { 13 %1 = icmp sgt i32 %count, 0 14 br i1 %1, label %.lr.ph, label %._crit_edge 15.lr.ph: 16 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] 17 %.01 = phi %struct.A* [ %11, %.lr.ph ], [ %p, %0 ] 18 %2 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0 19 store i8 1, i8* %2, align 1 20 %3 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1 21 store i8 2, i8* %3, align 1 22 %4 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 2 23 store i8 3, i8* %4, align 1 24 %5 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 3 25 store i8 4, i8* %5, align 1 26 %6 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 4 27 store i8 5, i8* %6, align 1 28 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 5 29 store i8 6, i8* %7, align 1 30 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 6 31 store i8 7, i8* %8, align 1 32 %9 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 7 33 store i8 8, i8* %9, align 1 34 %10 = add nsw i32 %i.02, 1 35 %11 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1 36 %exitcond = icmp eq i32 %10, %count 37 br i1 %exitcond, label %._crit_edge, label %.lr.ph 38._crit_edge: 39 ret void 40} 41 42; No vectors because we use noimplicitfloat 43; CHECK-LABEL: merge_const_store_no_vec: 44; CHECK-NOT: vmovups 45; CHECK: ret 46define void @merge_const_store_no_vec(i32 %count, %struct.B* nocapture %p) noimplicitfloat{ 47 %1 = icmp sgt i32 %count, 0 48 br i1 %1, label %.lr.ph, label %._crit_edge 49.lr.ph: 50 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] 51 %.01 = phi %struct.B* [ %11, %.lr.ph ], [ %p, %0 ] 52 %2 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 53 store i32 0, i32* %2, align 4 54 %3 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 55 store i32 0, i32* %3, align 4 56 %4 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2 57 store i32 0, i32* %4, align 4 58 %5 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3 59 store i32 0, i32* %5, align 4 60 %6 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 4 61 store i32 0, i32* %6, align 4 62 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 5 63 store i32 0, i32* %7, align 4 64 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 6 65 store i32 0, i32* %8, align 4 66 %9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 7 67 store i32 0, i32* %9, align 4 68 %10 = add nsw i32 %i.02, 1 69 %11 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 70 %exitcond = icmp eq i32 %10, %count 71 br i1 %exitcond, label %._crit_edge, label %.lr.ph 72._crit_edge: 73 ret void 74} 75 76; Move the constants using a single vector store. 77; CHECK-LABEL: merge_const_store_vec: 78; CHECK: vmovups 79; CHECK: ret 80define void @merge_const_store_vec(i32 %count, %struct.B* nocapture %p) nounwind uwtable noinline ssp { 81 %1 = icmp sgt i32 %count, 0 82 br i1 %1, label %.lr.ph, label %._crit_edge 83.lr.ph: 84 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] 85 %.01 = phi %struct.B* [ %11, %.lr.ph ], [ %p, %0 ] 86 %2 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 87 store i32 0, i32* %2, align 4 88 %3 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 89 store i32 0, i32* %3, align 4 90 %4 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2 91 store i32 0, i32* %4, align 4 92 %5 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3 93 store i32 0, i32* %5, align 4 94 %6 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 4 95 store i32 0, i32* %6, align 4 96 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 5 97 store i32 0, i32* %7, align 4 98 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 6 99 store i32 0, i32* %8, align 4 100 %9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 7 101 store i32 0, i32* %9, align 4 102 %10 = add nsw i32 %i.02, 1 103 %11 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 104 %exitcond = icmp eq i32 %10, %count 105 br i1 %exitcond, label %._crit_edge, label %.lr.ph 106._crit_edge: 107 ret void 108} 109 110; Move the first 4 constants as a single vector. Move the rest as scalars. 111; CHECK-LABEL: merge_nonconst_store: 112; CHECK: movl $67305985 113; CHECK: movb 114; CHECK: movb 115; CHECK: movb 116; CHECK: movb 117; CHECK: ret 118define void @merge_nonconst_store(i32 %count, i8 %zz, %struct.A* nocapture %p) nounwind uwtable noinline ssp { 119 %1 = icmp sgt i32 %count, 0 120 br i1 %1, label %.lr.ph, label %._crit_edge 121.lr.ph: 122 %i.02 = phi i32 [ %10, %.lr.ph ], [ 0, %0 ] 123 %.01 = phi %struct.A* [ %11, %.lr.ph ], [ %p, %0 ] 124 %2 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0 125 store i8 1, i8* %2, align 1 126 %3 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1 127 store i8 2, i8* %3, align 1 128 %4 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 2 129 store i8 3, i8* %4, align 1 130 %5 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 3 131 store i8 4, i8* %5, align 1 132 %6 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 4 133 store i8 %zz, i8* %6, align 1 ; <----------- Not a const; 134 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 5 135 store i8 6, i8* %7, align 1 136 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 6 137 store i8 7, i8* %8, align 1 138 %9 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 7 139 store i8 8, i8* %9, align 1 140 %10 = add nsw i32 %i.02, 1 141 %11 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1 142 %exitcond = icmp eq i32 %10, %count 143 br i1 %exitcond, label %._crit_edge, label %.lr.ph 144._crit_edge: 145 ret void 146} 147 148 149; CHECK-LABEL: merge_loads_i16: 150; load: 151; BWON: movzwl 152; BWOFF: movw 153; store: 154; CHECK: movw 155; CHECK: ret 156define void @merge_loads_i16(i32 %count, %struct.A* noalias nocapture %q, %struct.A* noalias nocapture %p) nounwind uwtable noinline ssp { 157 %1 = icmp sgt i32 %count, 0 158 br i1 %1, label %.lr.ph, label %._crit_edge 159 160.lr.ph: ; preds = %0 161 %2 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 0 162 %3 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 1 163 br label %4 164 165; <label>:4 ; preds = %4, %.lr.ph 166 %i.02 = phi i32 [ 0, %.lr.ph ], [ %9, %4 ] 167 %.01 = phi %struct.A* [ %p, %.lr.ph ], [ %10, %4 ] 168 %5 = load i8, i8* %2, align 1 169 %6 = load i8, i8* %3, align 1 170 %7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0 171 store i8 %5, i8* %7, align 1 172 %8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1 173 store i8 %6, i8* %8, align 1 174 %9 = add nsw i32 %i.02, 1 175 %10 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1 176 %exitcond = icmp eq i32 %9, %count 177 br i1 %exitcond, label %._crit_edge, label %4 178 179._crit_edge: ; preds = %4, %0 180 ret void 181} 182 183; The loads and the stores are interleaved. Can't merge them. 184; CHECK-LABEL: no_merge_loads: 185; BWON: movzbl 186; BWOFF: movb 187; CHECK: movb 188; CHECK: movb 189; CHECK: movb 190; CHECK: ret 191define void @no_merge_loads(i32 %count, %struct.A* noalias nocapture %q, %struct.A* noalias nocapture %p) nounwind uwtable noinline ssp { 192 %1 = icmp sgt i32 %count, 0 193 br i1 %1, label %.lr.ph, label %._crit_edge 194 195.lr.ph: ; preds = %0 196 %2 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 0 197 %3 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 1 198 br label %a4 199 200a4: ; preds = %4, %.lr.ph 201 %i.02 = phi i32 [ 0, %.lr.ph ], [ %a9, %a4 ] 202 %.01 = phi %struct.A* [ %p, %.lr.ph ], [ %a10, %a4 ] 203 %a5 = load i8, i8* %2, align 1 204 %a7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0 205 store i8 %a5, i8* %a7, align 1 206 %a8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1 207 %a6 = load i8, i8* %3, align 1 208 store i8 %a6, i8* %a8, align 1 209 %a9 = add nsw i32 %i.02, 1 210 %a10 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1 211 %exitcond = icmp eq i32 %a9, %count 212 br i1 %exitcond, label %._crit_edge, label %a4 213 214._crit_edge: ; preds = %4, %0 215 ret void 216} 217 218 219; CHECK-LABEL: merge_loads_integer: 220; load: 221; CHECK: movq 222; store: 223; CHECK: movq 224; CHECK: ret 225define void @merge_loads_integer(i32 %count, %struct.B* noalias nocapture %q, %struct.B* noalias nocapture %p) nounwind uwtable noinline ssp { 226 %1 = icmp sgt i32 %count, 0 227 br i1 %1, label %.lr.ph, label %._crit_edge 228 229.lr.ph: ; preds = %0 230 %2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0 231 %3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1 232 br label %4 233 234; <label>:4 ; preds = %4, %.lr.ph 235 %i.02 = phi i32 [ 0, %.lr.ph ], [ %9, %4 ] 236 %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %10, %4 ] 237 %5 = load i32, i32* %2 238 %6 = load i32, i32* %3 239 %7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 240 store i32 %5, i32* %7 241 %8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 242 store i32 %6, i32* %8 243 %9 = add nsw i32 %i.02, 1 244 %10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 245 %exitcond = icmp eq i32 %9, %count 246 br i1 %exitcond, label %._crit_edge, label %4 247 248._crit_edge: ; preds = %4, %0 249 ret void 250} 251 252 253; CHECK-LABEL: merge_loads_vector: 254; load: 255; CHECK: movups 256; store: 257; CHECK: movups 258; CHECK: ret 259define void @merge_loads_vector(i32 %count, %struct.B* noalias nocapture %q, %struct.B* noalias nocapture %p) nounwind uwtable noinline ssp { 260 %a1 = icmp sgt i32 %count, 0 261 br i1 %a1, label %.lr.ph, label %._crit_edge 262 263.lr.ph: ; preds = %0 264 %a2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0 265 %a3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1 266 %a4 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 2 267 %a5 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 3 268 br label %block4 269 270block4: ; preds = %4, %.lr.ph 271 %i.02 = phi i32 [ 0, %.lr.ph ], [ %c9, %block4 ] 272 %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %c10, %block4 ] 273 %a7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 274 %a8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 275 %a9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2 276 %a10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3 277 %b1 = load i32, i32* %a2 278 %b2 = load i32, i32* %a3 279 %b3 = load i32, i32* %a4 280 %b4 = load i32, i32* %a5 281 store i32 %b1, i32* %a7 282 store i32 %b2, i32* %a8 283 store i32 %b3, i32* %a9 284 store i32 %b4, i32* %a10 285 %c9 = add nsw i32 %i.02, 1 286 %c10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 287 %exitcond = icmp eq i32 %c9, %count 288 br i1 %exitcond, label %._crit_edge, label %block4 289 290._crit_edge: ; preds = %4, %0 291 ret void 292} 293 294;; On x86, even unaligned copies should be merged to vector ops. 295;; TODO: however, this cannot happen at the moment, due to brokenness 296;; in MergeConsecutiveStores. See UseAA FIXME in DAGCombiner.cpp 297;; visitSTORE. 298 299; CHECK-LABEL: merge_loads_no_align: 300; load: 301; CHECK-NOT: vmovups ;; TODO 302; store: 303; CHECK-NOT: vmovups ;; TODO 304; CHECK: ret 305define void @merge_loads_no_align(i32 %count, %struct.B* noalias nocapture %q, %struct.B* noalias nocapture %p) nounwind uwtable noinline ssp { 306 %a1 = icmp sgt i32 %count, 0 307 br i1 %a1, label %.lr.ph, label %._crit_edge 308 309.lr.ph: ; preds = %0 310 %a2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0 311 %a3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1 312 %a4 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 2 313 %a5 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 3 314 br label %block4 315 316block4: ; preds = %4, %.lr.ph 317 %i.02 = phi i32 [ 0, %.lr.ph ], [ %c9, %block4 ] 318 %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %c10, %block4 ] 319 %a7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0 320 %a8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1 321 %a9 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 2 322 %a10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 3 323 %b1 = load i32, i32* %a2, align 1 324 %b2 = load i32, i32* %a3, align 1 325 %b3 = load i32, i32* %a4, align 1 326 %b4 = load i32, i32* %a5, align 1 327 store i32 %b1, i32* %a7, align 1 328 store i32 %b2, i32* %a8, align 1 329 store i32 %b3, i32* %a9, align 1 330 store i32 %b4, i32* %a10, align 1 331 %c9 = add nsw i32 %i.02, 1 332 %c10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1 333 %exitcond = icmp eq i32 %c9, %count 334 br i1 %exitcond, label %._crit_edge, label %block4 335 336._crit_edge: ; preds = %4, %0 337 ret void 338} 339 340; Make sure that we merge the consecutive load/store sequence below and use a 341; word (16 bit) instead of a byte copy. 342; CHECK-LABEL: MergeLoadStoreBaseIndexOffset: 343; CHECK: movw (%{{.*}},%{{.*}}), [[REG:%[a-z]+]] 344; CHECK: movw [[REG]], (%{{.*}}) 345define void @MergeLoadStoreBaseIndexOffset(i64* %a, i8* %b, i8* %c, i32 %n) { 346 br label %1 347 348; <label>:1 349 %.09 = phi i32 [ %n, %0 ], [ %11, %1 ] 350 %.08 = phi i8* [ %b, %0 ], [ %10, %1 ] 351 %.0 = phi i64* [ %a, %0 ], [ %2, %1 ] 352 %2 = getelementptr inbounds i64, i64* %.0, i64 1 353 %3 = load i64, i64* %.0, align 1 354 %4 = getelementptr inbounds i8, i8* %c, i64 %3 355 %5 = load i8, i8* %4, align 1 356 %6 = add i64 %3, 1 357 %7 = getelementptr inbounds i8, i8* %c, i64 %6 358 %8 = load i8, i8* %7, align 1 359 store i8 %5, i8* %.08, align 1 360 %9 = getelementptr inbounds i8, i8* %.08, i64 1 361 store i8 %8, i8* %9, align 1 362 %10 = getelementptr inbounds i8, i8* %.08, i64 2 363 %11 = add nsw i32 %.09, -1 364 %12 = icmp eq i32 %11, 0 365 br i1 %12, label %13, label %1 366 367; <label>:13 368 ret void 369} 370 371; Make sure that we merge the consecutive load/store sequence below and use a 372; word (16 bit) instead of a byte copy even if there are intermediate sign 373; extensions. 374; CHECK-LABEL: MergeLoadStoreBaseIndexOffsetSext: 375; CHECK: movw (%{{.*}},%{{.*}}), [[REG:%[a-z]+]] 376; CHECK: movw [[REG]], (%{{.*}}) 377define void @MergeLoadStoreBaseIndexOffsetSext(i8* %a, i8* %b, i8* %c, i32 %n) { 378 br label %1 379 380; <label>:1 381 %.09 = phi i32 [ %n, %0 ], [ %12, %1 ] 382 %.08 = phi i8* [ %b, %0 ], [ %11, %1 ] 383 %.0 = phi i8* [ %a, %0 ], [ %2, %1 ] 384 %2 = getelementptr inbounds i8, i8* %.0, i64 1 385 %3 = load i8, i8* %.0, align 1 386 %4 = sext i8 %3 to i64 387 %5 = getelementptr inbounds i8, i8* %c, i64 %4 388 %6 = load i8, i8* %5, align 1 389 %7 = add i64 %4, 1 390 %8 = getelementptr inbounds i8, i8* %c, i64 %7 391 %9 = load i8, i8* %8, align 1 392 store i8 %6, i8* %.08, align 1 393 %10 = getelementptr inbounds i8, i8* %.08, i64 1 394 store i8 %9, i8* %10, align 1 395 %11 = getelementptr inbounds i8, i8* %.08, i64 2 396 %12 = add nsw i32 %.09, -1 397 %13 = icmp eq i32 %12, 0 398 br i1 %13, label %14, label %1 399 400; <label>:14 401 ret void 402} 403 404; However, we can only merge ignore sign extensions when they are on all memory 405; computations; 406; CHECK-LABEL: loadStoreBaseIndexOffsetSextNoSex: 407; CHECK-NOT: movw (%{{.*}},%{{.*}}), [[REG:%[a-z]+]] 408; CHECK-NOT: movw [[REG]], (%{{.*}}) 409define void @loadStoreBaseIndexOffsetSextNoSex(i8* %a, i8* %b, i8* %c, i32 %n) { 410 br label %1 411 412; <label>:1 413 %.09 = phi i32 [ %n, %0 ], [ %12, %1 ] 414 %.08 = phi i8* [ %b, %0 ], [ %11, %1 ] 415 %.0 = phi i8* [ %a, %0 ], [ %2, %1 ] 416 %2 = getelementptr inbounds i8, i8* %.0, i64 1 417 %3 = load i8, i8* %.0, align 1 418 %4 = sext i8 %3 to i64 419 %5 = getelementptr inbounds i8, i8* %c, i64 %4 420 %6 = load i8, i8* %5, align 1 421 %7 = add i8 %3, 1 422 %wrap.4 = sext i8 %7 to i64 423 %8 = getelementptr inbounds i8, i8* %c, i64 %wrap.4 424 %9 = load i8, i8* %8, align 1 425 store i8 %6, i8* %.08, align 1 426 %10 = getelementptr inbounds i8, i8* %.08, i64 1 427 store i8 %9, i8* %10, align 1 428 %11 = getelementptr inbounds i8, i8* %.08, i64 2 429 %12 = add nsw i32 %.09, -1 430 %13 = icmp eq i32 %12, 0 431 br i1 %13, label %14, label %1 432 433; <label>:14 434 ret void 435} 436 437; PR21711 ( http://llvm.org/bugs/show_bug.cgi?id=21711 ) 438define void @merge_vec_element_store(<8 x float> %v, float* %ptr) { 439 %vecext0 = extractelement <8 x float> %v, i32 0 440 %vecext1 = extractelement <8 x float> %v, i32 1 441 %vecext2 = extractelement <8 x float> %v, i32 2 442 %vecext3 = extractelement <8 x float> %v, i32 3 443 %vecext4 = extractelement <8 x float> %v, i32 4 444 %vecext5 = extractelement <8 x float> %v, i32 5 445 %vecext6 = extractelement <8 x float> %v, i32 6 446 %vecext7 = extractelement <8 x float> %v, i32 7 447 %arrayidx1 = getelementptr inbounds float, float* %ptr, i64 1 448 %arrayidx2 = getelementptr inbounds float, float* %ptr, i64 2 449 %arrayidx3 = getelementptr inbounds float, float* %ptr, i64 3 450 %arrayidx4 = getelementptr inbounds float, float* %ptr, i64 4 451 %arrayidx5 = getelementptr inbounds float, float* %ptr, i64 5 452 %arrayidx6 = getelementptr inbounds float, float* %ptr, i64 6 453 %arrayidx7 = getelementptr inbounds float, float* %ptr, i64 7 454 store float %vecext0, float* %ptr, align 4 455 store float %vecext1, float* %arrayidx1, align 4 456 store float %vecext2, float* %arrayidx2, align 4 457 store float %vecext3, float* %arrayidx3, align 4 458 store float %vecext4, float* %arrayidx4, align 4 459 store float %vecext5, float* %arrayidx5, align 4 460 store float %vecext6, float* %arrayidx6, align 4 461 store float %vecext7, float* %arrayidx7, align 4 462 ret void 463 464; CHECK-LABEL: merge_vec_element_store 465; CHECK: vmovups 466; CHECK-NEXT: vzeroupper 467; CHECK-NEXT: retq 468} 469 470; PR21711 - Merge vector stores into wider vector stores. 471; These should be merged into 32-byte stores. 472define void @merge_vec_extract_stores(<8 x float> %v1, <8 x float> %v2, <4 x float>* %ptr) { 473 %idx0 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 3 474 %idx1 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 4 475 %idx2 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 5 476 %idx3 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 6 477 %shuffle0 = shufflevector <8 x float> %v1, <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3> 478 %shuffle1 = shufflevector <8 x float> %v1, <8 x float> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7> 479 %shuffle2 = shufflevector <8 x float> %v2, <8 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3> 480 %shuffle3 = shufflevector <8 x float> %v2, <8 x float> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7> 481 store <4 x float> %shuffle0, <4 x float>* %idx0, align 16 482 store <4 x float> %shuffle1, <4 x float>* %idx1, align 16 483 store <4 x float> %shuffle2, <4 x float>* %idx2, align 16 484 store <4 x float> %shuffle3, <4 x float>* %idx3, align 16 485 ret void 486 487; CHECK-LABEL: merge_vec_extract_stores 488; CHECK: vmovups %ymm0, 48(%rdi) 489; CHECK-NEXT: vmovups %ymm1, 80(%rdi) 490; CHECK-NEXT: vzeroupper 491; CHECK-NEXT: retq 492} 493 494; Merging vector stores when sourced from vector loads is not currently handled. 495define void @merge_vec_stores_from_loads(<4 x float>* %v, <4 x float>* %ptr) { 496 %load_idx0 = getelementptr inbounds <4 x float>, <4 x float>* %v, i64 0 497 %load_idx1 = getelementptr inbounds <4 x float>, <4 x float>* %v, i64 1 498 %v0 = load <4 x float>, <4 x float>* %load_idx0 499 %v1 = load <4 x float>, <4 x float>* %load_idx1 500 %store_idx0 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 0 501 %store_idx1 = getelementptr inbounds <4 x float>, <4 x float>* %ptr, i64 1 502 store <4 x float> %v0, <4 x float>* %store_idx0, align 16 503 store <4 x float> %v1, <4 x float>* %store_idx1, align 16 504 ret void 505 506; CHECK-LABEL: merge_vec_stores_from_loads 507; CHECK: vmovaps 508; CHECK-NEXT: vmovaps 509; CHECK-NEXT: vmovaps 510; CHECK-NEXT: vmovaps 511; CHECK-NEXT: retq 512} 513 514; Merging vector stores when sourced from a constant vector is not currently handled. 515define void @merge_vec_stores_of_constants(<4 x i32>* %ptr) { 516 %idx0 = getelementptr inbounds <4 x i32>, <4 x i32>* %ptr, i64 3 517 %idx1 = getelementptr inbounds <4 x i32>, <4 x i32>* %ptr, i64 4 518 store <4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32>* %idx0, align 16 519 store <4 x i32> <i32 0, i32 0, i32 0, i32 0>, <4 x i32>* %idx1, align 16 520 ret void 521 522; CHECK-LABEL: merge_vec_stores_of_constants 523; CHECK: vxorps 524; CHECK-NEXT: vmovaps 525; CHECK-NEXT: vmovaps 526; CHECK-NEXT: retq 527} 528 529; This is a minimized test based on real code that was failing. 530; We could merge stores (and loads) like this... 531 532define void @merge_vec_element_and_scalar_load([6 x i64]* %array) { 533 %idx0 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 0 534 %idx1 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 1 535 %idx4 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 4 536 %idx5 = getelementptr inbounds [6 x i64], [6 x i64]* %array, i64 0, i64 5 537 538 %a0 = load i64, i64* %idx0, align 8 539 store i64 %a0, i64* %idx4, align 8 540 541 %b = bitcast i64* %idx1 to <2 x i64>* 542 %v = load <2 x i64>, <2 x i64>* %b, align 8 543 %a1 = extractelement <2 x i64> %v, i32 0 544 store i64 %a1, i64* %idx5, align 8 545 ret void 546 547; CHECK-LABEL: merge_vec_element_and_scalar_load 548; CHECK: movq (%rdi), %rax 549; CHECK-NEXT: movq %rax, 32(%rdi) 550; CHECK-NEXT: movq 8(%rdi), %rax 551; CHECK-NEXT: movq %rax, 40(%rdi) 552; CHECK-NEXT: retq 553} 554