1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 declare <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptrs, i32, <2 x i1> %mask, <2 x double> %src0)
5 declare void @llvm.masked.store.v2f64.p0v2f64(<2 x double> %val, <2 x double>* %ptrs, i32, <2 x i1> %mask)
6 declare <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> %ptrs, i32, <2 x i1> %mask, <2 x double> %passthru)
7 declare <4 x double> @llvm.masked.gather.v4f64.v4p0f64(<4 x double*> %ptrs, i32, <4 x i1> %mask, <4 x double> %passthru)
8 declare void @llvm.masked.scatter.v2f64.v2p0f64(<2 x double> %val, <2 x double*> %ptrs, i32, <2 x i1> %mask)
10 define <2 x double> @load_zeromask(<2 x double>* %ptr, <2 x double> %passthru) {
11 ; CHECK-LABEL: @load_zeromask(
12 ; CHECK-NEXT: ret <2 x double> [[PASSTHRU:%.*]]
14 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 1, <2 x i1> zeroinitializer, <2 x double> %passthru)
18 define <2 x double> @load_onemask(<2 x double>* %ptr, <2 x double> %passthru) {
19 ; CHECK-LABEL: @load_onemask(
20 ; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x double>, <2 x double>* [[PTR:%.*]], align 2
21 ; CHECK-NEXT: ret <2 x double> [[UNMASKEDLOAD]]
23 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 2, <2 x i1> <i1 1, i1 1>, <2 x double> %passthru)
27 define <2 x double> @load_undefmask(<2 x double>* %ptr, <2 x double> %passthru) {
28 ; CHECK-LABEL: @load_undefmask(
29 ; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x double>, <2 x double>* [[PTR:%.*]], align 2
30 ; CHECK-NEXT: ret <2 x double> [[UNMASKEDLOAD]]
32 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 2, <2 x i1> <i1 1, i1 undef>, <2 x double> %passthru)
36 @G = external global i8
38 define <2 x double> @load_cemask(<2 x double>* %ptr, <2 x double> %passthru) {
39 ; CHECK-LABEL: @load_cemask(
40 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* [[PTR:%.*]], i32 2, <2 x i1> <i1 true, i1 ptrtoint (i8* @G to i1)>, <2 x double> [[PASSTHRU:%.*]])
41 ; CHECK-NEXT: ret <2 x double> [[RES]]
43 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 2, <2 x i1> <i1 1, i1 ptrtoint (i8* @G to i1)>, <2 x double> %passthru)
47 define <2 x double> @load_lane0(<2 x double>* %ptr, double %pt) {
48 ; CHECK-LABEL: @load_lane0(
49 ; CHECK-NEXT: [[PTV2:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 1
50 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* [[PTR:%.*]], i32 2, <2 x i1> <i1 true, i1 false>, <2 x double> [[PTV2]])
51 ; CHECK-NEXT: ret <2 x double> [[RES]]
53 %ptv1 = insertelement <2 x double> undef, double %pt, i64 0
54 %ptv2 = insertelement <2 x double> %ptv1, double %pt, i64 1
55 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 2, <2 x i1> <i1 true, i1 false>, <2 x double> %ptv2)
59 define double @load_all(double* %base, double %pt) {
60 ; CHECK-LABEL: @load_all(
61 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr double, double* [[BASE:%.*]], <4 x i64> <i64 0, i64 undef, i64 2, i64 3>
62 ; CHECK-NEXT: [[RES:%.*]] = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64(<4 x double*> [[PTRS]], i32 4, <4 x i1> <i1 true, i1 false, i1 true, i1 true>, <4 x double> undef)
63 ; CHECK-NEXT: [[ELT:%.*]] = extractelement <4 x double> [[RES]], i64 2
64 ; CHECK-NEXT: ret double [[ELT]]
66 %ptrs = getelementptr double, double* %base, <4 x i64> <i64 0, i64 1, i64 2, i64 3>
67 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64(<4 x double*> %ptrs, i32 4, <4 x i1> <i1 true, i1 false, i1 true, i1 true>, <4 x double> undef)
68 %elt = extractelement <4 x double> %res, i64 2
72 define <2 x double> @load_generic(<2 x double>* %ptr, double %pt,
73 ; CHECK-LABEL: @load_generic(
74 ; CHECK-NEXT: [[PTV1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
75 ; CHECK-NEXT: [[PTV2:%.*]] = shufflevector <2 x double> [[PTV1]], <2 x double> undef, <2 x i32> zeroinitializer
76 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* [[PTR:%.*]], i32 4, <2 x i1> [[MASK:%.*]], <2 x double> [[PTV2]])
77 ; CHECK-NEXT: ret <2 x double> [[RES]]
80 %ptv1 = insertelement <2 x double> undef, double %pt, i64 0
81 %ptv2 = insertelement <2 x double> %ptv1, double %pt, i64 1
82 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 4, <2 x i1> %mask, <2 x double> %ptv2)
86 define <2 x double> @load_speculative(<2 x double>* dereferenceable(16) %ptr,
87 ; CHECK-LABEL: @load_speculative(
88 ; CHECK-NEXT: [[PTV1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
89 ; CHECK-NEXT: [[PTV2:%.*]] = shufflevector <2 x double> [[PTV1]], <2 x double> undef, <2 x i32> zeroinitializer
90 ; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x double>, <2 x double>* [[PTR:%.*]], align 4
91 ; CHECK-NEXT: [[TMP1:%.*]] = select <2 x i1> [[MASK:%.*]], <2 x double> [[UNMASKEDLOAD]], <2 x double> [[PTV2]]
92 ; CHECK-NEXT: ret <2 x double> [[TMP1]]
94 double %pt, <2 x i1> %mask) {
95 %ptv1 = insertelement <2 x double> undef, double %pt, i64 0
96 %ptv2 = insertelement <2 x double> %ptv1, double %pt, i64 1
97 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 4, <2 x i1> %mask, <2 x double> %ptv2)
101 define <2 x double> @neg_load_spec_width(<2 x double>* dereferenceable(8) %ptr,
102 ; CHECK-LABEL: @neg_load_spec_width(
103 ; CHECK-NEXT: [[PTV1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
104 ; CHECK-NEXT: [[PTV2:%.*]] = shufflevector <2 x double> [[PTV1]], <2 x double> undef, <2 x i32> zeroinitializer
105 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* nonnull [[PTR:%.*]], i32 4, <2 x i1> [[MASK:%.*]], <2 x double> [[PTV2]])
106 ; CHECK-NEXT: ret <2 x double> [[RES]]
108 double %pt, <2 x i1> %mask) {
109 %ptv1 = insertelement <2 x double> undef, double %pt, i64 0
110 %ptv2 = insertelement <2 x double> %ptv1, double %pt, i64 1
111 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 4, <2 x i1> %mask, <2 x double> %ptv2)
112 ret <2 x double> %res
115 ; Can't speculate since only half of required size is known deref
116 define <2 x double> @load_spec_neg_size(<2 x double>* dereferenceable(8) %ptr,
117 ; CHECK-LABEL: @load_spec_neg_size(
118 ; CHECK-NEXT: [[PTV1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
119 ; CHECK-NEXT: [[PTV2:%.*]] = shufflevector <2 x double> [[PTV1]], <2 x double> undef, <2 x i32> zeroinitializer
120 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* nonnull [[PTR:%.*]], i32 4, <2 x i1> [[MASK:%.*]], <2 x double> [[PTV2]])
121 ; CHECK-NEXT: ret <2 x double> [[RES]]
123 double %pt, <2 x i1> %mask) {
124 %ptv1 = insertelement <2 x double> undef, double %pt, i64 0
125 %ptv2 = insertelement <2 x double> %ptv1, double %pt, i64 1
126 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 4, <2 x i1> %mask, <2 x double> %ptv2)
127 ret <2 x double> %res
130 ; Can only speculate one lane (but it's the only one active)
131 define <2 x double> @load_spec_lan0(<2 x double>* dereferenceable(8) %ptr,
132 ; CHECK-LABEL: @load_spec_lan0(
133 ; CHECK-NEXT: [[PTV1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
134 ; CHECK-NEXT: [[PTV2:%.*]] = shufflevector <2 x double> [[PTV1]], <2 x double> undef, <2 x i32> zeroinitializer
135 ; CHECK-NEXT: [[MASK2:%.*]] = insertelement <2 x i1> [[MASK:%.*]], i1 false, i64 1
136 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* nonnull [[PTR:%.*]], i32 4, <2 x i1> [[MASK2]], <2 x double> [[PTV2]])
137 ; CHECK-NEXT: ret <2 x double> [[RES]]
139 double %pt, <2 x i1> %mask) {
140 %ptv1 = insertelement <2 x double> undef, double %pt, i64 0
141 %ptv2 = insertelement <2 x double> %ptv1, double %pt, i64 1
142 %mask2 = insertelement <2 x i1> %mask, i1 false, i64 1
143 %res = call <2 x double> @llvm.masked.load.v2f64.p0v2f64(<2 x double>* %ptr, i32 4, <2 x i1> %mask2, <2 x double> %ptv2)
144 ret <2 x double> %res
147 define void @store_zeromask(<2 x double>* %ptr, <2 x double> %val) {
148 ; CHECK-LABEL: @store_zeromask(
149 ; CHECK-NEXT: ret void
151 call void @llvm.masked.store.v2f64.p0v2f64(<2 x double> %val, <2 x double>* %ptr, i32 4, <2 x i1> zeroinitializer)
155 define void @store_onemask(<2 x double>* %ptr, <2 x double> %val) {
156 ; CHECK-LABEL: @store_onemask(
157 ; CHECK-NEXT: store <2 x double> [[VAL:%.*]], <2 x double>* [[PTR:%.*]], align 4
158 ; CHECK-NEXT: ret void
160 call void @llvm.masked.store.v2f64.p0v2f64(<2 x double> %val, <2 x double>* %ptr, i32 4, <2 x i1> <i1 1, i1 1>)
164 define void @store_demandedelts(<2 x double>* %ptr, double %val) {
165 ; CHECK-LABEL: @store_demandedelts(
166 ; CHECK-NEXT: [[VALVEC2:%.*]] = insertelement <2 x double> undef, double [[VAL:%.*]], i32 0
167 ; CHECK-NEXT: call void @llvm.masked.store.v2f64.p0v2f64(<2 x double> [[VALVEC2]], <2 x double>* [[PTR:%.*]], i32 4, <2 x i1> <i1 true, i1 false>)
168 ; CHECK-NEXT: ret void
170 %valvec1 = insertelement <2 x double> undef, double %val, i32 0
171 %valvec2 = insertelement <2 x double> %valvec1, double %val, i32 1
172 call void @llvm.masked.store.v2f64.p0v2f64(<2 x double> %valvec2, <2 x double>* %ptr, i32 4, <2 x i1> <i1 true, i1 false>)
176 define <2 x double> @gather_generic(<2 x double*> %ptrs, <2 x i1> %mask,
177 ; CHECK-LABEL: @gather_generic(
178 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> [[PTRS:%.*]], i32 4, <2 x i1> [[MASK:%.*]], <2 x double> [[PASSTHRU:%.*]])
179 ; CHECK-NEXT: ret <2 x double> [[RES]]
181 <2 x double> %passthru) {
182 %res = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> %ptrs, i32 4, <2 x i1> %mask, <2 x double> %passthru)
183 ret <2 x double> %res
187 define <2 x double> @gather_zeromask(<2 x double*> %ptrs, <2 x double> %passthru) {
188 ; CHECK-LABEL: @gather_zeromask(
189 ; CHECK-NEXT: ret <2 x double> [[PASSTHRU:%.*]]
191 %res = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> %ptrs, i32 4, <2 x i1> zeroinitializer, <2 x double> %passthru)
192 ret <2 x double> %res
196 define <2 x double> @gather_onemask(<2 x double*> %ptrs, <2 x double> %passthru) {
197 ; CHECK-LABEL: @gather_onemask(
198 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> [[PTRS:%.*]], i32 4, <2 x i1> <i1 true, i1 true>, <2 x double> undef)
199 ; CHECK-NEXT: ret <2 x double> [[RES]]
201 %res = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> %ptrs, i32 4, <2 x i1> <i1 true, i1 true>, <2 x double> %passthru)
202 ret <2 x double> %res
205 define <4 x double> @gather_lane2(double* %base, double %pt) {
206 ; CHECK-LABEL: @gather_lane2(
207 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr double, double* [[BASE:%.*]], <4 x i64> <i64 undef, i64 undef, i64 2, i64 undef>
208 ; CHECK-NEXT: [[PT_V1:%.*]] = insertelement <4 x double> undef, double [[PT:%.*]], i64 0
209 ; CHECK-NEXT: [[PT_V2:%.*]] = shufflevector <4 x double> [[PT_V1]], <4 x double> undef, <4 x i32> <i32 0, i32 0, i32 undef, i32 0>
210 ; CHECK-NEXT: [[RES:%.*]] = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64(<4 x double*> [[PTRS]], i32 4, <4 x i1> <i1 false, i1 false, i1 true, i1 false>, <4 x double> [[PT_V2]])
211 ; CHECK-NEXT: ret <4 x double> [[RES]]
213 %ptrs = getelementptr double, double *%base, <4 x i64> <i64 0, i64 1, i64 2, i64 3>
214 %pt_v1 = insertelement <4 x double> undef, double %pt, i64 0
215 %pt_v2 = shufflevector <4 x double> %pt_v1, <4 x double> undef, <4 x i32> zeroinitializer
216 %res = call <4 x double> @llvm.masked.gather.v4f64.v4p0f64(<4 x double*> %ptrs, i32 4, <4 x i1> <i1 false, i1 false, i1 true, i1 false>, <4 x double> %pt_v2)
217 ret <4 x double> %res
220 define <2 x double> @gather_lane0_maybe(double* %base, double %pt,
221 ; CHECK-LABEL: @gather_lane0_maybe(
222 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr double, double* [[BASE:%.*]], <2 x i64> <i64 0, i64 1>
223 ; CHECK-NEXT: [[PT_V1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
224 ; CHECK-NEXT: [[PT_V2:%.*]] = shufflevector <2 x double> [[PT_V1]], <2 x double> undef, <2 x i32> zeroinitializer
225 ; CHECK-NEXT: [[MASK2:%.*]] = insertelement <2 x i1> [[MASK:%.*]], i1 false, i64 1
226 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> [[PTRS]], i32 4, <2 x i1> [[MASK2]], <2 x double> [[PT_V2]])
227 ; CHECK-NEXT: ret <2 x double> [[RES]]
230 %ptrs = getelementptr double, double *%base, <2 x i64> <i64 0, i64 1>
231 %pt_v1 = insertelement <2 x double> undef, double %pt, i64 0
232 %pt_v2 = insertelement <2 x double> %pt_v1, double %pt, i64 1
233 %mask2 = insertelement <2 x i1> %mask, i1 false, i64 1
234 %res = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> %ptrs, i32 4, <2 x i1> %mask2, <2 x double> %pt_v2)
235 ret <2 x double> %res
238 define <2 x double> @gather_lane0_maybe_spec(double* %base, double %pt,
239 ; CHECK-LABEL: @gather_lane0_maybe_spec(
240 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr double, double* [[BASE:%.*]], <2 x i64> <i64 0, i64 1>
241 ; CHECK-NEXT: [[PT_V1:%.*]] = insertelement <2 x double> undef, double [[PT:%.*]], i64 0
242 ; CHECK-NEXT: [[PT_V2:%.*]] = shufflevector <2 x double> [[PT_V1]], <2 x double> undef, <2 x i32> zeroinitializer
243 ; CHECK-NEXT: [[MASK2:%.*]] = insertelement <2 x i1> [[MASK:%.*]], i1 false, i64 1
244 ; CHECK-NEXT: [[RES:%.*]] = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> [[PTRS]], i32 4, <2 x i1> [[MASK2]], <2 x double> [[PT_V2]])
245 ; CHECK-NEXT: ret <2 x double> [[RES]]
248 %ptrs = getelementptr double, double *%base, <2 x i64> <i64 0, i64 1>
249 %pt_v1 = insertelement <2 x double> undef, double %pt, i64 0
250 %pt_v2 = insertelement <2 x double> %pt_v1, double %pt, i64 1
251 %mask2 = insertelement <2 x i1> %mask, i1 false, i64 1
252 %res = call <2 x double> @llvm.masked.gather.v2f64.v2p0f64(<2 x double*> %ptrs, i32 4, <2 x i1> %mask2, <2 x double> %pt_v2)
253 ret <2 x double> %res
257 define void @scatter_zeromask(<2 x double*> %ptrs, <2 x double> %val) {
258 ; CHECK-LABEL: @scatter_zeromask(
259 ; CHECK-NEXT: ret void
261 call void @llvm.masked.scatter.v2f64.v2p0f64(<2 x double> %val, <2 x double*> %ptrs, i32 6, <2 x i1> zeroinitializer)
265 define void @scatter_demandedelts(double* %ptr, double %val) {
266 ; CHECK-LABEL: @scatter_demandedelts(
267 ; CHECK-NEXT: [[PTRS:%.*]] = getelementptr double, double* [[PTR:%.*]], <2 x i64> <i64 0, i64 undef>
268 ; CHECK-NEXT: [[VALVEC2:%.*]] = insertelement <2 x double> undef, double [[VAL:%.*]], i32 0
269 ; CHECK-NEXT: call void @llvm.masked.scatter.v2f64.v2p0f64(<2 x double> [[VALVEC2]], <2 x double*> [[PTRS]], i32 8, <2 x i1> <i1 true, i1 false>)
270 ; CHECK-NEXT: ret void
272 %ptrs = getelementptr double, double* %ptr, <2 x i64> <i64 0, i64 1>
273 %valvec1 = insertelement <2 x double> undef, double %val, i32 0
274 %valvec2 = insertelement <2 x double> %valvec1, double %val, i32 1
275 call void @llvm.masked.scatter.v2f64.v2p0f64(<2 x double> %valvec2, <2 x double*> %ptrs, i32 8, <2 x i1> <i1 true, i1 false>)