interleaved-accesses-pred-stores.ll
5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
; RUN: opt -S -loop-vectorize -instcombine -force-vector-width=2 -force-vector-interleave=1 -enable-interleaved-mem-accesses < %s | FileCheck %s
; 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
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
%pair = type { i64, i64 }
; Ensure that we vectorize the interleaved load group even though the loop
; contains a conditional store. The store group contains gaps and is not
; vectorized.
;
; CHECK-LABEL: @interleaved_with_cond_store_0(
;
; CHECK: vector.ph
; CHECK: %n.mod.vf = and i64 %[[N:.+]], 1
; CHECK: %[[IsZero:[a-zA-Z0-9]+]] = icmp eq i64 %n.mod.vf, 0
; CHECK: %[[R:.+]] = select i1 %[[IsZero]], i64 2, i64 %n.mod.vf
; CHECK: %n.vec = sub nsw i64 %[[N]], %[[R]]
;
; CHECK: vector.body:
; CHECK: %wide.vec = load <4 x i64>, <4 x i64>* %{{.*}}
; CHECK: %strided.vec = shufflevector <4 x i64> %wide.vec, <4 x i64> undef, <2 x i32> <i32 0, i32 2>
;
; CHECK: pred.store.if
; CHECK: %[[X1:.+]] = extractelement <4 x i64> %wide.vec, i32 0
; CHECK: store i64 %[[X1]], {{.*}}
;
; CHECK: pred.store.if
; CHECK: %[[X2:.+]] = extractelement <4 x i64> %wide.vec, i32 2
; CHECK: store i64 %[[X2]], {{.*}}
define void @interleaved_with_cond_store_0(%pair *%p, i64 %x, i64 %n) {
entry:
br label %for.body
for.body:
%i = phi i64 [ %i.next, %if.merge ], [ 0, %entry ]
%p.1 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 1
%0 = load i64, i64* %p.1, align 8
%1 = icmp eq i64 %0, %x
br i1 %1, label %if.then, label %if.merge
if.then:
store i64 %0, i64* %p.1, align 8
br label %if.merge
if.merge:
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end
for.end:
ret void
}
; Ensure that we don't form a single interleaved group for the two loads. The
; conditional store prevents the second load from being hoisted. The two load
; groups are separately vectorized. The store group contains gaps and is not
; vectorized.
;
; CHECK-LABEL: @interleaved_with_cond_store_1(
;
; CHECK: vector.ph
; CHECK: %n.mod.vf = and i64 %[[N:.+]], 1
; CHECK: %[[IsZero:[a-zA-Z0-9]+]] = icmp eq i64 %n.mod.vf, 0
; CHECK: %[[R:.+]] = select i1 %[[IsZero]], i64 2, i64 %n.mod.vf
; CHECK: %n.vec = sub nsw i64 %[[N]], %[[R]]
;
; CHECK: vector.body:
; CHECK: %[[L1:.+]] = load <4 x i64>, <4 x i64>* %{{.*}}
; CHECK: %strided.vec = shufflevector <4 x i64> %[[L1]], <4 x i64> undef, <2 x i32> <i32 0, i32 2>
;
; CHECK: pred.store.if
; CHECK: %[[X1:.+]] = extractelement <4 x i64> %wide.vec, i32 0
; CHECK: store i64 %[[X1]], {{.*}}
;
; CHECK: pred.store.if
; CHECK: %[[X2:.+]] = extractelement <4 x i64> %wide.vec, i32 2
; CHECK: store i64 %[[X2]], {{.*}}
;
; CHECK: pred.store.continue
; CHECK: %[[L2:.+]] = load <4 x i64>, <4 x i64>* {{.*}}
; CHECK: %[[X3:.+]] = extractelement <4 x i64> %[[L2]], i32 0
; CHECK: store i64 %[[X3]], {{.*}}
; CHECK: %[[X4:.+]] = extractelement <4 x i64> %[[L2]], i32 2
; CHECK: store i64 %[[X4]], {{.*}}
define void @interleaved_with_cond_store_1(%pair *%p, i64 %x, i64 %n) {
entry:
br label %for.body
for.body:
%i = phi i64 [ %i.next, %if.merge ], [ 0, %entry ]
%p.0 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 0
%p.1 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 1
%0 = load i64, i64* %p.1, align 8
%1 = icmp eq i64 %0, %x
br i1 %1, label %if.then, label %if.merge
if.then:
store i64 %0, i64* %p.0, align 8
br label %if.merge
if.merge:
%2 = load i64, i64* %p.0, align 8
store i64 %2, i64 *%p.1, align 8
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end
for.end:
ret void
}
; Ensure that we don't create a single interleaved group for the two stores.
; The second store is conditional and we can't sink the first store inside the
; predicated block. The load group is vectorized, and the store groups contain
; gaps and are not vectorized.
;
; CHECK-LABEL: @interleaved_with_cond_store_2(
;
; CHECK: vector.ph
; CHECK: %n.mod.vf = and i64 %[[N:.+]], 1
; CHECK: %[[IsZero:[a-zA-Z0-9]+]] = icmp eq i64 %n.mod.vf, 0
; CHECK: %[[R:.+]] = select i1 %[[IsZero]], i64 2, i64 %n.mod.vf
; CHECK: %n.vec = sub nsw i64 %[[N]], %[[R]]
;
; CHECK: vector.body:
; CHECK: %[[L1:.+]] = load <4 x i64>, <4 x i64>* %{{.*}}
; CHECK: %strided.vec = shufflevector <4 x i64> %[[L1]], <4 x i64> undef, <2 x i32> <i32 0, i32 2>
; CHECK: store i64 %x, {{.*}}
; CHECK: store i64 %x, {{.*}}
;
; CHECK: pred.store.if
; CHECK: %[[X1:.+]] = extractelement <4 x i64> %wide.vec, i32 0
; CHECK: store i64 %[[X1]], {{.*}}
;
; CHECK: pred.store.if
; CHECK: %[[X2:.+]] = extractelement <4 x i64> %wide.vec, i32 2
; CHECK: store i64 %[[X2]], {{.*}}
define void @interleaved_with_cond_store_2(%pair *%p, i64 %x, i64 %n) {
entry:
br label %for.body
for.body:
%i = phi i64 [ %i.next, %if.merge ], [ 0, %entry ]
%p.0 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 0
%p.1 = getelementptr inbounds %pair, %pair* %p, i64 %i, i32 1
%0 = load i64, i64* %p.1, align 8
store i64 %x, i64* %p.0, align 8
%1 = icmp eq i64 %0, %x
br i1 %1, label %if.then, label %if.merge
if.then:
store i64 %0, i64* %p.1, align 8
br label %if.merge
if.merge:
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end
for.end:
ret void
}