vec_shuffle.ll 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. define <4 x float> @test1(<4 x float> %v1) {
  3. ; CHECK-LABEL: @test1(
  4. ; CHECK: ret <4 x float> %v1
  5. %v2 = shufflevector <4 x float> %v1, <4 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  6. ret <4 x float> %v2
  7. }
  8. define <4 x float> @test2(<4 x float> %v1) {
  9. ; CHECK-LABEL: @test2(
  10. ; CHECK: ret <4 x float> %v1
  11. %v2 = shufflevector <4 x float> %v1, <4 x float> %v1, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
  12. ret <4 x float> %v2
  13. }
  14. define float @test3(<4 x float> %A, <4 x float> %B, float %f) {
  15. ; CHECK-LABEL: @test3(
  16. ; CHECK: ret float %f
  17. %C = insertelement <4 x float> %A, float %f, i32 0
  18. %D = shufflevector <4 x float> %C, <4 x float> %B, <4 x i32> <i32 5, i32 0, i32 2, i32 7>
  19. %E = extractelement <4 x float> %D, i32 1
  20. ret float %E
  21. }
  22. define i32 @test4(<4 x i32> %X) {
  23. ; CHECK-LABEL: @test4(
  24. ; CHECK-NEXT: extractelement
  25. ; CHECK-NEXT: ret
  26. %tmp152.i53899.i = shufflevector <4 x i32> %X, <4 x i32> undef, <4 x i32> zeroinitializer
  27. %tmp34 = extractelement <4 x i32> %tmp152.i53899.i, i32 0
  28. ret i32 %tmp34
  29. }
  30. define i32 @test5(<4 x i32> %X) {
  31. ; CHECK-LABEL: @test5(
  32. ; CHECK-NEXT: extractelement
  33. ; CHECK-NEXT: ret
  34. %tmp152.i53899.i = shufflevector <4 x i32> %X, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 undef, i32 undef>
  35. %tmp34 = extractelement <4 x i32> %tmp152.i53899.i, i32 0
  36. ret i32 %tmp34
  37. }
  38. define float @test6(<4 x float> %X) {
  39. ; CHECK-LABEL: @test6(
  40. ; CHECK-NEXT: extractelement
  41. ; CHECK-NEXT: ret
  42. %X1 = bitcast <4 x float> %X to <4 x i32>
  43. %tmp152.i53899.i = shufflevector <4 x i32> %X1, <4 x i32> undef, <4 x i32> zeroinitializer
  44. %tmp152.i53900.i = bitcast <4 x i32> %tmp152.i53899.i to <4 x float>
  45. %tmp34 = extractelement <4 x float> %tmp152.i53900.i, i32 0
  46. ret float %tmp34
  47. }
  48. define <4 x float> @test7(<4 x float> %tmp45.i) {
  49. ; CHECK-LABEL: @test7(
  50. ; CHECK-NEXT: ret <4 x float> %tmp45.i
  51. %tmp1642.i = shufflevector <4 x float> %tmp45.i, <4 x float> undef, <4 x i32> < i32 0, i32 1, i32 6, i32 7 >
  52. ret <4 x float> %tmp1642.i
  53. }
  54. ; This should turn into a single shuffle.
  55. define <4 x float> @test8(<4 x float> %tmp, <4 x float> %tmp1) {
  56. ; CHECK-LABEL: @test8(
  57. ; CHECK-NEXT: shufflevector
  58. ; CHECK-NEXT: ret
  59. %tmp4 = extractelement <4 x float> %tmp, i32 1
  60. %tmp2 = extractelement <4 x float> %tmp, i32 3
  61. %tmp1.upgrd.1 = extractelement <4 x float> %tmp1, i32 0
  62. %tmp128 = insertelement <4 x float> undef, float %tmp4, i32 0
  63. %tmp130 = insertelement <4 x float> %tmp128, float undef, i32 1
  64. %tmp132 = insertelement <4 x float> %tmp130, float %tmp2, i32 2
  65. %tmp134 = insertelement <4 x float> %tmp132, float %tmp1.upgrd.1, i32 3
  66. ret <4 x float> %tmp134
  67. }
  68. ; Test fold of two shuffles where the first shuffle vectors inputs are a
  69. ; different length then the second.
  70. define <4 x i8> @test9(<16 x i8> %tmp6) nounwind {
  71. ; CHECK-LABEL: @test9(
  72. ; CHECK-NEXT: shufflevector
  73. ; CHECK-NEXT: ret
  74. %tmp7 = shufflevector <16 x i8> %tmp6, <16 x i8> undef, <4 x i32> < i32 13, i32 9, i32 4, i32 13 > ; <<4 x i8>> [#uses=1]
  75. %tmp9 = shufflevector <4 x i8> %tmp7, <4 x i8> undef, <4 x i32> < i32 3, i32 1, i32 2, i32 0 > ; <<4 x i8>> [#uses=1]
  76. ret <4 x i8> %tmp9
  77. }
  78. ; Same as test9, but make sure that "undef" mask values are not confused with
  79. ; mask values of 2*N, where N is the mask length. These shuffles should not
  80. ; be folded (because [8,9,4,8] may not be a mask supported by the target).
  81. define <4 x i8> @test9a(<16 x i8> %tmp6) nounwind {
  82. ; CHECK-LABEL: @test9a(
  83. ; CHECK-NEXT: shufflevector
  84. ; CHECK-NEXT: shufflevector
  85. ; CHECK-NEXT: ret
  86. %tmp7 = shufflevector <16 x i8> %tmp6, <16 x i8> undef, <4 x i32> < i32 undef, i32 9, i32 4, i32 8 > ; <<4 x i8>> [#uses=1]
  87. %tmp9 = shufflevector <4 x i8> %tmp7, <4 x i8> undef, <4 x i32> < i32 3, i32 1, i32 2, i32 0 > ; <<4 x i8>> [#uses=1]
  88. ret <4 x i8> %tmp9
  89. }
  90. ; Test fold of two shuffles where the first shuffle vectors inputs are a
  91. ; different length then the second.
  92. define <4 x i8> @test9b(<4 x i8> %tmp6, <4 x i8> %tmp7) nounwind {
  93. ; CHECK-LABEL: @test9b(
  94. ; CHECK-NEXT: shufflevector
  95. ; CHECK-NEXT: ret
  96. %tmp1 = shufflevector <4 x i8> %tmp6, <4 x i8> %tmp7, <8 x i32> <i32 0, i32 1, i32 4, i32 5, i32 4, i32 5, i32 2, i32 3> ; <<4 x i8>> [#uses=1]
  97. %tmp9 = shufflevector <8 x i8> %tmp1, <8 x i8> undef, <4 x i32> <i32 0, i32 1, i32 4, i32 5> ; <<4 x i8>> [#uses=1]
  98. ret <4 x i8> %tmp9
  99. }
  100. ; Redundant vector splats should be removed. Radar 8597790.
  101. define <4 x i32> @test10(<4 x i32> %tmp5) nounwind {
  102. ; CHECK-LABEL: @test10(
  103. ; CHECK-NEXT: shufflevector
  104. ; CHECK-NEXT: ret
  105. %tmp6 = shufflevector <4 x i32> %tmp5, <4 x i32> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
  106. %tmp7 = shufflevector <4 x i32> %tmp6, <4 x i32> undef, <4 x i32> zeroinitializer
  107. ret <4 x i32> %tmp7
  108. }
  109. ; Test fold of two shuffles where the two shufflevector inputs's op1 are
  110. ; the same
  111. define <8 x i8> @test11(<16 x i8> %tmp6) nounwind {
  112. ; CHECK-LABEL: @test11(
  113. ; CHECK-NEXT: shufflevector <16 x i8> %tmp6, <16 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
  114. ; CHECK-NEXT: ret
  115. %tmp1 = shufflevector <16 x i8> %tmp6, <16 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3> ; <<4 x i8>> [#uses=1]
  116. %tmp2 = shufflevector <16 x i8> %tmp6, <16 x i8> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7> ; <<4 x i8>> [#uses=1]
  117. %tmp3 = shufflevector <4 x i8> %tmp1, <4 x i8> %tmp2, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7> ; <<8 x i8>> [#uses=1]
  118. ret <8 x i8> %tmp3
  119. }
  120. ; Test fold of two shuffles where the first shufflevector's inputs are
  121. ; the same as the second
  122. define <8 x i8> @test12(<8 x i8> %tmp6, <8 x i8> %tmp2) nounwind {
  123. ; CHECK-LABEL: @test12(
  124. ; CHECK-NEXT: shufflevector <8 x i8> %tmp6, <8 x i8> %tmp2, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 9, i32 8, i32 11, i32 12>
  125. ; CHECK-NEXT: ret
  126. %tmp1 = shufflevector <8 x i8> %tmp6, <8 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 5, i32 4, i32 undef, i32 7> ; <<8 x i8>> [#uses=1]
  127. %tmp3 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 9, i32 8, i32 11, i32 12> ; <<8 x i8>> [#uses=1]
  128. ret <8 x i8> %tmp3
  129. }
  130. ; Test fold of two shuffles where the first shufflevector's inputs are
  131. ; the same as the second
  132. define <8 x i8> @test12a(<8 x i8> %tmp6, <8 x i8> %tmp2) nounwind {
  133. ; CHECK-LABEL: @test12a(
  134. ; CHECK-NEXT: shufflevector <8 x i8> %tmp2, <8 x i8> %tmp6, <8 x i32> <i32 0, i32 3, i32 1, i32 4, i32 8, i32 9, i32 10, i32 11>
  135. ; CHECK-NEXT: ret
  136. %tmp1 = shufflevector <8 x i8> %tmp6, <8 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 5, i32 4, i32 undef, i32 7> ; <<8 x i8>> [#uses=1]
  137. %tmp3 = shufflevector <8 x i8> %tmp2, <8 x i8> %tmp1, <8 x i32> <i32 0, i32 3, i32 1, i32 4, i32 8, i32 9, i32 10, i32 11> ; <<8 x i8>> [#uses=1]
  138. ret <8 x i8> %tmp3
  139. }
  140. define <2 x i8> @test13a(i8 %x1, i8 %x2) {
  141. ; CHECK-LABEL: @test13a(
  142. ; CHECK-NEXT: insertelement {{.*}} undef, i8 %x1, i32 1
  143. ; CHECK-NEXT: insertelement {{.*}} i8 %x2, i32 0
  144. ; CHECK-NEXT: add {{.*}} <i8 7, i8 5>
  145. ; CHECK-NEXT: ret
  146. %A = insertelement <2 x i8> undef, i8 %x1, i32 0
  147. %B = insertelement <2 x i8> %A, i8 %x2, i32 1
  148. %C = add <2 x i8> %B, <i8 5, i8 7>
  149. %D = shufflevector <2 x i8> %C, <2 x i8> undef, <2 x i32> <i32 1, i32 0>
  150. ret <2 x i8> %D
  151. }
  152. define <2 x i8> @test13b(i8 %x) {
  153. ; CHECK-LABEL: @test13b(
  154. ; CHECK-NEXT: insertelement <2 x i8> undef, i8 %x, i32 1
  155. ; CHECK-NEXT: ret
  156. %A = insertelement <2 x i8> undef, i8 %x, i32 0
  157. %B = shufflevector <2 x i8> %A, <2 x i8> undef, <2 x i32> <i32 undef, i32 0>
  158. ret <2 x i8> %B
  159. }
  160. define <2 x i8> @test13c(i8 %x1, i8 %x2) {
  161. ; CHECK-LABEL: @test13c(
  162. ; CHECK-NEXT: insertelement <2 x i8> {{.*}}, i32 0
  163. ; CHECK-NEXT: insertelement <2 x i8> {{.*}}, i32 1
  164. ; CHECK-NEXT: ret
  165. %A = insertelement <4 x i8> undef, i8 %x1, i32 0
  166. %B = insertelement <4 x i8> %A, i8 %x2, i32 2
  167. %C = shufflevector <4 x i8> %B, <4 x i8> undef, <2 x i32> <i32 0, i32 2>
  168. ret <2 x i8> %C
  169. }
  170. define void @test14(i16 %conv10) {
  171. %tmp = alloca <4 x i16>, align 8
  172. %vecinit6 = insertelement <4 x i16> undef, i16 23, i32 3
  173. store <4 x i16> %vecinit6, <4 x i16>* undef
  174. %tmp1 = load <4 x i16>, <4 x i16>* undef
  175. %vecinit11 = insertelement <4 x i16> undef, i16 %conv10, i32 3
  176. %div = udiv <4 x i16> %tmp1, %vecinit11
  177. store <4 x i16> %div, <4 x i16>* %tmp
  178. %tmp4 = load <4 x i16>, <4 x i16>* %tmp
  179. %tmp5 = shufflevector <4 x i16> %tmp4, <4 x i16> undef, <2 x i32> <i32 2, i32 0>
  180. %cmp = icmp ule <2 x i16> %tmp5, undef
  181. %sext = sext <2 x i1> %cmp to <2 x i16>
  182. ret void
  183. }
  184. ; Check that sequences of insert/extract element are
  185. ; collapsed into valid shuffle instruction with correct shuffle indexes.
  186. define <4 x float> @test15a(<4 x float> %LHS, <4 x float> %RHS) {
  187. ; CHECK-LABEL: @test15a
  188. ; CHECK-NEXT: shufflevector <4 x float> %LHS, <4 x float> %RHS, <4 x i32> <i32 4, i32 0, i32 6, i32 6>
  189. ; CHECK-NEXT: ret <4 x float> %tmp4
  190. %tmp1 = extractelement <4 x float> %LHS, i32 0
  191. %tmp2 = insertelement <4 x float> %RHS, float %tmp1, i32 1
  192. %tmp3 = extractelement <4 x float> %RHS, i32 2
  193. %tmp4 = insertelement <4 x float> %tmp2, float %tmp3, i32 3
  194. ret <4 x float> %tmp4
  195. }
  196. define <4 x float> @test15b(<4 x float> %LHS, <4 x float> %RHS) {
  197. ; CHECK-LABEL: @test15b
  198. ; CHECK-NEXT: shufflevector <4 x float> %LHS, <4 x float> %RHS, <4 x i32> <i32 4, i32 3, i32 6, i32 6>
  199. ; CHECK-NEXT: ret <4 x float> %tmp5
  200. %tmp0 = extractelement <4 x float> %LHS, i32 3
  201. %tmp1 = insertelement <4 x float> %RHS, float %tmp0, i32 0
  202. %tmp2 = extractelement <4 x float> %tmp1, i32 0
  203. %tmp3 = insertelement <4 x float> %RHS, float %tmp2, i32 1
  204. %tmp4 = extractelement <4 x float> %RHS, i32 2
  205. %tmp5 = insertelement <4 x float> %tmp3, float %tmp4, i32 3
  206. ret <4 x float> %tmp5
  207. }
  208. define <1 x i32> @test16a(i32 %ele) {
  209. ; CHECK-LABEL: @test16a(
  210. ; CHECK-NEXT: ret <1 x i32> <i32 2>
  211. %tmp0 = insertelement <2 x i32> <i32 1, i32 undef>, i32 %ele, i32 1
  212. %tmp1 = shl <2 x i32> %tmp0, <i32 1, i32 1>
  213. %tmp2 = shufflevector <2 x i32> %tmp1, <2 x i32> undef, <1 x i32> <i32 0>
  214. ret <1 x i32> %tmp2
  215. }
  216. define <4 x i8> @test16b(i8 %ele) {
  217. ; CHECK-LABEL: @test16b(
  218. ; CHECK-NEXT: ret <4 x i8> <i8 2, i8 2, i8 2, i8 2>
  219. %tmp0 = insertelement <8 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 undef, i8 1>, i8 %ele, i32 6
  220. %tmp1 = shl <8 x i8> %tmp0, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
  221. %tmp2 = shufflevector <8 x i8> %tmp1, <8 x i8> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 4>
  222. ret <4 x i8> %tmp2
  223. }
  224. ; If composition of two shuffles is identity, shuffles can be removed.
  225. define <4 x i32> @shuffle_17ident(<4 x i32> %v) nounwind uwtable {
  226. ; CHECK-LABEL: @shuffle_17ident(
  227. ; CHECK-NOT: shufflevector
  228. %shuffle = shufflevector <4 x i32> %v, <4 x i32> zeroinitializer,
  229. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  230. %shuffle2 = shufflevector <4 x i32> %shuffle, <4 x i32> zeroinitializer,
  231. <4 x i32> <i32 3, i32 0, i32 1, i32 2>
  232. ret <4 x i32> %shuffle2
  233. }
  234. ; swizzle can be put after operation
  235. define <4 x i32> @shuffle_17and(<4 x i32> %v1, <4 x i32> %v2) nounwind uwtable {
  236. ; CHECK-LABEL: @shuffle_17and(
  237. ; CHECK-NOT: shufflevector
  238. ; CHECK: and <4 x i32> %v1, %v2
  239. ; CHECK: shufflevector
  240. %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer,
  241. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  242. %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer,
  243. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  244. %r = and <4 x i32> %t1, %t2
  245. ret <4 x i32> %r
  246. }
  247. define <4 x i32> @shuffle_17add(<4 x i32> %v1, <4 x i32> %v2) nounwind uwtable {
  248. ; CHECK-LABEL: @shuffle_17add(
  249. ; CHECK-NOT: shufflevector
  250. ; CHECK: add <4 x i32> %v1, %v2
  251. ; CHECK: shufflevector
  252. %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer,
  253. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  254. %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer,
  255. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  256. %r = add <4 x i32> %t1, %t2
  257. ret <4 x i32> %r
  258. }
  259. define <4 x i32> @shuffle_17addnsw(<4 x i32> %v1, <4 x i32> %v2) nounwind uwtable {
  260. ; CHECK-LABEL: @shuffle_17addnsw(
  261. ; CHECK-NOT: shufflevector
  262. ; CHECK: add nsw <4 x i32> %v1, %v2
  263. ; CHECK: shufflevector
  264. %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer,
  265. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  266. %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer,
  267. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  268. %r = add nsw <4 x i32> %t1, %t2
  269. ret <4 x i32> %r
  270. }
  271. define <4 x i32> @shuffle_17addnuw(<4 x i32> %v1, <4 x i32> %v2) nounwind uwtable {
  272. ; CHECK-LABEL: @shuffle_17addnuw(
  273. ; CHECK-NOT: shufflevector
  274. ; CHECK: add nuw <4 x i32> %v1, %v2
  275. ; CHECK: shufflevector
  276. %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer,
  277. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  278. %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer,
  279. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  280. %r = add nuw <4 x i32> %t1, %t2
  281. ret <4 x i32> %r
  282. }
  283. define <4 x float> @shuffle_17fsub(<4 x float> %v1, <4 x float> %v2) nounwind uwtable {
  284. ; CHECK-LABEL: @shuffle_17fsub(
  285. ; CHECK-NOT: shufflevector
  286. ; CHECK: fsub <4 x float> %v1, %v2
  287. ; CHECK: shufflevector
  288. %t1 = shufflevector <4 x float> %v1, <4 x float> zeroinitializer,
  289. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  290. %t2 = shufflevector <4 x float> %v2, <4 x float> zeroinitializer,
  291. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  292. %r = fsub <4 x float> %t1, %t2
  293. ret <4 x float> %r
  294. }
  295. define <4 x i32> @shuffle_17addconst(<4 x i32> %v1, <4 x i32> %v2) {
  296. ; CHECK-LABEL: @shuffle_17addconst(
  297. ; CHECK-NOT: shufflevector
  298. ; CHECK: [[VAR1:%[a-zA-Z0-9.]+]] = add <4 x i32> %v1, <i32 4, i32 1, i32 2, i32 3>
  299. ; CHECK: [[VAR2:%[a-zA-Z0-9.]+]] = shufflevector <4 x i32> [[VAR1]], <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  300. ; CHECK: ret <4 x i32> [[VAR2]]
  301. %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer,
  302. <4 x i32> <i32 1, i32 2, i32 3, i32 0>
  303. %r = add <4 x i32> %t1, <i32 1, i32 2, i32 3, i32 4>
  304. ret <4 x i32> %r
  305. }
  306. define <4 x i32> @shuffle_17add2(<4 x i32> %v) {
  307. ; CHECK-LABEL: @shuffle_17add2(
  308. ; CHECK-NOT: shufflevector
  309. ; CHECK: [[VAR:%[a-zA-Z0-9.]+]] = shl <4 x i32> %v, <i32 1, i32 1, i32 1, i32 1>
  310. ; CHECK: ret <4 x i32> [[VAR]]
  311. %t1 = shufflevector <4 x i32> %v, <4 x i32> zeroinitializer,
  312. <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  313. %t2 = add <4 x i32> %t1, %t1
  314. %r = shufflevector <4 x i32> %t2, <4 x i32> zeroinitializer,
  315. <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  316. ret <4 x i32> %r
  317. }
  318. define <4 x i32> @shuffle_17mulsplat(<4 x i32> %v) {
  319. ; CHECK-LABEL: @shuffle_17mulsplat(
  320. ; CHECK-NOT: shufflevector
  321. ; CHECK: [[VAR1:%[a-zA-Z0-9.]+]] = mul <4 x i32> %v, %v
  322. ; CHECK: [[VAR2:%[a-zA-Z0-9.]+]] = shufflevector <4 x i32> [[VAR1]], <4 x i32> undef, <4 x i32> zeroinitializer
  323. ; CHECK: ret <4 x i32> [[VAR2]]
  324. %s1 = shufflevector <4 x i32> %v,
  325. <4 x i32> zeroinitializer,
  326. <4 x i32> zeroinitializer
  327. %m1 = mul <4 x i32> %s1, %s1
  328. %s2 = shufflevector <4 x i32> %m1,
  329. <4 x i32> zeroinitializer,
  330. <4 x i32> <i32 1, i32 1, i32 1, i32 1>
  331. ret <4 x i32> %s2
  332. }
  333. ; Do not reorder shuffle and binop if LHS of shuffles are of different size
  334. define <2 x i32> @pr19717(<4 x i32> %in0, <2 x i32> %in1) {
  335. ; CHECK-LABEL: @pr19717(
  336. ; CHECK: shufflevector
  337. ; CHECK: shufflevector
  338. ; CHECK: mul
  339. %shuffle = shufflevector <4 x i32> %in0, <4 x i32> %in0, <2 x i32> zeroinitializer
  340. %shuffle4 = shufflevector <2 x i32> %in1, <2 x i32> %in1, <2 x i32> zeroinitializer
  341. %mul = mul <2 x i32> %shuffle, %shuffle4
  342. ret <2 x i32> %mul
  343. }
  344. define <4 x i16> @pr19717a(<8 x i16> %in0, <8 x i16> %in1) {
  345. ; CHECK-LABEL: @pr19717a(
  346. ; CHECK: [[VAR1:%[a-zA-Z0-9.]+]] = mul <8 x i16> %in0, %in1
  347. ; CHECK: [[VAR2:%[a-zA-Z0-9.]+]] = shufflevector <8 x i16> [[VAR1]], <8 x i16> undef, <4 x i32> <i32 5, i32 5, i32 5, i32 5>
  348. ; CHECK: ret <4 x i16> [[VAR2]]
  349. %shuffle = shufflevector <8 x i16> %in0, <8 x i16> %in0, <4 x i32> <i32 5, i32 5, i32 5, i32 5>
  350. %shuffle1 = shufflevector <8 x i16> %in1, <8 x i16> %in1, <4 x i32> <i32 5, i32 5, i32 5, i32 5>
  351. %mul = mul <4 x i16> %shuffle, %shuffle1
  352. ret <4 x i16> %mul
  353. }
  354. define <8 x i8> @pr19730(<16 x i8> %in0) {
  355. ; CHECK-LABEL: @pr19730(
  356. ; CHECK: shufflevector
  357. %shuffle = shufflevector <16 x i8> %in0, <16 x i8> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  358. %shuffle1 = shufflevector <8 x i8> %shuffle, <8 x i8> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  359. ret <8 x i8> %shuffle1
  360. }
  361. define i32 @pr19737(<4 x i32> %in0) {
  362. ; CHECK-LABEL: @pr19737(
  363. ; CHECK: [[VAR:%[a-zA-Z0-9.]+]] = extractelement <4 x i32> %in0, i32 0
  364. ; CHECK: ret i32 [[VAR]]
  365. %shuffle.i = shufflevector <4 x i32> zeroinitializer, <4 x i32> %in0, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
  366. %neg.i = xor <4 x i32> %shuffle.i, <i32 -1, i32 -1, i32 -1, i32 -1>
  367. %and.i = and <4 x i32> %in0, %neg.i
  368. %rv = extractelement <4 x i32> %and.i, i32 0
  369. ret i32 %rv
  370. }
  371. define <4 x i32> @pr20114(<4 x i32> %__mask) {
  372. ; CHECK-LABEL: @pr20114
  373. ; CHECK: shufflevector
  374. ; CHECK: and
  375. %mask01.i = shufflevector <4 x i32> %__mask, <4 x i32> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
  376. %masked_new.i.i.i = and <4 x i32> bitcast (<2 x i64> <i64 ptrtoint (<4 x i32> (<4 x i32>)* @pr20114 to i64), i64 ptrtoint (<4 x i32> (<4 x i32>)* @pr20114 to i64)> to <4 x i32>), %mask01.i
  377. ret <4 x i32> %masked_new.i.i.i
  378. }
  379. define <2 x i32*> @pr23113(<4 x i32*> %A) {
  380. ; CHECK-LABEL: @pr23113
  381. ; CHECK: %[[V:.*]] = shufflevector <4 x i32*> %A, <4 x i32*> undef, <2 x i32> <i32 0, i32 1>
  382. ; CHECK-NEXT: ret <2 x i32*> %[[V]]
  383. %1 = shufflevector <4 x i32*> %A, <4 x i32*> undef, <2 x i32> <i32 0, i32 1>
  384. ret <2 x i32*> %1
  385. }