1 ; RUN: opt -S -loop-vectorize -instcombine -force-vector-width=2 -force-vector-interleave=1 -enable-interleaved-mem-accesses < %s | FileCheck %s
2 ; RUN: opt -S -loop-vectorize -instcombine -force-vector-width=2 -force-vector-interleave=1 -enable-interleaved-mem-accesses -enable-masked-interleaved-mem-accesses < %s | FileCheck %s
4 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
5 %pair = type { i64, i64 }
7 ; Ensure that we vectorize the interleaved load group even though the loop
8 ; contains a conditional store. The store group contains gaps and is not
11 ; CHECK-LABEL: @interleaved_with_cond_store_0(
14 ; CHECK: %n.mod.vf = and i64 %[[N:.+]], 1
15 ; CHECK: %[[IsZero:[a-zA-Z0-9]+]] = icmp eq i64 %n.mod.vf, 0
16 ; CHECK: %[[R:.+]] = select i1 %[[IsZero]], i64 2, i64 %n.mod.vf
17 ; CHECK: %n.vec = sub nsw i64 %[[N]], %[[R]]
20 ; CHECK: %wide.vec = load <4 x i64>, <4 x i64>* %{{.*}}
21 ; CHECK: %strided.vec = shufflevector <4 x i64> %wide.vec, <4 x i64> undef, <2 x i32> <i32 0, i32 2>
23 ; CHECK: pred.store.if
24 ; CHECK: %[[X1:.+]] = extractelement <4 x i64> %wide.vec, i32 0
25 ; CHECK: store i64 %[[X1]], {{.*}}
27 ; CHECK: pred.store.if
28 ; CHECK: %[[X2:.+]] = extractelement <4 x i64> %wide.vec, i32 2
29 ; CHECK: store i64 %[[X2]], {{.*}}
31 define void @interleaved_with_cond_store_0(%pair *%p, i64 %x, i64 %n) {
36 %i = phi i64 [ %i.next, %if.merge ], [ 0, %entry ]
37 %p.1 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 1
38 %0 = load i64, i64* %p.1, align 8
39 %1 = icmp eq i64 %0, %x
40 br i1 %1, label %if.then, label %if.merge
43 store i64 %0, i64* %p.1, align 8
47 %i.next = add nuw nsw i64 %i, 1
48 %cond = icmp slt i64 %i.next, %n
49 br i1 %cond, label %for.body, label %for.end
55 ; Ensure that we don't form a single interleaved group for the two loads. The
56 ; conditional store prevents the second load from being hoisted. The two load
57 ; groups are separately vectorized. The store group contains gaps and is not
60 ; CHECK-LABEL: @interleaved_with_cond_store_1(
63 ; CHECK: %n.mod.vf = and i64 %[[N:.+]], 1
64 ; CHECK: %[[IsZero:[a-zA-Z0-9]+]] = icmp eq i64 %n.mod.vf, 0
65 ; CHECK: %[[R:.+]] = select i1 %[[IsZero]], i64 2, i64 %n.mod.vf
66 ; CHECK: %n.vec = sub nsw i64 %[[N]], %[[R]]
69 ; CHECK: %[[L1:.+]] = load <4 x i64>, <4 x i64>* %{{.*}}
70 ; CHECK: %strided.vec = shufflevector <4 x i64> %[[L1]], <4 x i64> undef, <2 x i32> <i32 0, i32 2>
72 ; CHECK: pred.store.if
73 ; CHECK: %[[X1:.+]] = extractelement <4 x i64> %wide.vec, i32 0
74 ; CHECK: store i64 %[[X1]], {{.*}}
76 ; CHECK: pred.store.if
77 ; CHECK: %[[X2:.+]] = extractelement <4 x i64> %wide.vec, i32 2
78 ; CHECK: store i64 %[[X2]], {{.*}}
80 ; CHECK: pred.store.continue
81 ; CHECK: %[[L2:.+]] = load <4 x i64>, <4 x i64>* {{.*}}
82 ; CHECK: %[[X3:.+]] = extractelement <4 x i64> %[[L2]], i32 0
83 ; CHECK: store i64 %[[X3]], {{.*}}
84 ; CHECK: %[[X4:.+]] = extractelement <4 x i64> %[[L2]], i32 2
85 ; CHECK: store i64 %[[X4]], {{.*}}
87 define void @interleaved_with_cond_store_1(%pair *%p, i64 %x, i64 %n) {
92 %i = phi i64 [ %i.next, %if.merge ], [ 0, %entry ]
93 %p.0 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 0
94 %p.1 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 1
95 %0 = load i64, i64* %p.1, align 8
96 %1 = icmp eq i64 %0, %x
97 br i1 %1, label %if.then, label %if.merge
100 store i64 %0, i64* %p.0, align 8
104 %2 = load i64, i64* %p.0, align 8
105 store i64 %2, i64 *%p.1, align 8
106 %i.next = add nuw nsw i64 %i, 1
107 %cond = icmp slt i64 %i.next, %n
108 br i1 %cond, label %for.body, label %for.end
114 ; Ensure that we don't create a single interleaved group for the two stores.
115 ; The second store is conditional and we can't sink the first store inside the
116 ; predicated block. The load group is vectorized, and the store groups contain
117 ; gaps and are not vectorized.
119 ; CHECK-LABEL: @interleaved_with_cond_store_2(
122 ; CHECK: %n.mod.vf = and i64 %[[N:.+]], 1
123 ; CHECK: %[[IsZero:[a-zA-Z0-9]+]] = icmp eq i64 %n.mod.vf, 0
124 ; CHECK: %[[R:.+]] = select i1 %[[IsZero]], i64 2, i64 %n.mod.vf
125 ; CHECK: %n.vec = sub nsw i64 %[[N]], %[[R]]
127 ; CHECK: vector.body:
128 ; CHECK: %[[L1:.+]] = load <4 x i64>, <4 x i64>* %{{.*}}
129 ; CHECK: %strided.vec = shufflevector <4 x i64> %[[L1]], <4 x i64> undef, <2 x i32> <i32 0, i32 2>
130 ; CHECK: store i64 %x, {{.*}}
131 ; CHECK: store i64 %x, {{.*}}
133 ; CHECK: pred.store.if
134 ; CHECK: %[[X1:.+]] = extractelement <4 x i64> %wide.vec, i32 0
135 ; CHECK: store i64 %[[X1]], {{.*}}
137 ; CHECK: pred.store.if
138 ; CHECK: %[[X2:.+]] = extractelement <4 x i64> %wide.vec, i32 2
139 ; CHECK: store i64 %[[X2]], {{.*}}
141 define void @interleaved_with_cond_store_2(%pair *%p, i64 %x, i64 %n) {
146 %i = phi i64 [ %i.next, %if.merge ], [ 0, %entry ]
147 %p.0 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 0
148 %p.1 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 1
149 %0 = load i64, i64* %p.1, align 8
150 store i64 %x, i64* %p.0, align 8
151 %1 = icmp eq i64 %0, %x
152 br i1 %1, label %if.then, label %if.merge
155 store i64 %0, i64* %p.1, align 8
159 %i.next = add nuw nsw i64 %i, 1
160 %cond = icmp slt i64 %i.next, %n
161 br i1 %cond, label %for.body, label %for.end