apint-shift.ll 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. ; This test makes sure that shift instructions are properly eliminated
  2. ; even with arbitrary precision integers.
  3. ; RUN: opt < %s -instcombine -S | FileCheck %s
  4. ; CHECK-LABEL: @test1(
  5. ; CHECK-NOT: sh
  6. define i47 @test1(i47 %A) {
  7. %B = shl i47 %A, 0 ; <i47> [#uses=1]
  8. ret i47 %B
  9. }
  10. ; CHECK-LABEL: @test2(
  11. ; CHECK-NOT: sh
  12. define i41 @test2(i7 %X) {
  13. %A = zext i7 %X to i41 ; <i41> [#uses=1]
  14. %B = shl i41 0, %A ; <i41> [#uses=1]
  15. ret i41 %B
  16. }
  17. ; CHECK-LABEL: @test3(
  18. ; CHECK-NOT: sh
  19. define i41 @test3(i41 %A) {
  20. %B = ashr i41 %A, 0 ; <i41> [#uses=1]
  21. ret i41 %B
  22. }
  23. ; CHECK-LABEL: @test4(
  24. ; CHECK-NOT: sh
  25. define i39 @test4(i7 %X) {
  26. %A = zext i7 %X to i39 ; <i39> [#uses=1]
  27. %B = ashr i39 0, %A ; <i39> [#uses=1]
  28. ret i39 %B
  29. }
  30. ; CHECK-LABEL: @test5(
  31. ; CHECK-NOT: sh
  32. define i55 @test5(i55 %A) {
  33. %B = lshr i55 %A, 55 ; <i55> [#uses=1]
  34. ret i55 %B
  35. }
  36. ; CHECK-LABEL: @test5a(
  37. ; CHECK-NOT: sh
  38. define i32 @test5a(i32 %A) {
  39. %B = shl i32 %A, 32 ; <i32> [#uses=1]
  40. ret i32 %B
  41. }
  42. ; CHECK-LABEL: @test6(
  43. ; CHECK: mul i55 %A, 6
  44. define i55 @test6(i55 %A) {
  45. %B = shl i55 %A, 1 ; <i55> [#uses=1]
  46. %C = mul i55 %B, 3 ; <i55> [#uses=1]
  47. ret i55 %C
  48. }
  49. ; CHECK-LABEL: @test6a(
  50. ; CHECK: mul i55 %A, 6
  51. define i55 @test6a(i55 %A) {
  52. %B = mul i55 %A, 3 ; <i55> [#uses=1]
  53. %C = shl i55 %B, 1 ; <i55> [#uses=1]
  54. ret i55 %C
  55. }
  56. ; CHECK-LABEL: @test7(
  57. ; CHECK-NOT: sh
  58. define i29 @test7(i8 %X) {
  59. %A = zext i8 %X to i29 ; <i29> [#uses=1]
  60. %B = ashr i29 -1, %A ; <i29> [#uses=1]
  61. ret i29 %B
  62. }
  63. ; CHECK-LABEL: @test8(
  64. ; CHECK-NOT: sh
  65. define i7 @test8(i7 %A) {
  66. %B = shl i7 %A, 4 ; <i7> [#uses=1]
  67. %C = shl i7 %B, 3 ; <i7> [#uses=1]
  68. ret i7 %C
  69. }
  70. ; CHECK-LABEL: @test9(
  71. ; CHECK-NOT: sh
  72. define i17 @test9(i17 %A) {
  73. %B = shl i17 %A, 16 ; <i17> [#uses=1]
  74. %C = lshr i17 %B, 16 ; <i17> [#uses=1]
  75. ret i17 %C
  76. }
  77. ; CHECK-LABEL: @test10(
  78. ; CHECK-NOT: sh
  79. define i19 @test10(i19 %A) {
  80. %B = lshr i19 %A, 18 ; <i19> [#uses=1]
  81. %C = shl i19 %B, 18 ; <i19> [#uses=1]
  82. ret i19 %C
  83. }
  84. ; CHECK-LABEL: @test11(
  85. ; Don't hide the shl from scalar evolution. DAGCombine will get it.
  86. ; CHECK: shl
  87. define i23 @test11(i23 %A) {
  88. %a = mul i23 %A, 3 ; <i23> [#uses=1]
  89. %B = lshr i23 %a, 11 ; <i23> [#uses=1]
  90. %C = shl i23 %B, 12 ; <i23> [#uses=1]
  91. ret i23 %C
  92. }
  93. ; CHECK-LABEL: @test12(
  94. ; CHECK-NOT: sh
  95. define i47 @test12(i47 %A) {
  96. %B = ashr i47 %A, 8 ; <i47> [#uses=1]
  97. %C = shl i47 %B, 8 ; <i47> [#uses=1]
  98. ret i47 %C
  99. }
  100. ; CHECK-LABEL: @test13(
  101. ; Don't hide the shl from scalar evolution. DAGCombine will get it.
  102. ; CHECK: shl
  103. define i18 @test13(i18 %A) {
  104. %a = mul i18 %A, 3 ; <i18> [#uses=1]
  105. %B = ashr i18 %a, 8 ; <i18> [#uses=1]
  106. %C = shl i18 %B, 9 ; <i18> [#uses=1]
  107. ret i18 %C
  108. }
  109. ; CHECK-LABEL: @test14(
  110. ; CHECK-NOT: sh
  111. define i35 @test14(i35 %A) {
  112. %B = lshr i35 %A, 4 ; <i35> [#uses=1]
  113. %C = or i35 %B, 1234 ; <i35> [#uses=1]
  114. %D = shl i35 %C, 4 ; <i35> [#uses=1]
  115. ret i35 %D
  116. }
  117. ; CHECK-LABEL: @test14a(
  118. ; CHECK-NOT: sh
  119. define i79 @test14a(i79 %A) {
  120. %B = shl i79 %A, 4 ; <i79> [#uses=1]
  121. %C = and i79 %B, 1234 ; <i79> [#uses=1]
  122. %D = lshr i79 %C, 4 ; <i79> [#uses=1]
  123. ret i79 %D
  124. }
  125. ; CHECK-LABEL: @test15(
  126. ; CHECK-NOT: sh
  127. define i45 @test15(i1 %C) {
  128. %A = select i1 %C, i45 3, i45 1 ; <i45> [#uses=1]
  129. %V = shl i45 %A, 2 ; <i45> [#uses=1]
  130. ret i45 %V
  131. }
  132. ; CHECK-LABEL: @test15a(
  133. ; CHECK-NOT: sh
  134. define i53 @test15a(i1 %X) {
  135. %A = select i1 %X, i8 3, i8 1 ; <i8> [#uses=1]
  136. %B = zext i8 %A to i53 ; <i53> [#uses=1]
  137. %V = shl i53 64, %B ; <i53> [#uses=1]
  138. ret i53 %V
  139. }
  140. ; CHECK-LABEL: @test16(
  141. ; CHECK-NOT: sh
  142. define i1 @test16(i84 %X) {
  143. %tmp.3 = ashr i84 %X, 4 ; <i84> [#uses=1]
  144. %tmp.6 = and i84 %tmp.3, 1 ; <i84> [#uses=1]
  145. %tmp.7 = icmp ne i84 %tmp.6, 0 ; <i1> [#uses=1]
  146. ret i1 %tmp.7
  147. }
  148. ; CHECK-LABEL: @test17(
  149. ; CHECK-NOT: sh
  150. define i1 @test17(i106 %A) {
  151. %B = lshr i106 %A, 3 ; <i106> [#uses=1]
  152. %C = icmp eq i106 %B, 1234 ; <i1> [#uses=1]
  153. ret i1 %C
  154. }
  155. ; CHECK-LABEL: @test18(
  156. ; CHECK-NOT: sh
  157. define i1 @test18(i11 %A) {
  158. %B = lshr i11 %A, 10 ; <i11> [#uses=1]
  159. %C = icmp eq i11 %B, 123 ; <i1> [#uses=1]
  160. ret i1 %C
  161. }
  162. ; CHECK-LABEL: @test19(
  163. ; CHECK-NOT: sh
  164. define i1 @test19(i37 %A) {
  165. %B = ashr i37 %A, 2 ; <i37> [#uses=1]
  166. %C = icmp eq i37 %B, 0 ; <i1> [#uses=1]
  167. ret i1 %C
  168. }
  169. ; CHECK-LABEL: @test19a(
  170. ; CHECK-NOT: sh
  171. define i1 @test19a(i39 %A) {
  172. %B = ashr i39 %A, 2 ; <i39> [#uses=1]
  173. %C = icmp eq i39 %B, -1 ; <i1> [#uses=1]
  174. ret i1 %C
  175. }
  176. ; CHECK-LABEL: @test20(
  177. ; CHECK-NOT: sh
  178. define i1 @test20(i13 %A) {
  179. %B = ashr i13 %A, 12 ; <i13> [#uses=1]
  180. %C = icmp eq i13 %B, 123 ; <i1> [#uses=1]
  181. ret i1 %C
  182. }
  183. ; CHECK-LABEL: @test21(
  184. ; CHECK-NOT: sh
  185. define i1 @test21(i12 %A) {
  186. %B = shl i12 %A, 6 ; <i12> [#uses=1]
  187. %C = icmp eq i12 %B, -128 ; <i1> [#uses=1]
  188. ret i1 %C
  189. }
  190. ; CHECK-LABEL: @test22(
  191. ; CHECK-NOT: sh
  192. define i1 @test22(i14 %A) {
  193. %B = shl i14 %A, 7 ; <i14> [#uses=1]
  194. %C = icmp eq i14 %B, 0 ; <i1> [#uses=1]
  195. ret i1 %C
  196. }
  197. ; CHECK-LABEL: @test23(
  198. ; CHECK-NOT: sh
  199. define i11 @test23(i44 %A) {
  200. %B = shl i44 %A, 33 ; <i44> [#uses=1]
  201. %C = ashr i44 %B, 33 ; <i44> [#uses=1]
  202. %D = trunc i44 %C to i11 ; <i8> [#uses=1]
  203. ret i11 %D
  204. }
  205. ; CHECK-LABEL: @test25(
  206. ; CHECK-NOT: sh
  207. define i37 @test25(i37 %tmp.2, i37 %AA) {
  208. %x = lshr i37 %AA, 17 ; <i37> [#uses=1]
  209. %tmp.3 = lshr i37 %tmp.2, 17 ; <i37> [#uses=1]
  210. %tmp.5 = add i37 %tmp.3, %x ; <i37> [#uses=1]
  211. %tmp.6 = shl i37 %tmp.5, 17 ; <i37> [#uses=1]
  212. ret i37 %tmp.6
  213. }
  214. ; CHECK-LABEL: @test26(
  215. ; CHECK-NOT: sh
  216. define i40 @test26(i40 %A) {
  217. %B = lshr i40 %A, 1 ; <i40> [#uses=1]
  218. %C = bitcast i40 %B to i40 ; <i40> [#uses=1]
  219. %D = shl i40 %C, 1 ; <i40> [#uses=1]
  220. ret i40 %D
  221. }