1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
4 define <4 x i32> @const_folding(<4 x i32> %x) {
5 ; CHECK-LABEL: @const_folding(
6 ; CHECK-NEXT: ret <4 x i32> zeroinitializer
8 %shuf = shufflevector <4 x i32> %x, <4 x i32> zeroinitializer, <4 x i32> <i32 5, i32 4, i32 5, i32 4>
12 define <4 x i32> @const_folding1(<4 x i32> %x) {
13 ; CHECK-LABEL: @const_folding1(
14 ; CHECK-NEXT: ret <4 x i32> <i32 5, i32 5, i32 5, i32 5>
16 %shuf = shufflevector <4 x i32> <i32 5, i32 4, i32 5, i32 4>, <4 x i32> %x, <4 x i32> zeroinitializer
20 define <4 x i32> @const_folding_negative(<3 x i32> %x) {
21 ; CHECK-LABEL: @const_folding_negative(
22 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i32> [[X:%.*]], <3 x i32> zeroinitializer, <4 x i32> <i32 2, i32 4, i32 5, i32 4>
23 ; CHECK-NEXT: ret <4 x i32> [[SHUF]]
25 %shuf = shufflevector <3 x i32> %x, <3 x i32> zeroinitializer, <4 x i32> <i32 2, i32 4, i32 5, i32 4>
29 define <4 x i32> @splat_operand(<4 x i32> %x) {
30 ; CHECK-LABEL: @splat_operand(
31 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
32 ; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
34 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
35 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
39 define <4 x i32> @splat_operand1(<4 x i32> %x, <4 x i32> %y) {
40 ; CHECK-LABEL: @splat_operand1(
41 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]], <4 x i32> zeroinitializer
42 ; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
44 %splat = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> zeroinitializer
45 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
49 define <4 x i32> @splat_operand2(<4 x i32> %x, <4 x i32> %y) {
50 ; CHECK-LABEL: @splat_operand2(
51 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
52 ; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
54 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
55 %shuf = shufflevector <4 x i32> %splat, <4 x i32> %y, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
59 define <4 x i32> @splat_operand3(<4 x i32> %x) {
60 ; CHECK-LABEL: @splat_operand3(
61 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
62 ; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
64 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
65 %shuf = shufflevector <4 x i32> zeroinitializer, <4 x i32> %splat, <4 x i32> <i32 7, i32 6, i32 5, i32 5>
69 define <8 x i32> @splat_operand_negative(<4 x i32> %x) {
70 ; CHECK-LABEL: @splat_operand_negative(
71 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
72 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <8 x i32> <i32 0, i32 3, i32 2, i32 1, i32 undef, i32 undef, i32 undef, i32 undef>
73 ; CHECK-NEXT: ret <8 x i32> [[SHUF]]
75 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
76 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <8 x i32> <i32 0, i32 3, i32 2, i32 1, i32 undef, i32 undef, i32 undef, i32 undef>
80 define <4 x i32> @splat_operand_negative2(<4 x i32> %x, <4 x i32> %y) {
81 ; CHECK-LABEL: @splat_operand_negative2(
82 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
83 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> [[Y:%.*]], <4 x i32> <i32 0, i32 3, i32 4, i32 1>
84 ; CHECK-NEXT: ret <4 x i32> [[SHUF]]
86 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
87 %shuf = shufflevector <4 x i32> %splat, <4 x i32> %y, <4 x i32> <i32 0, i32 3, i32 4, i32 1>
91 define <4 x i32> @splat_operand_negative3(<4 x i32> %x, <4 x i32> %y) {
92 ; CHECK-LABEL: @splat_operand_negative3(
93 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
94 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[Y:%.*]], <4 x i32> [[SPLAT]], <4 x i32> <i32 0, i32 3, i32 4, i32 1>
95 ; CHECK-NEXT: ret <4 x i32> [[SHUF]]
97 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
98 %shuf = shufflevector <4 x i32> %y, <4 x i32> %splat, <4 x i32> <i32 0, i32 3, i32 4, i32 1>
102 define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {
103 ; CHECK-LABEL: @splat_operand_negative4(
104 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> <i32 2, i32 undef, i32 2, i32 undef>
105 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
106 ; CHECK-NEXT: ret <4 x i32> [[SHUF]]
108 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 2, i32 undef, i32 2, i32 undef>
109 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
113 define <4 x i32> @undef_mask(<4 x i32> %x) {
114 ; CHECK-LABEL: @undef_mask(
115 ; CHECK-NEXT: ret <4 x i32> undef
117 %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef
121 define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
122 ; CHECK-LABEL: @undef_mask_1(
123 ; CHECK-NEXT: ret <4 x i32> undef
125 %shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef
129 define <4 x i32> @identity_mask_0(<4 x i32> %x) {
130 ; CHECK-LABEL: @identity_mask_0(
131 ; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
133 %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
137 define <4 x i32> @identity_mask_1(<4 x i32> %x) {
138 ; CHECK-LABEL: @identity_mask_1(
139 ; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
141 %shuf = shufflevector <4 x i32> undef, <4 x i32> %x, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
145 define <4 x i32> @pseudo_identity_mask(<4 x i32> %x) {
146 ; CHECK-LABEL: @pseudo_identity_mask(
147 ; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
149 %shuf = shufflevector <4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
153 define <4 x i32> @not_identity_mask(<4 x i32> %x) {
154 ; CHECK-LABEL: @not_identity_mask(
155 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[X]], <4 x i32> <i32 0, i32 1, i32 2, i32 6>
156 ; CHECK-NEXT: ret <4 x i32> [[SHUF]]
158 %shuf = shufflevector <4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 2, i32 6>
162 ; TODO: Should we simplify if the mask has an undef element?
164 define <4 x i32> @possible_identity_mask(<4 x i32> %x) {
165 ; CHECK-LABEL: @possible_identity_mask(
166 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
167 ; CHECK-NEXT: ret <4 x i32> [[SHUF]]
169 %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
173 define <4 x i32> @const_operand(<4 x i32> %x) {
174 ; CHECK-LABEL: @const_operand(
175 ; CHECK-NEXT: ret <4 x i32> <i32 42, i32 45, i32 44, i32 43>
177 %shuf = shufflevector <4 x i32> <i32 42, i32 43, i32 44, i32 45>, <4 x i32> %x, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
181 define <4 x i32> @merge(<4 x i32> %x) {
182 ; CHECK-LABEL: @merge(
183 ; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
185 %lower = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 1, i32 0>
186 %upper = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3>
187 %merged = shufflevector <2 x i32> %upper, <2 x i32> %lower, <4 x i32> <i32 3, i32 2, i32 0, i32 1>
188 ret <4 x i32> %merged
191 ; This crosses lanes from the source op.
193 define <4 x i32> @not_merge(<4 x i32> %x) {
194 ; CHECK-LABEL: @not_merge(
195 ; CHECK-NEXT: [[L:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <2 x i32> <i32 0, i32 1>
196 ; CHECK-NEXT: [[U:%.*]] = shufflevector <4 x i32> [[X]], <4 x i32> undef, <2 x i32> <i32 2, i32 3>
197 ; CHECK-NEXT: [[MERGED:%.*]] = shufflevector <2 x i32> [[U]], <2 x i32> [[L]], <4 x i32> <i32 3, i32 2, i32 0, i32 1>
198 ; CHECK-NEXT: ret <4 x i32> [[MERGED]]
200 %l = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 0, i32 1>
201 %u = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3>
202 %merged = shufflevector <2 x i32> %u, <2 x i32> %l, <4 x i32> <i32 3, i32 2, i32 0, i32 1>
203 ret <4 x i32> %merged
206 define <8 x double> @extract_and_concat(<8 x double> %x) {
207 ; CHECK-LABEL: @extract_and_concat(
208 ; CHECK-NEXT: ret <8 x double> [[X:%.*]]
210 %s1 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 0, i32 1>
211 %s2 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 2, i32 3>
212 %s3 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 4, i32 5>
213 %s4 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 6, i32 7>
214 %s5 = shufflevector <2 x double> %s1, <2 x double> %s2, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
215 %s6 = shufflevector <2 x double> %s3, <2 x double> %s4, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
216 %s7 = shufflevector <4 x double> %s5, <4 x double> %s6, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
220 ; This case has intermediate lane crossings.
222 define <8 x i64> @PR30630(<8 x i64> %x) {
223 ; CHECK-LABEL: @PR30630(
224 ; CHECK-NEXT: ret <8 x i64> [[X:%.*]]
226 %s1 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 0, i32 4>
227 %s2 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 1, i32 5>
228 %s3 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 2, i32 6>
229 %s4 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 3, i32 7>
230 %s5 = shufflevector <2 x i64> %s1, <2 x i64> %s2, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
231 %s6 = shufflevector <2 x i64> %s3, <2 x i64> %s4, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
232 %s7 = shufflevector <4 x i64> %s5, <4 x i64> %s6, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 1, i32 3, i32 5, i32 7>
236 ; This case covers internal canonicalization of shuffles with one constant input vector.
238 ;FIXME: Another issue exposed here, this whole function could be simplified to:
239 ; ret <2 x float> zeroinitializer
240 define <2 x float> @PR32872(<2 x float> %x) {
241 ; CHECK-LABEL: @PR32872(
242 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> zeroinitializer, <4 x i32> <i32 2, i32 2, i32 0, i32 1>
243 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x float> zeroinitializer, <4 x float> [[TMP1]], <2 x i32> <i32 4, i32 5>
244 ; CHECK-NEXT: ret <2 x float> [[TMP4]]
246 %tmp1 = shufflevector <2 x float> %x, <2 x float> zeroinitializer, <4 x i32> <i32 2, i32 2, i32 0, i32 1>
247 %tmp4 = shufflevector <4 x float> zeroinitializer, <4 x float> %tmp1, <2 x i32> <i32 4, i32 5>
248 ret <2 x float> %tmp4