basic.ll 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ; RUN: opt -lower-expect -strip-dead-prototypes -S -o - < %s | FileCheck %s
  2. ; RUN: opt -S -passes=lower-expect < %s | opt -strip-dead-prototypes -S | FileCheck %s
  3. ; CHECK-LABEL: @test1(
  4. define i32 @test1(i32 %x) nounwind uwtable ssp {
  5. entry:
  6. %retval = alloca i32, align 4
  7. %x.addr = alloca i32, align 4
  8. store i32 %x, i32* %x.addr, align 4
  9. %tmp = load i32, i32* %x.addr, align 4
  10. %cmp = icmp sgt i32 %tmp, 1
  11. %conv = zext i1 %cmp to i32
  12. %conv1 = sext i32 %conv to i64
  13. %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)
  14. %tobool = icmp ne i64 %expval, 0
  15. ; CHECK: !prof !0
  16. ; CHECK-NOT: @llvm.expect
  17. br i1 %tobool, label %if.then, label %if.end
  18. if.then: ; preds = %entry
  19. %call = call i32 (...) @f()
  20. store i32 %call, i32* %retval
  21. br label %return
  22. if.end: ; preds = %entry
  23. store i32 1, i32* %retval
  24. br label %return
  25. return: ; preds = %if.end, %if.then
  26. %0 = load i32, i32* %retval
  27. ret i32 %0
  28. }
  29. declare i64 @llvm.expect.i64(i64, i64) nounwind readnone
  30. declare i32 @f(...)
  31. ; CHECK-LABEL: @test2(
  32. define i32 @test2(i32 %x) nounwind uwtable ssp {
  33. entry:
  34. %retval = alloca i32, align 4
  35. %x.addr = alloca i32, align 4
  36. store i32 %x, i32* %x.addr, align 4
  37. %tmp = load i32, i32* %x.addr, align 4
  38. %conv = sext i32 %tmp to i64
  39. %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  40. %tobool = icmp ne i64 %expval, 0
  41. ; CHECK: !prof !0
  42. ; CHECK-NOT: @llvm.expect
  43. br i1 %tobool, label %if.then, label %if.end
  44. if.then: ; preds = %entry
  45. %call = call i32 (...) @f()
  46. store i32 %call, i32* %retval
  47. br label %return
  48. if.end: ; preds = %entry
  49. store i32 1, i32* %retval
  50. br label %return
  51. return: ; preds = %if.end, %if.then
  52. %0 = load i32, i32* %retval
  53. ret i32 %0
  54. }
  55. ; CHECK-LABEL: @test3(
  56. define i32 @test3(i32 %x) nounwind uwtable ssp {
  57. entry:
  58. %retval = alloca i32, align 4
  59. %x.addr = alloca i32, align 4
  60. store i32 %x, i32* %x.addr, align 4
  61. %tmp = load i32, i32* %x.addr, align 4
  62. %tobool = icmp ne i32 %tmp, 0
  63. %lnot = xor i1 %tobool, true
  64. %lnot.ext = zext i1 %lnot to i32
  65. %conv = sext i32 %lnot.ext to i64
  66. %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  67. %tobool1 = icmp ne i64 %expval, 0
  68. ; CHECK: !prof !0
  69. ; CHECK-NOT: @llvm.expect
  70. br i1 %tobool1, label %if.then, label %if.end
  71. if.then: ; preds = %entry
  72. %call = call i32 (...) @f()
  73. store i32 %call, i32* %retval
  74. br label %return
  75. if.end: ; preds = %entry
  76. store i32 1, i32* %retval
  77. br label %return
  78. return: ; preds = %if.end, %if.then
  79. %0 = load i32, i32* %retval
  80. ret i32 %0
  81. }
  82. ; CHECK-LABEL: @test4(
  83. define i32 @test4(i32 %x) nounwind uwtable ssp {
  84. entry:
  85. %retval = alloca i32, align 4
  86. %x.addr = alloca i32, align 4
  87. store i32 %x, i32* %x.addr, align 4
  88. %tmp = load i32, i32* %x.addr, align 4
  89. %tobool = icmp ne i32 %tmp, 0
  90. %lnot = xor i1 %tobool, true
  91. %lnot1 = xor i1 %lnot, true
  92. %lnot.ext = zext i1 %lnot1 to i32
  93. %conv = sext i32 %lnot.ext to i64
  94. %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  95. %tobool2 = icmp ne i64 %expval, 0
  96. ; CHECK: !prof !0
  97. ; CHECK-NOT: @llvm.expect
  98. br i1 %tobool2, label %if.then, label %if.end
  99. if.then: ; preds = %entry
  100. %call = call i32 (...) @f()
  101. store i32 %call, i32* %retval
  102. br label %return
  103. if.end: ; preds = %entry
  104. store i32 1, i32* %retval
  105. br label %return
  106. return: ; preds = %if.end, %if.then
  107. %0 = load i32, i32* %retval
  108. ret i32 %0
  109. }
  110. ; CHECK-LABEL: @test5(
  111. define i32 @test5(i32 %x) nounwind uwtable ssp {
  112. entry:
  113. %retval = alloca i32, align 4
  114. %x.addr = alloca i32, align 4
  115. store i32 %x, i32* %x.addr, align 4
  116. %tmp = load i32, i32* %x.addr, align 4
  117. %cmp = icmp slt i32 %tmp, 0
  118. %conv = zext i1 %cmp to i32
  119. %conv1 = sext i32 %conv to i64
  120. %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 0)
  121. %tobool = icmp ne i64 %expval, 0
  122. ; CHECK: !prof !1
  123. ; CHECK-NOT: @llvm.expect
  124. br i1 %tobool, label %if.then, label %if.end
  125. if.then: ; preds = %entry
  126. %call = call i32 (...) @f()
  127. store i32 %call, i32* %retval
  128. br label %return
  129. if.end: ; preds = %entry
  130. store i32 1, i32* %retval
  131. br label %return
  132. return: ; preds = %if.end, %if.then
  133. %0 = load i32, i32* %retval
  134. ret i32 %0
  135. }
  136. ; CHECK-LABEL: @test6(
  137. define i32 @test6(i32 %x) nounwind uwtable ssp {
  138. entry:
  139. %retval = alloca i32, align 4
  140. %x.addr = alloca i32, align 4
  141. store i32 %x, i32* %x.addr, align 4
  142. %tmp = load i32, i32* %x.addr, align 4
  143. %conv = sext i32 %tmp to i64
  144. %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  145. ; CHECK: !prof !2
  146. ; CHECK-NOT: @llvm.expect
  147. switch i64 %expval, label %sw.epilog [
  148. i64 1, label %sw.bb
  149. i64 2, label %sw.bb
  150. ]
  151. sw.bb: ; preds = %entry, %entry
  152. store i32 0, i32* %retval
  153. br label %return
  154. sw.epilog: ; preds = %entry
  155. store i32 1, i32* %retval
  156. br label %return
  157. return: ; preds = %sw.epilog, %sw.bb
  158. %0 = load i32, i32* %retval
  159. ret i32 %0
  160. }
  161. ; CHECK-LABEL: @test7(
  162. define i32 @test7(i32 %x) nounwind uwtable ssp {
  163. entry:
  164. %retval = alloca i32, align 4
  165. %x.addr = alloca i32, align 4
  166. store i32 %x, i32* %x.addr, align 4
  167. %tmp = load i32, i32* %x.addr, align 4
  168. %conv = sext i32 %tmp to i64
  169. %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  170. ; CHECK: !prof !3
  171. ; CHECK-NOT: @llvm.expect
  172. switch i64 %expval, label %sw.epilog [
  173. i64 2, label %sw.bb
  174. i64 3, label %sw.bb
  175. ]
  176. sw.bb: ; preds = %entry, %entry
  177. %tmp1 = load i32, i32* %x.addr, align 4
  178. store i32 %tmp1, i32* %retval
  179. br label %return
  180. sw.epilog: ; preds = %entry
  181. store i32 0, i32* %retval
  182. br label %return
  183. return: ; preds = %sw.epilog, %sw.bb
  184. %0 = load i32, i32* %retval
  185. ret i32 %0
  186. }
  187. ; CHECK-LABEL: @test8(
  188. define i32 @test8(i32 %x) nounwind uwtable ssp {
  189. entry:
  190. %retval = alloca i32, align 4
  191. %x.addr = alloca i32, align 4
  192. store i32 %x, i32* %x.addr, align 4
  193. %tmp = load i32, i32* %x.addr, align 4
  194. %cmp = icmp sgt i32 %tmp, 1
  195. %conv = zext i1 %cmp to i32
  196. %expval = call i32 @llvm.expect.i32(i32 %conv, i32 1)
  197. %tobool = icmp ne i32 %expval, 0
  198. ; CHECK: !prof !0
  199. ; CHECK-NOT: @llvm.expect
  200. br i1 %tobool, label %if.then, label %if.end
  201. if.then: ; preds = %entry
  202. %call = call i32 (...) @f()
  203. store i32 %call, i32* %retval
  204. br label %return
  205. if.end: ; preds = %entry
  206. store i32 1, i32* %retval
  207. br label %return
  208. return: ; preds = %if.end, %if.then
  209. %0 = load i32, i32* %retval
  210. ret i32 %0
  211. }
  212. declare i32 @llvm.expect.i32(i32, i32) nounwind readnone
  213. ; CHECK-LABEL: @test9(
  214. define i32 @test9(i32 %x) nounwind uwtable ssp {
  215. entry:
  216. %retval = alloca i32, align 4
  217. %x.addr = alloca i32, align 4
  218. store i32 %x, i32* %x.addr, align 4
  219. %tmp = load i32, i32* %x.addr, align 4
  220. %cmp = icmp sgt i32 %tmp, 1
  221. %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1)
  222. ; CHECK: !prof !0
  223. ; CHECK-NOT: @llvm.expect
  224. br i1 %expval, label %if.then, label %if.end
  225. if.then: ; preds = %entry
  226. %call = call i32 (...) @f()
  227. store i32 %call, i32* %retval
  228. br label %return
  229. if.end: ; preds = %entry
  230. store i32 1, i32* %retval
  231. br label %return
  232. return: ; preds = %if.end, %if.then
  233. %0 = load i32, i32* %retval
  234. ret i32 %0
  235. }
  236. declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
  237. ; CHECK: !0 = !{!"branch_weights", i32 64, i32 4}
  238. ; CHECK: !1 = !{!"branch_weights", i32 4, i32 64}
  239. ; CHECK: !2 = !{!"branch_weights", i32 4, i32 64, i32 4}
  240. ; CHECK: !3 = !{!"branch_weights", i32 64, i32 4, i32 4}