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> poison, 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> poison, 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> [[Y:%.*]], <4 x i32> <i32 poison, i32 3, i32 5, i32 6>
43 ; CHECK-NEXT: [[TMP2:%.*]] = mul <4 x i8> [[TMP1]], [[TMP1]]
44 ; CHECK-NEXT: ret <4 x i8> [[TMP2]]
46 %x0 = extractelement <4 x i8> poison, i32 0
47 %x3 = extractelement <4 x i8> %x, i32 3
48 %y1 = extractelement <4 x i8> %y, i32 1
49 %y2 = extractelement <4 x i8> %y, i32 2
50 %x0x0 = mul i8 %x0, %x0
51 %x3x3 = mul i8 %x3, %x3
52 %y1y1 = mul i8 %y1, %y1
53 %y2y2 = mul i8 %y2, %y2
54 %ins1 = insertelement <4 x i8> poison, i8 %x0x0, i32 0
55 %ins2 = insertelement <4 x i8> %ins1, i8 %x3x3, i32 1
56 %ins3 = insertelement <4 x i8> %ins2, i8 %y1y1, i32 2
57 %ins4 = insertelement <4 x i8> %ins3, i8 %y2y2, i32 3
61 define i8 @i(<4 x i8> %x, <4 x i8> %y) {
63 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> <i32 0, i32 3, i32 5, i32 6>
64 ; CHECK-NEXT: [[TMP2:%.*]] = mul <4 x i8> [[TMP1]], [[TMP1]]
65 ; CHECK-NEXT: [[TMP3:%.*]] = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> [[TMP2]])
66 ; CHECK-NEXT: ret i8 [[TMP3]]
68 %x0 = extractelement <4 x i8> %x, i32 0
69 %x3 = extractelement <4 x i8> %x, i32 3
70 %y1 = extractelement <4 x i8> %y, i32 1
71 %y2 = extractelement <4 x i8> %y, i32 2
72 %x0x0 = mul i8 %x0, %x0
73 %x3x3 = mul i8 %x3, %x3
74 %y1y1 = mul i8 %y1, %y1
75 %y2y2 = mul i8 %y2, %y2
76 %1 = add i8 %x0x0, %x3x3
77 %2 = add i8 %y1y1, %y2y2
82 define i8 @j(<4 x i8> %x, <4 x i8> %y) {
84 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 5>
85 ; CHECK-NEXT: [[TMP2:%.*]] = mul <2 x i8> [[TMP1]], [[TMP1]]
86 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[Y]], <2 x i32> <i32 3, i32 6>
87 ; CHECK-NEXT: [[TMP4:%.*]] = mul <2 x i8> [[TMP3]], [[TMP3]]
88 ; CHECK-NEXT: [[TMP5:%.*]] = add <2 x i8> [[TMP2]], [[TMP4]]
89 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x i8> [[TMP5]], i64 0
90 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i8> [[TMP5]], i64 1
91 ; CHECK-NEXT: [[TMP8:%.*]] = sdiv i8 [[TMP6]], [[TMP7]]
92 ; CHECK-NEXT: ret i8 [[TMP8]]
94 %x0 = extractelement <4 x i8> %x, i32 0
95 %x3 = extractelement <4 x i8> %x, i32 3
96 %y1 = extractelement <4 x i8> %y, i32 1
97 %y2 = extractelement <4 x i8> %y, i32 2
98 %x0x0 = mul i8 %x0, %x0
99 %x3x3 = mul i8 %x3, %x3
100 %y1y1 = mul i8 %y1, %y1
101 %y2y2 = mul i8 %y2, %y2
102 %1 = add i8 %x0x0, %x3x3
103 %2 = add i8 %y1y1, %y2y2
108 define i8 @k(<4 x i8> %x) {
110 ; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i8> [[X:%.*]], [[X]]
111 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <2 x i32> <i32 0, i32 1>
112 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i8> [[X]], [[X]]
113 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x i8> [[TMP3]], <4 x i8> poison, <2 x i32> <i32 2, i32 3>
114 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i8> [[TMP4]], <2 x i8> poison, <2 x i32> <i32 1, i32 0>
115 ; CHECK-NEXT: [[TMP6:%.*]] = add <2 x i8> [[TMP2]], [[TMP5]]
116 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i8> [[TMP6]], i64 0
117 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i8> [[TMP6]], i64 1
118 ; CHECK-NEXT: [[TMP9:%.*]] = sdiv i8 [[TMP7]], [[TMP8]]
119 ; CHECK-NEXT: ret i8 [[TMP9]]
121 %x0 = extractelement <4 x i8> %x, i32 0
122 %x3 = extractelement <4 x i8> %x, i32 3
123 %x1 = extractelement <4 x i8> %x, i32 1
124 %x2 = extractelement <4 x i8> %x, i32 2
125 %x0x0 = mul i8 %x0, %x0
126 %x3x3 = mul i8 %x3, %x3
127 %x1x1 = mul i8 %x1, %x1
128 %x2x2 = mul i8 %x2, %x2
129 %1 = add i8 %x0x0, %x3x3
130 %2 = add i8 %x1x1, %x2x2
135 define i8 @k_bb(<4 x i8> %x) {
136 ; CHECK-LABEL: @k_bb(
137 ; CHECK-NEXT: br label [[BB1:%.*]]
139 ; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i8> [[X:%.*]], [[X]]
140 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x i8> poison, <2 x i32> <i32 0, i32 1>
141 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i8> [[X]], [[X]]
142 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x i8> [[TMP3]], <4 x i8> poison, <2 x i32> <i32 2, i32 3>
143 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i8> [[TMP4]], <2 x i8> poison, <2 x i32> <i32 1, i32 0>
144 ; CHECK-NEXT: [[TMP6:%.*]] = add <2 x i8> [[TMP2]], [[TMP5]]
145 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i8> [[TMP6]], i64 0
146 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i8> [[TMP6]], i64 1
147 ; CHECK-NEXT: [[TMP9:%.*]] = sdiv i8 [[TMP7]], [[TMP8]]
148 ; CHECK-NEXT: ret i8 [[TMP9]]
150 %x0 = extractelement <4 x i8> %x, i32 0
153 %x3 = extractelement <4 x i8> %x, i32 3
154 %x1 = extractelement <4 x i8> %x, i32 1
155 %x2 = extractelement <4 x i8> %x, i32 2
156 %x0x0 = mul i8 %x0, %x0
157 %x3x3 = mul i8 %x3, %x3
158 %x1x1 = mul i8 %x1, %x1
159 %x2x2 = mul i8 %x2, %x2
160 %1 = add i8 %x0x0, %x3x3
161 %2 = add i8 %x1x1, %x2x2