1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=slp-vectorizer,instcombine -S -o - -mtriple=x86_64-unknown-linux -mcpu=bdver2 | FileCheck %s
4 define <2 x i8> @g(<2 x i8> %x, <2 x i8> %y) {
6 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 3>
7 ; CHECK-NEXT: [[TMP2:%.*]] = mul <2 x i8> [[TMP1]], [[TMP1]]
8 ; CHECK-NEXT: ret <2 x i8> [[TMP2]]
10 %x0 = extractelement <2 x i8> %x, i32 0
11 %y1 = extractelement <2 x i8> %y, i32 1
12 %x0x0 = mul i8 %x0, %x0
13 %y1y1 = mul i8 %y1, %y1
14 %ins1 = insertelement <2 x i8> undef, i8 %x0x0, i32 0
15 %ins2 = insertelement <2 x i8> %ins1, i8 %y1y1, i32 1
19 define <4 x i8> @h(<4 x i8> %x, <4 x i8> %y) {
21 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> <i32 0, i32 3, i32 5, i32 6>
22 ; CHECK-NEXT: [[TMP2:%.*]] = mul <4 x i8> [[TMP1]], [[TMP1]]
23 ; CHECK-NEXT: ret <4 x i8> [[TMP2]]
25 %x0 = extractelement <4 x i8> %x, i32 0
26 %x3 = extractelement <4 x i8> %x, i32 3
27 %y1 = extractelement <4 x i8> %y, i32 1
28 %y2 = extractelement <4 x i8> %y, i32 2
29 %x0x0 = mul i8 %x0, %x0
30 %x3x3 = mul i8 %x3, %x3
31 %y1y1 = mul i8 %y1, %y1
32 %y2y2 = mul i8 %y2, %y2
33 %ins1 = insertelement <4 x i8> undef, i8 %x0x0, i32 0
34 %ins2 = insertelement <4 x i8> %ins1, i8 %x3x3, i32 1
35 %ins3 = insertelement <4 x i8> %ins2, i8 %y1y1, i32 2
36 %ins4 = insertelement <4 x i8> %ins3, i8 %y2y2, i32 3
40 define <4 x i8> @h_undef(<4 x i8> %x, <4 x i8> %y) {
41 ; CHECK-LABEL: @h_undef(
42 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> <i8 undef, i8 poison, i8 poison, i8 poison>, <4 x i32> <i32 4, i32 3, i32 poison, i32 poison>
43 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> [[Y:%.*]], <4 x i32> <i32 0, i32 1, i32 5, i32 6>
44 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i8> [[TMP2]], [[TMP2]]
45 ; CHECK-NEXT: ret <4 x i8> [[TMP3]]
47 %x0 = extractelement <4 x i8> undef, i32 0
48 %x3 = extractelement <4 x i8> %x, i32 3
49 %y1 = extractelement <4 x i8> %y, i32 1
50 %y2 = extractelement <4 x i8> %y, i32 2
51 %x0x0 = mul i8 %x0, %x0
52 %x3x3 = mul i8 %x3, %x3
53 %y1y1 = mul i8 %y1, %y1
54 %y2y2 = mul i8 %y2, %y2
55 %ins1 = insertelement <4 x i8> undef, i8 %x0x0, i32 0
56 %ins2 = insertelement <4 x i8> %ins1, i8 %x3x3, i32 1
57 %ins3 = insertelement <4 x i8> %ins2, i8 %y1y1, i32 2
58 %ins4 = insertelement <4 x i8> %ins3, i8 %y2y2, i32 3
62 define i8 @i(<4 x i8> %x, <4 x i8> %y) {
64 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> <i32 0, i32 3, i32 5, i32 6>
65 ; CHECK-NEXT: [[TMP2:%.*]] = mul <4 x i8> [[TMP1]], [[TMP1]]
66 ; CHECK-NEXT: [[TMP3:%.*]] = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> [[TMP2]])
67 ; CHECK-NEXT: ret i8 [[TMP3]]
69 %x0 = extractelement <4 x i8> %x, i32 0
70 %x3 = extractelement <4 x i8> %x, i32 3
71 %y1 = extractelement <4 x i8> %y, i32 1
72 %y2 = extractelement <4 x i8> %y, i32 2
73 %x0x0 = mul i8 %x0, %x0
74 %x3x3 = mul i8 %x3, %x3
75 %y1y1 = mul i8 %y1, %y1
76 %y2y2 = mul i8 %y2, %y2
77 %1 = add i8 %x0x0, %x3x3
78 %2 = add i8 %y1y1, %y2y2
83 define i8 @j(<4 x i8> %x, <4 x i8> %y) {
85 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 5>
86 ; CHECK-NEXT: [[TMP2:%.*]] = mul <2 x i8> [[TMP1]], [[TMP1]]
87 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[Y]], <2 x i32> <i32 3, i32 6>
88 ; CHECK-NEXT: [[TMP4:%.*]] = mul <2 x i8> [[TMP3]], [[TMP3]]
89 ; CHECK-NEXT: [[TMP5:%.*]] = add <2 x i8> [[TMP2]], [[TMP4]]
90 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x i8> [[TMP5]], i64 0
91 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i8> [[TMP5]], i64 1
92 ; CHECK-NEXT: [[TMP8:%.*]] = sdiv i8 [[TMP6]], [[TMP7]]
93 ; CHECK-NEXT: ret i8 [[TMP8]]
95 %x0 = extractelement <4 x i8> %x, i32 0
96 %x3 = extractelement <4 x i8> %x, i32 3
97 %y1 = extractelement <4 x i8> %y, i32 1
98 %y2 = extractelement <4 x i8> %y, i32 2
99 %x0x0 = mul i8 %x0, %x0
100 %x3x3 = mul i8 %x3, %x3
101 %y1y1 = mul i8 %y1, %y1
102 %y2y2 = mul i8 %y2, %y2
103 %1 = add i8 %x0x0, %x3x3
104 %2 = add i8 %y1y1, %y2y2
109 define i8 @k(<4 x i8> %x) {
111 ; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i8> [[X:%.*]], [[X]]
112 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <2 x i32> <i32 0, i32 1>
113 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i8> [[X]], [[X]]
114 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x i8> [[TMP3]], <4 x i8> poison, <2 x i32> <i32 2, i32 3>
115 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i8> [[TMP4]], <2 x i8> poison, <2 x i32> <i32 1, i32 0>
116 ; CHECK-NEXT: [[TMP6:%.*]] = add <2 x i8> [[TMP2]], [[TMP5]]
117 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i8> [[TMP6]], i64 0
118 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i8> [[TMP6]], i64 1
119 ; CHECK-NEXT: [[TMP9:%.*]] = sdiv i8 [[TMP7]], [[TMP8]]
120 ; CHECK-NEXT: ret i8 [[TMP9]]
122 %x0 = extractelement <4 x i8> %x, i32 0
123 %x3 = extractelement <4 x i8> %x, i32 3
124 %x1 = extractelement <4 x i8> %x, i32 1
125 %x2 = extractelement <4 x i8> %x, i32 2
126 %x0x0 = mul i8 %x0, %x0
127 %x3x3 = mul i8 %x3, %x3
128 %x1x1 = mul i8 %x1, %x1
129 %x2x2 = mul i8 %x2, %x2
130 %1 = add i8 %x0x0, %x3x3
131 %2 = add i8 %x1x1, %x2x2
136 define i8 @k_bb(<4 x i8> %x) {
137 ; CHECK-LABEL: @k_bb(
138 ; CHECK-NEXT: br label [[BB1:%.*]]
140 ; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i8> [[X:%.*]], [[X]]
141 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <2 x i32> <i32 0, i32 1>
142 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i8> [[X]], [[X]]
143 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x i8> [[TMP3]], <4 x i8> poison, <2 x i32> <i32 2, i32 3>
144 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i8> [[TMP4]], <2 x i8> poison, <2 x i32> <i32 1, i32 0>
145 ; CHECK-NEXT: [[TMP6:%.*]] = add <2 x i8> [[TMP2]], [[TMP5]]
146 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i8> [[TMP6]], i64 0
147 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i8> [[TMP6]], i64 1
148 ; CHECK-NEXT: [[TMP9:%.*]] = sdiv i8 [[TMP7]], [[TMP8]]
149 ; CHECK-NEXT: ret i8 [[TMP9]]
151 %x0 = extractelement <4 x i8> %x, i32 0
154 %x3 = extractelement <4 x i8> %x, i32 3
155 %x1 = extractelement <4 x i8> %x, i32 1
156 %x2 = extractelement <4 x i8> %x, i32 2
157 %x0x0 = mul i8 %x0, %x0
158 %x3x3 = mul i8 %x3, %x3
159 %x1x1 = mul i8 %x1, %x1
160 %x2x2 = mul i8 %x2, %x2
161 %1 = add i8 %x0x0, %x3x3
162 %2 = add i8 %x1x1, %x2x2