basic.ll 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. ; RUN: opt -S -bdce -instsimplify < %s | FileCheck %s
  2. ; RUN: opt -S -instsimplify < %s | FileCheck %s -check-prefix=CHECK-IO
  3. target datalayout = "E-m:e-i64:64-n32:64"
  4. target triple = "powerpc64-unknown-linux-gnu"
  5. ; Function Attrs: nounwind readnone
  6. define signext i32 @bar(i32 signext %x) #0 {
  7. entry:
  8. %call = tail call signext i32 @foo(i32 signext 5) #0
  9. %and = and i32 %call, 4
  10. %or = or i32 %and, %x
  11. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  12. %and2 = and i32 %call1, 8
  13. %or3 = or i32 %or, %and2
  14. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  15. %and5 = and i32 %call4, 16
  16. %or6 = or i32 %or3, %and5
  17. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  18. %and8 = and i32 %call7, 32
  19. %or9 = or i32 %or6, %and8
  20. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  21. %and11 = and i32 %call10, 64
  22. %or12 = or i32 %or9, %and11
  23. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  24. %and14 = and i32 %call13, 128
  25. %or15 = or i32 %or12, %and14
  26. %shr = ashr i32 %or15, 4
  27. ret i32 %shr
  28. ; CHECK-LABEL: @bar
  29. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  30. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  31. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  32. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  33. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  34. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  35. ; CHECK: ret i32
  36. ; Check that instsimplify is not doing this all on its own.
  37. ; CHECK-IO-LABEL: @bar
  38. ; CHECK-IO: tail call signext i32 @foo(i32 signext 5)
  39. ; CHECK-IO: tail call signext i32 @foo(i32 signext 3)
  40. ; CHECK-IO: tail call signext i32 @foo(i32 signext 2)
  41. ; CHECK-IO: tail call signext i32 @foo(i32 signext 1)
  42. ; CHECK-IO: tail call signext i32 @foo(i32 signext 0)
  43. ; CHECK-IO: tail call signext i32 @foo(i32 signext 4)
  44. ; CHECK-IO: ret i32
  45. }
  46. ; Function Attrs: nounwind readnone
  47. declare signext i32 @foo(i32 signext) #0
  48. ; Function Attrs: nounwind readnone
  49. define signext i32 @far(i32 signext %x) #1 {
  50. entry:
  51. %call = tail call signext i32 @goo(i32 signext 5) #1
  52. %and = and i32 %call, 4
  53. %or = or i32 %and, %x
  54. %call1 = tail call signext i32 @goo(i32 signext 3) #1
  55. %and2 = and i32 %call1, 8
  56. %or3 = or i32 %or, %and2
  57. %call4 = tail call signext i32 @goo(i32 signext 2) #1
  58. %and5 = and i32 %call4, 16
  59. %or6 = or i32 %or3, %and5
  60. %call7 = tail call signext i32 @goo(i32 signext 1) #1
  61. %and8 = and i32 %call7, 32
  62. %or9 = or i32 %or6, %and8
  63. %call10 = tail call signext i32 @goo(i32 signext 0) #1
  64. %and11 = and i32 %call10, 64
  65. %or12 = or i32 %or9, %and11
  66. %call13 = tail call signext i32 @goo(i32 signext 4) #1
  67. %and14 = and i32 %call13, 128
  68. %or15 = or i32 %or12, %and14
  69. %shr = ashr i32 %or15, 4
  70. ret i32 %shr
  71. ; CHECK-LABEL: @far
  72. ; Calls to foo(5) and foo(3) are still there, but their results are not used.
  73. ; CHECK: tail call signext i32 @goo(i32 signext 5)
  74. ; CHECK-NEXT: tail call signext i32 @goo(i32 signext 3)
  75. ; CHECK-NEXT: tail call signext i32 @goo(i32 signext 2)
  76. ; CHECK: tail call signext i32 @goo(i32 signext 1)
  77. ; CHECK: tail call signext i32 @goo(i32 signext 0)
  78. ; CHECK: tail call signext i32 @goo(i32 signext 4)
  79. ; CHECK: ret i32
  80. ; Check that instsimplify is not doing this all on its own.
  81. ; CHECK-IO-LABEL: @far
  82. ; CHECK-IO: tail call signext i32 @goo(i32 signext 5)
  83. ; CHECK-IO: tail call signext i32 @goo(i32 signext 3)
  84. ; CHECK-IO: tail call signext i32 @goo(i32 signext 2)
  85. ; CHECK-IO: tail call signext i32 @goo(i32 signext 1)
  86. ; CHECK-IO: tail call signext i32 @goo(i32 signext 0)
  87. ; CHECK-IO: tail call signext i32 @goo(i32 signext 4)
  88. ; CHECK-IO: ret i32
  89. }
  90. declare signext i32 @goo(i32 signext) #1
  91. ; Function Attrs: nounwind readnone
  92. define signext i32 @tar1(i32 signext %x) #0 {
  93. entry:
  94. %call = tail call signext i32 @foo(i32 signext 5) #0
  95. %and = and i32 %call, 33554432
  96. %or = or i32 %and, %x
  97. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  98. %and2 = and i32 %call1, 67108864
  99. %or3 = or i32 %or, %and2
  100. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  101. %and5 = and i32 %call4, 16
  102. %or6 = or i32 %or3, %and5
  103. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  104. %and8 = and i32 %call7, 32
  105. %or9 = or i32 %or6, %and8
  106. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  107. %and11 = and i32 %call10, 64
  108. %or12 = or i32 %or9, %and11
  109. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  110. %and14 = and i32 %call13, 128
  111. %or15 = or i32 %or12, %and14
  112. %bs = tail call i32 @llvm.bswap.i32(i32 %or15) #0
  113. %shr = ashr i32 %bs, 4
  114. ret i32 %shr
  115. ; CHECK-LABEL: @tar1
  116. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  117. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  118. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  119. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  120. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  121. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  122. ; CHECK: ret i32
  123. }
  124. ; Function Attrs: nounwind readnone
  125. declare i32 @llvm.bswap.i32(i32) #0
  126. ; Function Attrs: nounwind readnone
  127. define signext i32 @tar2(i32 signext %x) #0 {
  128. entry:
  129. %call = tail call signext i32 @foo(i32 signext 5) #0
  130. %and = and i32 %call, 33554432
  131. %or = or i32 %and, %x
  132. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  133. %and2 = and i32 %call1, 67108864
  134. %or3 = or i32 %or, %and2
  135. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  136. %and5 = and i32 %call4, 16
  137. %or6 = or i32 %or3, %and5
  138. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  139. %and8 = and i32 %call7, 32
  140. %or9 = or i32 %or6, %and8
  141. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  142. %and11 = and i32 %call10, 64
  143. %or12 = or i32 %or9, %and11
  144. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  145. %and14 = and i32 %call13, 128
  146. %or15 = or i32 %or12, %and14
  147. %shl = shl i32 %or15, 10
  148. ret i32 %shl
  149. ; CHECK-LABEL: @tar2
  150. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  151. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  152. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  153. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  154. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  155. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  156. ; CHECK: ret i32
  157. }
  158. ; Function Attrs: nounwind readnone
  159. define signext i32 @tar3(i32 signext %x) #0 {
  160. entry:
  161. %call = tail call signext i32 @foo(i32 signext 5) #0
  162. %and = and i32 %call, 33554432
  163. %or = or i32 %and, %x
  164. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  165. %and2 = and i32 %call1, 67108864
  166. %or3 = or i32 %or, %and2
  167. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  168. %and5 = and i32 %call4, 16
  169. %or6 = or i32 %or3, %and5
  170. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  171. %and8 = and i32 %call7, 32
  172. %or9 = or i32 %or6, %and8
  173. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  174. %and11 = and i32 %call10, 64
  175. %or12 = or i32 %or9, %and11
  176. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  177. %and14 = and i32 %call13, 128
  178. %or15 = or i32 %or12, %and14
  179. %add = add i32 %or15, 5
  180. %shl = shl i32 %add, 10
  181. ret i32 %shl
  182. ; CHECK-LABEL: @tar3
  183. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  184. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  185. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  186. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  187. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  188. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  189. ; CHECK: ret i32
  190. }
  191. ; Function Attrs: nounwind readnone
  192. define signext i32 @tar4(i32 signext %x) #0 {
  193. entry:
  194. %call = tail call signext i32 @foo(i32 signext 5) #0
  195. %and = and i32 %call, 33554432
  196. %or = or i32 %and, %x
  197. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  198. %and2 = and i32 %call1, 67108864
  199. %or3 = or i32 %or, %and2
  200. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  201. %and5 = and i32 %call4, 16
  202. %or6 = or i32 %or3, %and5
  203. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  204. %and8 = and i32 %call7, 32
  205. %or9 = or i32 %or6, %and8
  206. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  207. %and11 = and i32 %call10, 64
  208. %or12 = or i32 %or9, %and11
  209. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  210. %and14 = and i32 %call13, 128
  211. %or15 = or i32 %or12, %and14
  212. %sub = sub i32 %or15, 5
  213. %shl = shl i32 %sub, 10
  214. ret i32 %shl
  215. ; CHECK-LABEL: @tar4
  216. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  217. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  218. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  219. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  220. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  221. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  222. ; CHECK: ret i32
  223. }
  224. ; Function Attrs: nounwind readnone
  225. define signext i32 @tar5(i32 signext %x) #0 {
  226. entry:
  227. %call = tail call signext i32 @foo(i32 signext 5) #0
  228. %and = and i32 %call, 33554432
  229. %or = or i32 %and, %x
  230. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  231. %and2 = and i32 %call1, 67108864
  232. %or3 = or i32 %or, %and2
  233. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  234. %and5 = and i32 %call4, 16
  235. %or6 = or i32 %or3, %and5
  236. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  237. %and8 = and i32 %call7, 32
  238. %or9 = or i32 %or6, %and8
  239. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  240. %and11 = and i32 %call10, 64
  241. %or12 = or i32 %or9, %and11
  242. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  243. %and14 = and i32 %call13, 128
  244. %or15 = or i32 %or12, %and14
  245. %xor = xor i32 %or15, 5
  246. %shl = shl i32 %xor, 10
  247. ret i32 %shl
  248. ; CHECK-LABEL: @tar5
  249. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  250. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  251. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  252. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  253. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  254. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  255. ; CHECK: ret i32
  256. }
  257. ; Function Attrs: nounwind readnone
  258. define signext i32 @tar7(i32 signext %x, i1 %b) #0 {
  259. entry:
  260. %call = tail call signext i32 @foo(i32 signext 5) #0
  261. %and = and i32 %call, 33554432
  262. %or = or i32 %and, %x
  263. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  264. %and2 = and i32 %call1, 67108864
  265. %or3 = or i32 %or, %and2
  266. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  267. %and5 = and i32 %call4, 16
  268. %or6 = or i32 %or3, %and5
  269. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  270. %and8 = and i32 %call7, 32
  271. %or9 = or i32 %or6, %and8
  272. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  273. %and11 = and i32 %call10, 64
  274. %or12 = or i32 %or9, %and11
  275. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  276. %and14 = and i32 %call13, 128
  277. %or15 = or i32 %or12, %and14
  278. %v = select i1 %b, i32 %or15, i32 5
  279. %shl = shl i32 %v, 10
  280. ret i32 %shl
  281. ; CHECK-LABEL: @tar7
  282. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  283. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  284. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  285. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  286. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  287. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  288. ; CHECK: ret i32
  289. }
  290. ; Function Attrs: nounwind readnone
  291. define signext i16 @tar8(i32 signext %x) #0 {
  292. entry:
  293. %call = tail call signext i32 @foo(i32 signext 5) #0
  294. %and = and i32 %call, 33554432
  295. %or = or i32 %and, %x
  296. %call1 = tail call signext i32 @foo(i32 signext 3) #0
  297. %and2 = and i32 %call1, 67108864
  298. %or3 = or i32 %or, %and2
  299. %call4 = tail call signext i32 @foo(i32 signext 2) #0
  300. %and5 = and i32 %call4, 16
  301. %or6 = or i32 %or3, %and5
  302. %call7 = tail call signext i32 @foo(i32 signext 1) #0
  303. %and8 = and i32 %call7, 32
  304. %or9 = or i32 %or6, %and8
  305. %call10 = tail call signext i32 @foo(i32 signext 0) #0
  306. %and11 = and i32 %call10, 64
  307. %or12 = or i32 %or9, %and11
  308. %call13 = tail call signext i32 @foo(i32 signext 4) #0
  309. %and14 = and i32 %call13, 128
  310. %or15 = or i32 %or12, %and14
  311. %tr = trunc i32 %or15 to i16
  312. ret i16 %tr
  313. ; CHECK-LABEL: @tar8
  314. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
  315. ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
  316. ; CHECK: tail call signext i32 @foo(i32 signext 2)
  317. ; CHECK: tail call signext i32 @foo(i32 signext 1)
  318. ; CHECK: tail call signext i32 @foo(i32 signext 0)
  319. ; CHECK: tail call signext i32 @foo(i32 signext 4)
  320. ; CHECK: ret i16
  321. }
  322. attributes #0 = { nounwind readnone }
  323. attributes #1 = { nounwind }