llvm.org GIT mirror llvm / 3d3dc67
[release_36] Cherry-pick r231601. Original commit message: [X86][AVX] Fix wrong lowering of VPERM2X128 nodes There were cases where the backend computed a wrong permute mask for a VPERM2X128 node. Example: \code define <8 x float> @foo(<8 x float> %a, <8 x float> %b) { %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32> <i32 undef, i32 undef, i32 6, i32 7, i32 undef, i32 undef, i32 6, i32 7> ret <8 x float> %shuffle } \code end Before this patch, llc (with -mattr=+avx) emitted the following vperm2f128: vperm2f128 $0, %ymm0, %ymm0, %ymm0 # ymm0 = ymm0[0,1,0,1] With this patch, llc emits a vperm2f128 with a correct permute mask: vperm2f128 $17, %ymm0, %ymm0, %ymm0 # ymm0 = ymm0[2,3,2,3] Differential Revision: http://reviews.llvm.org/D8119 git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@232803 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 5 years ago
3 changed file(s) with 86 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1011110111
1011210112 // Otherwise form a 128-bit permutation.
1011310113 // FIXME: Detect zero-vector inputs and use the VPERM2X128 to zero that half.
10114 unsigned PermMask = Mask[0] / 2 | (Mask[2] / 2) << 4;
10114 int MaskLO = Mask[0];
10115 if (MaskLO == SM_SentinelUndef)
10116 MaskLO = Mask[1] == SM_SentinelUndef ? 0 : Mask[1];
10117
10118 int MaskHI = Mask[2];
10119 if (MaskHI == SM_SentinelUndef)
10120 MaskHI = Mask[3] == SM_SentinelUndef ? 0 : Mask[3];
10121
10122 unsigned PermMask = MaskLO / 2 | (MaskHI / 2) << 4;
1011510123 return DAG.getNode(X86ISD::VPERM2X128, DL, VT, V1, V2,
1011610124 DAG.getConstant(PermMask, MVT::i8));
1011710125 }
171171 define <8 x float> @F(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
172172 ; ALL-LABEL: F:
173173 ; ALL: ## BB#0: ## %entry
174 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm1[0,1,0,1]
174 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3],ymm1[0,1]
175175 ; ALL-NEXT: retq
176176 entry:
177177 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
178 ret <8 x float> %shuffle
179 }
180
181 define <8 x float> @F2(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
182 ; ALL-LABEL: F2:
183 ; ALL: ## BB#0: ## %entry
184 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3,2,3]
185 ; ALL-NEXT: retq
186 entry:
187 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
188 ret <8 x float> %shuffle
189 }
190
191 define <8 x float> @F3(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
192 ; ALL-LABEL: F3:
193 ; ALL: ## BB#0: ## %entry
194 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3],ymm1[0,1]
195 ; ALL-NEXT: retq
196 entry:
197 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
198 ret <8 x float> %shuffle
199 }
200
201 define <8 x float> @F4(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
202 ; ALL-LABEL: F4:
203 ; ALL: ## BB#0: ## %entry
204 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3],ymm1[2,3]
205 ; ALL-NEXT: retq
206 entry:
207 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
208 ret <8 x float> %shuffle
209 }
210
211 define <8 x float> @F5(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
212 ; ALL-LABEL: F5:
213 ; ALL: ## BB#0: ## %entry
214 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3,2,3]
215 ; ALL-NEXT: retq
216 entry:
217 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
218 ret <8 x float> %shuffle
219 }
220
221 define <8 x float> @F6(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
222 ; ALL-LABEL: F6:
223 ; ALL: ## BB#0: ## %entry
224 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3],ymm1[0,1]
225 ; ALL-NEXT: retq
226 entry:
227 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
228 ret <8 x float> %shuffle
229 }
230
231 define <8 x float> @F7(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
232 ; ALL-LABEL: F7:
233 ; ALL: ## BB#0: ## %entry
234 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3,2,3]
235 ; ALL-NEXT: retq
236 entry:
237 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
238 ret <8 x float> %shuffle
239 }
240
241 define <8 x float> @F8(<8 x float> %a, <8 x float> %b) nounwind uwtable readnone ssp {
242 ; ALL-LABEL: F8:
243 ; ALL: ## BB#0: ## %entry
244 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm0 = ymm0[2,3],ymm1[2,3]
245 ; ALL-NEXT: retq
246 entry:
247 %shuffle = shufflevector <8 x float> %a, <8 x float> %b, <8 x i32>
178248 ret <8 x float> %shuffle
179249 }
180250
686686 ; ALL-LABEL: shuffle_v8f64_c348cda0:
687687 ; ALL: # BB#0:
688688 ; ALL-NEXT: vextractf64x4 $1, %zmm0, %ymm2
689 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm2 = ymm0[0,1],ymm2[0,1]
689 ; ALL-NEXT: vperm2f128 {{.*#+}} ymm2 = ymm0[2,3],ymm2[0,1]
690690 ; ALL-NEXT: vextractf64x4 $1, %zmm1, %ymm3
691691 ; ALL-NEXT: vbroadcastsd %xmm1, %ymm4
692692 ; ALL-NEXT: vblendpd {{.*#+}} ymm4 = ymm3[0,1,2],ymm4[3]
14041404 ; ALL-LABEL: shuffle_v8i64_6caa87e5:
14051405 ; ALL: # BB#0:
14061406 ; ALL-NEXT: vextracti64x4 $1, %zmm0, %ymm0
1407 ; ALL-NEXT: vperm2i128 {{.*#+}} ymm2 = ymm0[0,1,0,1]
1408 ; ALL-NEXT: vextracti64x4 $1, %zmm1, %ymm3
1409 ; ALL-NEXT: vpblendd {{.*#+}} ymm4 = ymm1[0,1,2,3],ymm3[4,5],ymm1[6,7]
1410 ; ALL-NEXT: vpblendd {{.*#+}} ymm2 = ymm4[0,1],ymm2[2,3],ymm4[4,5],ymm2[6,7]
14111407 ; ALL-NEXT: vperm2i128 {{.*#+}} ymm0 = ymm0[2,3,0,1]
1412 ; ALL-NEXT: vpblendd {{.*#+}} ymm1 = ymm3[0,1,2,3],ymm1[4,5,6,7]
1408 ; ALL-NEXT: vextracti64x4 $1, %zmm1, %ymm2
1409 ; ALL-NEXT: vpblendd {{.*#+}} ymm3 = ymm1[0,1,2,3],ymm2[4,5],ymm1[6,7]
1410 ; ALL-NEXT: vpblendd {{.*#+}} ymm3 = ymm3[0,1],ymm0[2,3],ymm3[4,5],ymm0[6,7]
1411 ; ALL-NEXT: vpblendd {{.*#+}} ymm1 = ymm2[0,1,2,3],ymm1[4,5,6,7]
14131412 ; ALL-NEXT: vpshufd {{.*#+}} ymm1 = ymm1[0,1,0,1,4,5,4,5]
14141413 ; ALL-NEXT: vpblendd {{.*#+}} ymm0 = ymm0[0,1],ymm1[2,3,4,5,6,7]
1415 ; ALL-NEXT: vinserti64x4 $1, %ymm2, %zmm0, %zmm0
1414 ; ALL-NEXT: vinserti64x4 $1, %ymm3, %zmm0, %zmm0
14161415 ; ALL-NEXT: retq
14171416 %shuffle = shufflevector <8 x i64> %a, <8 x i64> %b, <8 x i32>
14181417 ret <8 x i64> %shuffle