1 ; RUN: opt -S -instcombine %s | FileCheck %s
3 define <1 x i8> @test1(<8 x i8> %in) {
5 ; CHECK: shufflevector <8 x i8> %in, <8 x i8> undef, <1 x i32> <i32 5>
6 %val = extractelement <8 x i8> %in, i32 5
7 %vec = insertelement <1 x i8> undef, i8 %val, i32 0
11 define <4 x i16> @test2(<8 x i16> %in, <8 x i16> %in2) {
13 ; CHECK: shufflevector <8 x i16> %in2, <8 x i16> %in, <4 x i32> <i32 11, i32 9, i32 0, i32 10>
14 %elt0 = extractelement <8 x i16> %in, i32 3
15 %elt1 = extractelement <8 x i16> %in, i32 1
16 %elt2 = extractelement <8 x i16> %in2, i32 0
17 %elt3 = extractelement <8 x i16> %in, i32 2
19 %vec.0 = insertelement <4 x i16> undef, i16 %elt0, i32 0
20 %vec.1 = insertelement <4 x i16> %vec.0, i16 %elt1, i32 1
21 %vec.2 = insertelement <4 x i16> %vec.1, i16 %elt2, i32 2
22 %vec.3 = insertelement <4 x i16> %vec.2, i16 %elt3, i32 3
27 define <2 x i64> @test_vcopyq_lane_p64(<2 x i64> %a, <1 x i64> %b) {
28 ; CHECK-LABEL: @test_vcopyq_lane_p64
29 ; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <1 x i64> %b, <1 x i64> undef, <2 x i32> <i32 0, i32 undef>
30 ; CHECK-NEXT: shufflevector <2 x i64> %a, <2 x i64> %[[WIDEVEC]], <2 x i32> <i32 0, i32 2>
31 ; CHECK-NEXT: ret <2 x i64> %res
32 %elt = extractelement <1 x i64> %b, i32 0
33 %res = insertelement <2 x i64> %a, i64 %elt, i32 1
37 ; PR2109: https://llvm.org/bugs/show_bug.cgi?id=2109
39 define <4 x float> @widen_extract2(<4 x float> %ins, <2 x float> %ext) {
40 ; CHECK-LABEL: @widen_extract2(
41 ; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <2 x float> %ext, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
42 ; CHECK-NEXT: shufflevector <4 x float> %ins, <4 x float> %[[WIDEVEC]], <4 x i32> <i32 0, i32 4, i32 2, i32 5>
43 ; CHECK-NEXT: ret <4 x float> %i2
44 %e1 = extractelement <2 x float> %ext, i32 0
45 %e2 = extractelement <2 x float> %ext, i32 1
46 %i1 = insertelement <4 x float> %ins, float %e1, i32 1
47 %i2 = insertelement <4 x float> %i1, float %e2, i32 3
51 define <4 x float> @widen_extract3(<4 x float> %ins, <3 x float> %ext) {
52 ; CHECK-LABEL: @widen_extract3(
53 ; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <3 x float> %ext, <3 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
54 ; CHECK-NEXT: shufflevector <4 x float> %ins, <4 x float> %[[WIDEVEC]], <4 x i32> <i32 6, i32 5, i32 4, i32 3>
55 ; CHECK-NEXT: ret <4 x float> %i3
56 %e1 = extractelement <3 x float> %ext, i32 0
57 %e2 = extractelement <3 x float> %ext, i32 1
58 %e3 = extractelement <3 x float> %ext, i32 2
59 %i1 = insertelement <4 x float> %ins, float %e1, i32 2
60 %i2 = insertelement <4 x float> %i1, float %e2, i32 1
61 %i3 = insertelement <4 x float> %i2, float %e3, i32 0
65 define <8 x float> @widen_extract4(<8 x float> %ins, <2 x float> %ext) {
66 ; CHECK-LABEL: @widen_extract4(
67 ; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <2 x float> %ext, <2 x float> undef, <8 x i32> <i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
68 ; CHECK-NEXT: shufflevector <8 x float> %ins, <8 x float> %[[WIDEVEC]], <8 x i32> <i32 0, i32 1, i32 8, i32 3, i32 4, i32 5, i32 6, i32 7>
69 ; CHECK-NEXT: ret <8 x float> %i1
70 %e1 = extractelement <2 x float> %ext, i32 0
71 %i1 = insertelement <8 x float> %ins, float %e1, i32 2
75 ; PR26015: https://llvm.org/bugs/show_bug.cgi?id=26015
76 ; The widening shuffle must be inserted before any uses.
78 define <8 x i16> @pr26015(<4 x i16> %t0) {
79 ; CHECK-LABEL: @pr26015(
80 ; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <4 x i16> %t0, <4 x i16> undef, <8 x i32> <i32 undef, i32 undef, i32 undef, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
81 ; CHECK-NEXT: %[[EXT:.*]] = extractelement <4 x i16> %t0, i32 2
82 ; CHECK-NEXT: %t2 = insertelement <8 x i16> <i16 0, i16 0, i16 0, i16 undef, i16 0, i16 0, i16 undef, i16 undef>, i16 %[[EXT]], i32 3
83 ; CHECK-NEXT: %t3 = insertelement <8 x i16> %t2, i16 0, i32 6
84 ; CHECK-NEXT: %t5 = shufflevector <8 x i16> %t3, <8 x i16> %[[WIDEVEC]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 11>
85 ; CHECK-NEXT: ret <8 x i16> %t5
86 %t1 = extractelement <4 x i16> %t0, i32 2
87 %t2 = insertelement <8 x i16> zeroinitializer, i16 %t1, i32 3
88 %t3 = insertelement <8 x i16> %t2, i16 0, i32 6
89 %t4 = extractelement <4 x i16> %t0, i32 3
90 %t5 = insertelement <8 x i16> %t3, i16 %t4, i32 7
94 ; PR25999: https://llvm.org/bugs/show_bug.cgi?id=25999
95 ; TODO: The widening shuffle could be inserted at the start of the function to allow the first extract to use it.
97 define <8 x i16> @pr25999(<4 x i16> %t0, i1 %b) {
98 ; CHECK-LABEL: @pr25999(
99 ; CHECK-NEXT: %t1 = extractelement <4 x i16> %t0, i32 2
100 ; CHECK-NEXT: br i1 %b, label %if, label %end
102 ; CHECK-NEXT: %[[WIDEVEC:.*]] = shufflevector <4 x i16> %t0, <4 x i16> undef, <8 x i32> <i32 undef, i32 undef, i32 undef, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
103 ; CHECK-NEXT: %t2 = insertelement <8 x i16> <i16 0, i16 0, i16 0, i16 undef, i16 0, i16 0, i16 undef, i16 undef>, i16 %t1, i32 3
104 ; CHECK-NEXT: %t3 = insertelement <8 x i16> %t2, i16 0, i32 6
105 ; CHECK-NEXT: %t5 = shufflevector <8 x i16> %t3, <8 x i16> %[[WIDEVEC]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 11>
106 ; CHECK-NEXT: ret <8 x i16> %t5
108 ; CHECK-NEXT: %a1 = add i16 %t1, 4
109 ; CHECK-NEXT: %t6 = insertelement <8 x i16> <i16 undef, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, i16 %a1, i32 0
110 ; CHECK-NEXT: ret <8 x i16> %t6
112 %t1 = extractelement <4 x i16> %t0, i32 2
113 br i1 %b, label %if, label %end
116 %t2 = insertelement <8 x i16> zeroinitializer, i16 %t1, i32 3
117 %t3 = insertelement <8 x i16> %t2, i16 0, i32 6
118 %t4 = extractelement <4 x i16> %t0, i32 3
119 %t5 = insertelement <8 x i16> %t3, i16 %t4, i32 7
124 %t6 = insertelement <8 x i16> zeroinitializer, i16 %a1, i32 0