vector-mul.ll 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. ; Check that instcombine rewrites multiply by a vector
  3. ; of known constant power-of-2 elements with vector shift.
  4. define <4 x i8> @Zero_i8(<4 x i8> %InVec) {
  5. entry:
  6. %mul = mul <4 x i8> %InVec, <i8 0, i8 0, i8 0, i8 0>
  7. ret <4 x i8> %mul
  8. }
  9. ; CHECK-LABEL: @Zero_i8(
  10. ; CHECK: ret <4 x i8> zeroinitializer
  11. define <4 x i8> @Identity_i8(<4 x i8> %InVec) {
  12. entry:
  13. %mul = mul <4 x i8> %InVec, <i8 1, i8 1, i8 1, i8 1>
  14. ret <4 x i8> %mul
  15. }
  16. ; CHECK-LABEL: @Identity_i8(
  17. ; CHECK: ret <4 x i8> %InVec
  18. define <4 x i8> @AddToSelf_i8(<4 x i8> %InVec) {
  19. entry:
  20. %mul = mul <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
  21. ret <4 x i8> %mul
  22. }
  23. ; CHECK-LABEL: @AddToSelf_i8(
  24. ; CHECK: shl <4 x i8> %InVec, <i8 1, i8 1, i8 1, i8 1>
  25. ; CHECK: ret
  26. define <4 x i8> @SplatPow2Test1_i8(<4 x i8> %InVec) {
  27. entry:
  28. %mul = mul <4 x i8> %InVec, <i8 4, i8 4, i8 4, i8 4>
  29. ret <4 x i8> %mul
  30. }
  31. ; CHECK-LABEL: @SplatPow2Test1_i8(
  32. ; CHECK: shl <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
  33. ; CHECK: ret
  34. define <4 x i8> @SplatPow2Test2_i8(<4 x i8> %InVec) {
  35. entry:
  36. %mul = mul <4 x i8> %InVec, <i8 8, i8 8, i8 8, i8 8>
  37. ret <4 x i8> %mul
  38. }
  39. ; CHECK-LABEL: @SplatPow2Test2_i8(
  40. ; CHECK: shl <4 x i8> %InVec, <i8 3, i8 3, i8 3, i8 3>
  41. ; CHECK: ret
  42. define <4 x i8> @MulTest1_i8(<4 x i8> %InVec) {
  43. entry:
  44. %mul = mul <4 x i8> %InVec, <i8 1, i8 2, i8 4, i8 8>
  45. ret <4 x i8> %mul
  46. }
  47. ; CHECK-LABEL: @MulTest1_i8(
  48. ; CHECK: shl <4 x i8> %InVec, <i8 0, i8 1, i8 2, i8 3>
  49. ; CHECK: ret
  50. define <4 x i8> @MulTest2_i8(<4 x i8> %InVec) {
  51. entry:
  52. %mul = mul <4 x i8> %InVec, <i8 3, i8 3, i8 3, i8 3>
  53. ret <4 x i8> %mul
  54. }
  55. ; CHECK-LABEL: @MulTest2_i8(
  56. ; CHECK: mul <4 x i8> %InVec, <i8 3, i8 3, i8 3, i8 3>
  57. ; CHECK: ret
  58. define <4 x i8> @MulTest3_i8(<4 x i8> %InVec) {
  59. entry:
  60. %mul = mul <4 x i8> %InVec, <i8 4, i8 4, i8 2, i8 2>
  61. ret <4 x i8> %mul
  62. }
  63. ; CHECK-LABEL: @MulTest3_i8(
  64. ; CHECK: shl <4 x i8> %InVec, <i8 2, i8 2, i8 1, i8 1>
  65. ; CHECK: ret
  66. define <4 x i8> @MulTest4_i8(<4 x i8> %InVec) {
  67. entry:
  68. %mul = mul <4 x i8> %InVec, <i8 4, i8 4, i8 0, i8 1>
  69. ret <4 x i8> %mul
  70. }
  71. ; CHECK-LABEL: @MulTest4_i8(
  72. ; CHECK: mul <4 x i8> %InVec, <i8 4, i8 4, i8 0, i8 1>
  73. ; CHECK: ret
  74. define <4 x i16> @Zero_i16(<4 x i16> %InVec) {
  75. entry:
  76. %mul = mul <4 x i16> %InVec, <i16 0, i16 0, i16 0, i16 0>
  77. ret <4 x i16> %mul
  78. }
  79. ; CHECK-LABEL: @Zero_i16(
  80. ; CHECK: ret <4 x i16> zeroinitializer
  81. define <4 x i16> @Identity_i16(<4 x i16> %InVec) {
  82. entry:
  83. %mul = mul <4 x i16> %InVec, <i16 1, i16 1, i16 1, i16 1>
  84. ret <4 x i16> %mul
  85. }
  86. ; CHECK-LABEL: @Identity_i16(
  87. ; CHECK: ret <4 x i16> %InVec
  88. define <4 x i16> @AddToSelf_i16(<4 x i16> %InVec) {
  89. entry:
  90. %mul = mul <4 x i16> %InVec, <i16 2, i16 2, i16 2, i16 2>
  91. ret <4 x i16> %mul
  92. }
  93. ; CHECK-LABEL: @AddToSelf_i16(
  94. ; CHECK: shl <4 x i16> %InVec, <i16 1, i16 1, i16 1, i16 1>
  95. ; CHECK: ret
  96. define <4 x i16> @SplatPow2Test1_i16(<4 x i16> %InVec) {
  97. entry:
  98. %mul = mul <4 x i16> %InVec, <i16 4, i16 4, i16 4, i16 4>
  99. ret <4 x i16> %mul
  100. }
  101. ; CHECK-LABEL: @SplatPow2Test1_i16(
  102. ; CHECK: shl <4 x i16> %InVec, <i16 2, i16 2, i16 2, i16 2>
  103. ; CHECK: ret
  104. define <4 x i16> @SplatPow2Test2_i16(<4 x i16> %InVec) {
  105. entry:
  106. %mul = mul <4 x i16> %InVec, <i16 8, i16 8, i16 8, i16 8>
  107. ret <4 x i16> %mul
  108. }
  109. ; CHECK-LABEL: @SplatPow2Test2_i16(
  110. ; CHECK: shl <4 x i16> %InVec, <i16 3, i16 3, i16 3, i16 3>
  111. ; CHECK: ret
  112. define <4 x i16> @MulTest1_i16(<4 x i16> %InVec) {
  113. entry:
  114. %mul = mul <4 x i16> %InVec, <i16 1, i16 2, i16 4, i16 8>
  115. ret <4 x i16> %mul
  116. }
  117. ; CHECK-LABEL: @MulTest1_i16(
  118. ; CHECK: shl <4 x i16> %InVec, <i16 0, i16 1, i16 2, i16 3>
  119. ; CHECK: ret
  120. define <4 x i16> @MulTest2_i16(<4 x i16> %InVec) {
  121. entry:
  122. %mul = mul <4 x i16> %InVec, <i16 3, i16 3, i16 3, i16 3>
  123. ret <4 x i16> %mul
  124. }
  125. ; CHECK-LABEL: @MulTest2_i16(
  126. ; CHECK: mul <4 x i16> %InVec, <i16 3, i16 3, i16 3, i16 3>
  127. ; CHECK: ret
  128. define <4 x i16> @MulTest3_i16(<4 x i16> %InVec) {
  129. entry:
  130. %mul = mul <4 x i16> %InVec, <i16 4, i16 4, i16 2, i16 2>
  131. ret <4 x i16> %mul
  132. }
  133. ; CHECK-LABEL: @MulTest3_i16(
  134. ; CHECK: shl <4 x i16> %InVec, <i16 2, i16 2, i16 1, i16 1>
  135. ; CHECK: ret
  136. define <4 x i16> @MulTest4_i16(<4 x i16> %InVec) {
  137. entry:
  138. %mul = mul <4 x i16> %InVec, <i16 4, i16 4, i16 0, i16 2>
  139. ret <4 x i16> %mul
  140. }
  141. ; CHECK-LABEL: @MulTest4_i16(
  142. ; CHECK: mul <4 x i16> %InVec, <i16 4, i16 4, i16 0, i16 2>
  143. ; CHECK: ret
  144. define <4 x i32> @Zero_i32(<4 x i32> %InVec) {
  145. entry:
  146. %mul = mul <4 x i32> %InVec, <i32 0, i32 0, i32 0, i32 0>
  147. ret <4 x i32> %mul
  148. }
  149. ; CHECK-LABEL: @Zero_i32(
  150. ; CHECK: ret <4 x i32> zeroinitializer
  151. define <4 x i32> @Identity_i32(<4 x i32> %InVec) {
  152. entry:
  153. %mul = mul <4 x i32> %InVec, <i32 1, i32 1, i32 1, i32 1>
  154. ret <4 x i32> %mul
  155. }
  156. ; CHECK-LABEL: @Identity_i32(
  157. ; CHECK: ret <4 x i32> %InVec
  158. define <4 x i32> @AddToSelf_i32(<4 x i32> %InVec) {
  159. entry:
  160. %mul = mul <4 x i32> %InVec, <i32 2, i32 2, i32 2, i32 2>
  161. ret <4 x i32> %mul
  162. }
  163. ; CHECK-LABEL: @AddToSelf_i32(
  164. ; CHECK: shl <4 x i32> %InVec, <i32 1, i32 1, i32 1, i32 1>
  165. ; CHECK: ret
  166. define <4 x i32> @SplatPow2Test1_i32(<4 x i32> %InVec) {
  167. entry:
  168. %mul = mul <4 x i32> %InVec, <i32 4, i32 4, i32 4, i32 4>
  169. ret <4 x i32> %mul
  170. }
  171. ; CHECK-LABEL: @SplatPow2Test1_i32(
  172. ; CHECK: shl <4 x i32> %InVec, <i32 2, i32 2, i32 2, i32 2>
  173. ; CHECK: ret
  174. define <4 x i32> @SplatPow2Test2_i32(<4 x i32> %InVec) {
  175. entry:
  176. %mul = mul <4 x i32> %InVec, <i32 8, i32 8, i32 8, i32 8>
  177. ret <4 x i32> %mul
  178. }
  179. ; CHECK-LABEL: @SplatPow2Test2_i32(
  180. ; CHECK: shl <4 x i32> %InVec, <i32 3, i32 3, i32 3, i32 3>
  181. ; CHECK: ret
  182. define <4 x i32> @MulTest1_i32(<4 x i32> %InVec) {
  183. entry:
  184. %mul = mul <4 x i32> %InVec, <i32 1, i32 2, i32 4, i32 8>
  185. ret <4 x i32> %mul
  186. }
  187. ; CHECK-LABEL: @MulTest1_i32(
  188. ; CHECK: shl <4 x i32> %InVec, <i32 0, i32 1, i32 2, i32 3>
  189. ; CHECK: ret
  190. define <4 x i32> @MulTest2_i32(<4 x i32> %InVec) {
  191. entry:
  192. %mul = mul <4 x i32> %InVec, <i32 3, i32 3, i32 3, i32 3>
  193. ret <4 x i32> %mul
  194. }
  195. ; CHECK-LABEL: @MulTest2_i32(
  196. ; CHECK: mul <4 x i32> %InVec, <i32 3, i32 3, i32 3, i32 3>
  197. ; CHECK: ret
  198. define <4 x i32> @MulTest3_i32(<4 x i32> %InVec) {
  199. entry:
  200. %mul = mul <4 x i32> %InVec, <i32 4, i32 4, i32 2, i32 2>
  201. ret <4 x i32> %mul
  202. }
  203. ; CHECK-LABEL: @MulTest3_i32(
  204. ; CHECK: shl <4 x i32> %InVec, <i32 2, i32 2, i32 1, i32 1>
  205. ; CHECK: ret
  206. define <4 x i32> @MulTest4_i32(<4 x i32> %InVec) {
  207. entry:
  208. %mul = mul <4 x i32> %InVec, <i32 4, i32 4, i32 0, i32 1>
  209. ret <4 x i32> %mul
  210. }
  211. ; CHECK-LABEL: @MulTest4_i32(
  212. ; CHECK: mul <4 x i32> %InVec, <i32 4, i32 4, i32 0, i32 1>
  213. ; CHECK: ret
  214. define <4 x i64> @Zero_i64(<4 x i64> %InVec) {
  215. entry:
  216. %mul = mul <4 x i64> %InVec, <i64 0, i64 0, i64 0, i64 0>
  217. ret <4 x i64> %mul
  218. }
  219. ; CHECK-LABEL: @Zero_i64(
  220. ; CHECK: ret <4 x i64> zeroinitializer
  221. define <4 x i64> @Identity_i64(<4 x i64> %InVec) {
  222. entry:
  223. %mul = mul <4 x i64> %InVec, <i64 1, i64 1, i64 1, i64 1>
  224. ret <4 x i64> %mul
  225. }
  226. ; CHECK-LABEL: @Identity_i64(
  227. ; CHECK: ret <4 x i64> %InVec
  228. define <4 x i64> @AddToSelf_i64(<4 x i64> %InVec) {
  229. entry:
  230. %mul = mul <4 x i64> %InVec, <i64 2, i64 2, i64 2, i64 2>
  231. ret <4 x i64> %mul
  232. }
  233. ; CHECK-LABEL: @AddToSelf_i64(
  234. ; CHECK: shl <4 x i64> %InVec, <i64 1, i64 1, i64 1, i64 1>
  235. ; CHECK: ret
  236. define <4 x i64> @SplatPow2Test1_i64(<4 x i64> %InVec) {
  237. entry:
  238. %mul = mul <4 x i64> %InVec, <i64 4, i64 4, i64 4, i64 4>
  239. ret <4 x i64> %mul
  240. }
  241. ; CHECK-LABEL: @SplatPow2Test1_i64(
  242. ; CHECK: shl <4 x i64> %InVec, <i64 2, i64 2, i64 2, i64 2>
  243. ; CHECK: ret
  244. define <4 x i64> @SplatPow2Test2_i64(<4 x i64> %InVec) {
  245. entry:
  246. %mul = mul <4 x i64> %InVec, <i64 8, i64 8, i64 8, i64 8>
  247. ret <4 x i64> %mul
  248. }
  249. ; CHECK-LABEL: @SplatPow2Test2_i64(
  250. ; CHECK: shl <4 x i64> %InVec, <i64 3, i64 3, i64 3, i64 3>
  251. ; CHECK: ret
  252. define <4 x i64> @MulTest1_i64(<4 x i64> %InVec) {
  253. entry:
  254. %mul = mul <4 x i64> %InVec, <i64 1, i64 2, i64 4, i64 8>
  255. ret <4 x i64> %mul
  256. }
  257. ; CHECK-LABEL: @MulTest1_i64(
  258. ; CHECK: shl <4 x i64> %InVec, <i64 0, i64 1, i64 2, i64 3>
  259. ; CHECK: ret
  260. define <4 x i64> @MulTest2_i64(<4 x i64> %InVec) {
  261. entry:
  262. %mul = mul <4 x i64> %InVec, <i64 3, i64 3, i64 3, i64 3>
  263. ret <4 x i64> %mul
  264. }
  265. ; CHECK-LABEL: @MulTest2_i64(
  266. ; CHECK: mul <4 x i64> %InVec, <i64 3, i64 3, i64 3, i64 3>
  267. ; CHECK: ret
  268. define <4 x i64> @MulTest3_i64(<4 x i64> %InVec) {
  269. entry:
  270. %mul = mul <4 x i64> %InVec, <i64 4, i64 4, i64 2, i64 2>
  271. ret <4 x i64> %mul
  272. }
  273. ; CHECK-LABEL: @MulTest3_i64(
  274. ; CHECK: shl <4 x i64> %InVec, <i64 2, i64 2, i64 1, i64 1>
  275. ; CHECK: ret
  276. define <4 x i64> @MulTest4_i64(<4 x i64> %InVec) {
  277. entry:
  278. %mul = mul <4 x i64> %InVec, <i64 4, i64 4, i64 0, i64 1>
  279. ret <4 x i64> %mul
  280. }
  281. ; CHECK-LABEL: @MulTest4_i64(
  282. ; CHECK: mul <4 x i64> %InVec, <i64 4, i64 4, i64 0, i64 1>
  283. ; CHECK: ret
  284. ; Test also that the following rewriting rule works with vectors
  285. ; of integers as well:
  286. ; ((X << C1)*C2) == (X * (C2 << C1))
  287. define <4 x i8> @ShiftMulTest1(<4 x i8> %InVec) {
  288. entry:
  289. %shl = shl <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
  290. %mul = mul <4 x i8> %shl, <i8 3, i8 3, i8 3, i8 3>
  291. ret <4 x i8> %mul
  292. }
  293. ; CHECK-LABEL: @ShiftMulTest1(
  294. ; CHECK: mul <4 x i8> %InVec, <i8 12, i8 12, i8 12, i8 12>
  295. ; CHECK: ret
  296. define <4 x i16> @ShiftMulTest2(<4 x i16> %InVec) {
  297. entry:
  298. %shl = shl <4 x i16> %InVec, <i16 2, i16 2, i16 2, i16 2>
  299. %mul = mul <4 x i16> %shl, <i16 3, i16 3, i16 3, i16 3>
  300. ret <4 x i16> %mul
  301. }
  302. ; CHECK-LABEL: @ShiftMulTest2(
  303. ; CHECK: mul <4 x i16> %InVec, <i16 12, i16 12, i16 12, i16 12>
  304. ; CHECK: ret
  305. define <4 x i32> @ShiftMulTest3(<4 x i32> %InVec) {
  306. entry:
  307. %shl = shl <4 x i32> %InVec, <i32 2, i32 2, i32 2, i32 2>
  308. %mul = mul <4 x i32> %shl, <i32 3, i32 3, i32 3, i32 3>
  309. ret <4 x i32> %mul
  310. }
  311. ; CHECK-LABEL: @ShiftMulTest3(
  312. ; CHECK: mul <4 x i32> %InVec, <i32 12, i32 12, i32 12, i32 12>
  313. ; CHECK: ret
  314. define <4 x i64> @ShiftMulTest4(<4 x i64> %InVec) {
  315. entry:
  316. %shl = shl <4 x i64> %InVec, <i64 2, i64 2, i64 2, i64 2>
  317. %mul = mul <4 x i64> %shl, <i64 3, i64 3, i64 3, i64 3>
  318. ret <4 x i64> %mul
  319. }
  320. ; CHECK-LABEL: @ShiftMulTest4(
  321. ; CHECK: mul <4 x i64> %InVec, <i64 12, i64 12, i64 12, i64 12>
  322. ; CHECK: ret