Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit affca96

Browse files
committed
[InstCombine] add tests for shuffle+insert folds; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344908 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 502027b commit affca96

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

test/Transforms/InstCombine/insert-extract-shuffle.ll

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,126 @@ define <4 x float> @collectShuffleElts(<2 x float> %x, float %y) {
303303
ret <4 x float> %v3
304304
}
305305

306+
; TODO: Simplest case - insert scalar into undef, then shuffle that value in place into another vector.
307+
308+
define <4 x float> @insert_shuffle(float %x, <4 x float> %y) {
309+
; CHECK-LABEL: @insert_shuffle(
310+
; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
311+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> [[Y:%.*]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>
312+
; CHECK-NEXT: ret <4 x float> [[R]]
313+
;
314+
%xv = insertelement <4 x float> undef, float %x, i32 0
315+
%r = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
316+
ret <4 x float> %r
317+
}
318+
319+
; TODO: Insert scalar into some element of a dummy vector, then move it to a different element in another vector.
320+
321+
define <4 x float> @insert_shuffle_translate(float %x, <4 x float> %y) {
322+
; CHECK-LABEL: @insert_shuffle_translate(
323+
; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
324+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> [[Y:%.*]], <4 x i32> <i32 4, i32 0, i32 6, i32 7>
325+
; CHECK-NEXT: ret <4 x float> [[R]]
326+
;
327+
%xv = insertelement <4 x float> undef, float %x, i32 0
328+
%r = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 4, i32 0, i32 6, i32 7>
329+
ret <4 x float> %r
330+
}
331+
332+
; TODO: The vector operand of the insert is irrelevant.
333+
334+
define <4 x float> @insert_not_undef_shuffle_translate(float %x, <4 x float> %y, <4 x float> %q) {
335+
; CHECK-LABEL: @insert_not_undef_shuffle_translate(
336+
; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 3
337+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> [[Y:%.*]], <4 x i32> <i32 4, i32 5, i32 3, i32 7>
338+
; CHECK-NEXT: ret <4 x float> [[R]]
339+
;
340+
%xv = insertelement <4 x float> %q, float %x, i32 3
341+
%r = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 4, i32 5, i32 3, i32 7>
342+
ret <4 x float> %r
343+
}
344+
345+
; TODO: The insert may be the 2nd operand of the shuffle. The shuffle mask can include undef elements.
346+
347+
define <4 x float> @insert_not_undef_shuffle_translate_commute(float %x, <4 x float> %y, <4 x float> %q) {
348+
; CHECK-LABEL: @insert_not_undef_shuffle_translate_commute(
349+
; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 2
350+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[XV]], <4 x i32> <i32 0, i32 6, i32 2, i32 undef>
351+
; CHECK-NEXT: ret <4 x float> [[R]]
352+
;
353+
%xv = insertelement <4 x float> %q, float %x, i32 2
354+
%r = shufflevector <4 x float> %y, <4 x float> %xv, <4 x i32> <i32 0, i32 6, i32 2, i32 undef>
355+
ret <4 x float> %r
356+
}
357+
358+
; TODO: Both shuffle operands may be inserts - choose the correct side.
359+
360+
define <4 x float> @insert_insert_shuffle_translate(float %x1, float %x2, <4 x float> %q) {
361+
; CHECK-LABEL: @insert_insert_shuffle_translate(
362+
; CHECK-NEXT: [[XV1:%.*]] = insertelement <4 x float> undef, float [[X1:%.*]], i32 0
363+
; CHECK-NEXT: [[XV2:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X2:%.*]], i32 2
364+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV1]], <4 x float> [[XV2]], <4 x i32> <i32 4, i32 0, i32 6, i32 7>
365+
; CHECK-NEXT: ret <4 x float> [[R]]
366+
;
367+
%xv1 = insertelement <4 x float> %q, float %x1, i32 0
368+
%xv2 = insertelement <4 x float> %q, float %x2, i32 2
369+
%r = shufflevector <4 x float> %xv1, <4 x float> %xv2, <4 x i32> <i32 4, i32 0, i32 6, i32 7>
370+
ret <4 x float> %r
371+
}
372+
373+
; TODO: Both shuffle operands may be inserts - choose the correct side.
374+
375+
define <4 x float> @insert_insert_shuffle_translate_commute(float %x1, float %x2, <4 x float> %q) {
376+
; CHECK-LABEL: @insert_insert_shuffle_translate_commute(
377+
; CHECK-NEXT: [[XV1:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X1:%.*]], i32 0
378+
; CHECK-NEXT: [[XV2:%.*]] = insertelement <4 x float> undef, float [[X2:%.*]], i32 2
379+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV1]], <4 x float> [[XV2]], <4 x i32> <i32 0, i32 6, i32 2, i32 3>
380+
; CHECK-NEXT: ret <4 x float> [[R]]
381+
;
382+
%xv1 = insertelement <4 x float> %q, float %x1, i32 0
383+
%xv2 = insertelement <4 x float> %q, float %x2, i32 2
384+
%r = shufflevector <4 x float> %xv1, <4 x float> %xv2, <4 x i32> <i32 0, i32 6, i32 2, i32 3>
385+
ret <4 x float> %r
386+
}
387+
388+
define <4 x float> @insert_insert_shuffle_translate_wrong_mask(float %x1, float %x2, <4 x float> %q) {
389+
; CHECK-LABEL: @insert_insert_shuffle_translate_wrong_mask(
390+
; CHECK-NEXT: [[XV1:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X1:%.*]], i32 0
391+
; CHECK-NEXT: [[XV2:%.*]] = insertelement <4 x float> [[Q]], float [[X2:%.*]], i32 2
392+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV1]], <4 x float> [[XV2]], <4 x i32> <i32 0, i32 6, i32 2, i32 7>
393+
; CHECK-NEXT: ret <4 x float> [[R]]
394+
;
395+
%xv1 = insertelement <4 x float> %q, float %x1, i32 0
396+
%xv2 = insertelement <4 x float> %q, float %x2, i32 2
397+
%r = shufflevector <4 x float> %xv1, <4 x float> %xv2, <4 x i32> <i32 0, i32 6, i32 2, i32 7>
398+
ret <4 x float> %r
399+
}
400+
401+
; TODO: The insert may have other uses.
402+
403+
declare void @use(<4 x float>)
404+
405+
define <4 x float> @insert_not_undef_shuffle_translate_commute_uses(float %x, <4 x float> %y, <4 x float> %q) {
406+
; CHECK-LABEL: @insert_not_undef_shuffle_translate_commute_uses(
407+
; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X:%.*]], i32 2
408+
; CHECK-NEXT: call void @use(<4 x float> [[XV]])
409+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[XV]], <4 x i32> <i32 6, i32 undef, i32 2, i32 3>
410+
; CHECK-NEXT: ret <4 x float> [[R]]
411+
;
412+
%xv = insertelement <4 x float> %q, float %x, i32 2
413+
call void @use(<4 x float> %xv)
414+
%r = shufflevector <4 x float> %y, <4 x float> %xv, <4 x i32> <i32 6, i32 undef, i32 2, i32 3>
415+
ret <4 x float> %r
416+
}
417+
418+
define <5 x float> @insert_not_undef_shuffle_translate_commute_lengthen(float %x, <4 x float> %y, <4 x float> %q) {
419+
; CHECK-LABEL: @insert_not_undef_shuffle_translate_commute_lengthen(
420+
; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 2
421+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[XV]], <5 x i32> <i32 0, i32 6, i32 2, i32 undef, i32 undef>
422+
; CHECK-NEXT: ret <5 x float> [[R]]
423+
;
424+
%xv = insertelement <4 x float> %q, float %x, i32 2
425+
%r = shufflevector <4 x float> %y, <4 x float> %xv, <5 x i32> <i32 0, i32 6, i32 2, i32 undef, i32 undef>
426+
ret <5 x float> %r
427+
}
428+

0 commit comments

Comments
 (0)