c-general.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. // Test instrumentation of general constructs in C.
  2. // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN %s
  3. // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
  4. // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
  5. // Also check compatibility with older profiles.
  6. // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instr-use=%S/Inputs/c-general.profdata.v1 | FileCheck -check-prefix=PGOUSE %s
  7. // PGOGEN: @[[SLC:__llvm_profile_counters_simple_loops]] = private global [4 x i64] zeroinitializer
  8. // PGOGEN: @[[IFC:__llvm_profile_counters_conditionals]] = private global [11 x i64] zeroinitializer
  9. // PGOGEN: @[[EEC:__llvm_profile_counters_early_exits]] = private global [9 x i64] zeroinitializer
  10. // PGOGEN: @[[JMC:__llvm_profile_counters_jumps]] = private global [22 x i64] zeroinitializer
  11. // PGOGEN: @[[SWC:__llvm_profile_counters_switches]] = private global [19 x i64] zeroinitializer
  12. // PGOGEN: @[[BSC:__llvm_profile_counters_big_switch]] = private global [17 x i64] zeroinitializer
  13. // PGOGEN: @[[BOC:__llvm_profile_counters_boolean_operators]] = private global [8 x i64] zeroinitializer
  14. // PGOGEN: @[[BLC:__llvm_profile_counters_boolop_loops]] = private global [9 x i64] zeroinitializer
  15. // PGOGEN: @[[COC:__llvm_profile_counters_conditional_operator]] = private global [3 x i64] zeroinitializer
  16. // PGOGEN: @[[DFC:__llvm_profile_counters_do_fallthrough]] = private global [4 x i64] zeroinitializer
  17. // PGOGEN: @[[MAC:__llvm_profile_counters_main]] = private global [1 x i64] zeroinitializer
  18. // PGOGEN: @[[STC:"__llvm_profile_counters_c-general.c:static_func"]] = private global [2 x i64] zeroinitializer
  19. // PGOGEN-LABEL: @simple_loops()
  20. // PGOUSE-LABEL: @simple_loops()
  21. // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 0
  22. void simple_loops() {
  23. int i;
  24. // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 1
  25. // PGOUSE: br {{.*}} !prof ![[SL1:[0-9]+]]
  26. for (i = 0; i < 100; ++i) {
  27. }
  28. // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 2
  29. // PGOUSE: br {{.*}} !prof ![[SL2:[0-9]+]]
  30. while (i > 0)
  31. i--;
  32. // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 3
  33. // PGOUSE: br {{.*}} !prof ![[SL3:[0-9]+]]
  34. do {} while (i++ < 75);
  35. // PGOGEN-NOT: store {{.*}} @[[SLC]],
  36. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  37. }
  38. // PGOGEN-LABEL: @conditionals()
  39. // PGOUSE-LABEL: @conditionals()
  40. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 0
  41. void conditionals() {
  42. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 1
  43. // PGOUSE: br {{.*}} !prof ![[IF1:[0-9]+]]
  44. for (int i = 0; i < 100; ++i) {
  45. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 2
  46. // PGOUSE: br {{.*}} !prof ![[IF2:[0-9]+]]
  47. if (i % 2) {
  48. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 3
  49. // PGOUSE: br {{.*}} !prof ![[IF3:[0-9]+]]
  50. if (i) {}
  51. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 4
  52. // PGOUSE: br {{.*}} !prof ![[IF4:[0-9]+]]
  53. } else if (i % 3) {
  54. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 5
  55. // PGOUSE: br {{.*}} !prof ![[IF5:[0-9]+]]
  56. if (i) {}
  57. } else {
  58. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 6
  59. // PGOUSE: br {{.*}} !prof ![[IF6:[0-9]+]]
  60. if (i) {}
  61. }
  62. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 8
  63. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 7
  64. // PGOUSE: br {{.*}} !prof ![[IF7:[0-9]+]]
  65. if (1 && i) {}
  66. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 10
  67. // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 9
  68. // PGOUSE: br {{.*}} !prof ![[IF8:[0-9]+]]
  69. if (0 || i) {}
  70. }
  71. // PGOGEN-NOT: store {{.*}} @[[IFC]],
  72. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  73. }
  74. // PGOGEN-LABEL: @early_exits()
  75. // PGOUSE-LABEL: @early_exits()
  76. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 0
  77. void early_exits() {
  78. int i = 0;
  79. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 1
  80. // PGOUSE: br {{.*}} !prof ![[EE1:[0-9]+]]
  81. if (i) {}
  82. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 2
  83. // PGOUSE: br {{.*}} !prof ![[EE2:[0-9]+]]
  84. while (i < 100) {
  85. i++;
  86. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 3
  87. // PGOUSE: br {{.*}} !prof ![[EE3:[0-9]+]]
  88. if (i > 50)
  89. break;
  90. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 4
  91. // PGOUSE: br {{.*}} !prof ![[EE4:[0-9]+]]
  92. if (i % 2)
  93. continue;
  94. }
  95. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 5
  96. // PGOUSE: br {{.*}} !prof ![[EE5:[0-9]+]]
  97. if (i) {}
  98. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 6
  99. do {
  100. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 7
  101. // PGOUSE: br {{.*}} !prof ![[EE6:[0-9]+]]
  102. if (i > 75)
  103. return;
  104. else
  105. i++;
  106. // PGOUSE: br {{.*}} !prof ![[EE7:[0-9]+]]
  107. } while (i < 100);
  108. // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 8
  109. // Never reached -> no weights
  110. if (i) {}
  111. // PGOGEN-NOT: store {{.*}} @[[EEC]],
  112. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  113. }
  114. // PGOGEN-LABEL: @jumps()
  115. // PGOUSE-LABEL: @jumps()
  116. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 0
  117. void jumps() {
  118. int i;
  119. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 1
  120. // PGOUSE: br {{.*}} !prof ![[JM1:[0-9]+]]
  121. for (i = 0; i < 2; ++i) {
  122. goto outofloop;
  123. // Never reached -> no weights
  124. if (i) {}
  125. }
  126. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 3
  127. outofloop:
  128. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 4
  129. // PGOUSE: br {{.*}} !prof ![[JM2:[0-9]+]]
  130. if (i) {}
  131. goto loop1;
  132. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 5
  133. // PGOUSE: br {{.*}} !prof ![[JM3:[0-9]+]]
  134. while (i) {
  135. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 6
  136. loop1:
  137. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 7
  138. // PGOUSE: br {{.*}} !prof ![[JM4:[0-9]+]]
  139. if (i) {}
  140. }
  141. goto loop2;
  142. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 8
  143. first:
  144. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 9
  145. second:
  146. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 10
  147. third:
  148. i++;
  149. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 11
  150. // PGOUSE: br {{.*}} !prof ![[JM5:[0-9]+]]
  151. if (i < 3)
  152. goto loop2;
  153. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 12
  154. // PGOUSE: br {{.*}} !prof ![[JM6:[0-9]+]]
  155. while (i < 3) {
  156. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 13
  157. loop2:
  158. // PGOUSE: switch {{.*}} [
  159. // PGOUSE: ], !prof ![[JM7:[0-9]+]]
  160. switch (i) {
  161. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 15
  162. case 0:
  163. goto first;
  164. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 16
  165. case 1:
  166. goto second;
  167. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 17
  168. case 2:
  169. goto third;
  170. }
  171. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 14
  172. }
  173. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 18
  174. // PGOUSE: br {{.*}} !prof ![[JM8:[0-9]+]]
  175. for (i = 0; i < 10; ++i) {
  176. goto withinloop;
  177. // never reached -> no weights
  178. if (i) {}
  179. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 20
  180. withinloop:
  181. // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 21
  182. // PGOUSE: br {{.*}} !prof ![[JM9:[0-9]+]]
  183. if (i) {}
  184. }
  185. // PGOGEN-NOT: store {{.*}} @[[JMC]],
  186. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  187. }
  188. // PGOGEN-LABEL: @switches()
  189. // PGOUSE-LABEL: @switches()
  190. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 0
  191. void switches() {
  192. static int weights[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};
  193. // No cases -> no weights
  194. switch (weights[0]) {
  195. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 2
  196. default:
  197. break;
  198. }
  199. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 1
  200. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 3
  201. // PGOUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
  202. for (int i = 0, len = sizeof(weights) / sizeof(weights[0]); i < len; ++i) {
  203. // PGOUSE: switch {{.*}} [
  204. // PGOUSE: ], !prof ![[SW2:[0-9]+]]
  205. switch (i[weights]) {
  206. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 5
  207. case 1:
  208. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 6
  209. // PGOUSE: br {{.*}} !prof ![[SW3:[0-9]+]]
  210. if (i) {}
  211. // fallthrough
  212. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 7
  213. case 2:
  214. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 8
  215. // PGOUSE: br {{.*}} !prof ![[SW4:[0-9]+]]
  216. if (i) {}
  217. break;
  218. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 9
  219. case 3:
  220. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 10
  221. // PGOUSE: br {{.*}} !prof ![[SW5:[0-9]+]]
  222. if (i) {}
  223. continue;
  224. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 11
  225. case 4:
  226. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 12
  227. // PGOUSE: br {{.*}} !prof ![[SW6:[0-9]+]]
  228. if (i) {}
  229. // PGOUSE: switch {{.*}} [
  230. // PGOUSE: ], !prof ![[SW7:[0-9]+]]
  231. switch (i) {
  232. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 14
  233. case 6 ... 9:
  234. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 15
  235. // PGOUSE: br {{.*}} !prof ![[SW8:[0-9]+]]
  236. if (i) {}
  237. continue;
  238. }
  239. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 13
  240. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 16
  241. default:
  242. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 17
  243. // PGOUSE: br {{.*}} !prof ![[SW9:[0-9]+]]
  244. if (i == len - 1)
  245. return;
  246. }
  247. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 4
  248. }
  249. // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 18
  250. // Never reached -> no weights
  251. if (weights[0]) {}
  252. // PGOGEN-NOT: store {{.*}} @[[SWC]],
  253. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  254. }
  255. // PGOGEN-LABEL: @big_switch()
  256. // PGOUSE-LABEL: @big_switch()
  257. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 0
  258. void big_switch() {
  259. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 1
  260. // PGOUSE: br {{.*}} !prof ![[BS1:[0-9]+]]
  261. for (int i = 0; i < 32; ++i) {
  262. // PGOUSE: switch {{.*}} [
  263. // PGOUSE: ], !prof ![[BS2:[0-9]+]]
  264. switch (1 << i) {
  265. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 3
  266. case (1 << 0):
  267. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 4
  268. // PGOUSE: br {{.*}} !prof ![[BS3:[0-9]+]]
  269. if (i) {}
  270. // fallthrough
  271. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 5
  272. case (1 << 1):
  273. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 6
  274. // PGOUSE: br {{.*}} !prof ![[BS4:[0-9]+]]
  275. if (i) {}
  276. break;
  277. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 7
  278. case (1 << 2) ... (1 << 12):
  279. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 8
  280. // PGOUSE: br {{.*}} !prof ![[BS5:[0-9]+]]
  281. if (i) {}
  282. break;
  283. // The branch for the large case range above appears after the case body
  284. // PGOUSE: br {{.*}} !prof ![[BS6:[0-9]+]]
  285. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 9
  286. case (1 << 13):
  287. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 10
  288. // PGOUSE: br {{.*}} !prof ![[BS7:[0-9]+]]
  289. if (i) {}
  290. break;
  291. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 11
  292. case (1 << 14) ... (1 << 28):
  293. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 12
  294. // PGOUSE: br {{.*}} !prof ![[BS8:[0-9]+]]
  295. if (i) {}
  296. break;
  297. // The branch for the large case range above appears after the case body
  298. // PGOUSE: br {{.*}} !prof ![[BS9:[0-9]+]]
  299. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 13
  300. case (1 << 29) ... ((1 << 29) + 1):
  301. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 14
  302. // PGOUSE: br {{.*}} !prof ![[BS10:[0-9]+]]
  303. if (i) {}
  304. break;
  305. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 15
  306. default:
  307. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 16
  308. // PGOUSE: br {{.*}} !prof ![[BS11:[0-9]+]]
  309. if (i) {}
  310. break;
  311. }
  312. // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 2
  313. }
  314. // PGOGEN-NOT: store {{.*}} @[[BSC]],
  315. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  316. // PGOUSE: ret void
  317. }
  318. // PGOGEN-LABEL: @boolean_operators()
  319. // PGOUSE-LABEL: @boolean_operators()
  320. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 0
  321. void boolean_operators() {
  322. int v;
  323. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 1
  324. // PGOUSE: br {{.*}} !prof ![[BO1:[0-9]+]]
  325. for (int i = 0; i < 100; ++i) {
  326. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 2
  327. // PGOUSE: br {{.*}} !prof ![[BO2:[0-9]+]]
  328. v = i % 3 || i;
  329. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 3
  330. // PGOUSE: br {{.*}} !prof ![[BO3:[0-9]+]]
  331. v = i % 3 && i;
  332. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 5
  333. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 4
  334. // PGOUSE: br {{.*}} !prof ![[BO4:[0-9]+]]
  335. // PGOUSE: br {{.*}} !prof ![[BO5:[0-9]+]]
  336. v = i % 3 || i % 2 || i;
  337. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 7
  338. // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 6
  339. // PGOUSE: br {{.*}} !prof ![[BO6:[0-9]+]]
  340. // PGOUSE: br {{.*}} !prof ![[BO7:[0-9]+]]
  341. v = i % 2 && i % 3 && i;
  342. }
  343. // PGOGEN-NOT: store {{.*}} @[[BOC]],
  344. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  345. }
  346. // PGOGEN-LABEL: @boolop_loops()
  347. // PGOUSE-LABEL: @boolop_loops()
  348. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 0
  349. void boolop_loops() {
  350. int i = 100;
  351. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 2
  352. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 1
  353. // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]
  354. // PGOUSE: br {{.*}} !prof ![[BL2:[0-9]+]]
  355. while (i && i > 50)
  356. i--;
  357. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 4
  358. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 3
  359. // PGOUSE: br {{.*}} !prof ![[BL3:[0-9]+]]
  360. // PGOUSE: br {{.*}} !prof ![[BL4:[0-9]+]]
  361. while ((i % 2) || (i > 0))
  362. i--;
  363. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 6
  364. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 5
  365. // PGOUSE: br {{.*}} !prof ![[BL5:[0-9]+]]
  366. // PGOUSE: br {{.*}} !prof ![[BL6:[0-9]+]]
  367. for (i = 100; i && i > 50; --i);
  368. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 8
  369. // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 7
  370. // PGOUSE: br {{.*}} !prof ![[BL7:[0-9]+]]
  371. // PGOUSE: br {{.*}} !prof ![[BL8:[0-9]+]]
  372. for (; (i % 2) || (i > 0); --i);
  373. // PGOGEN-NOT: store {{.*}} @[[BLC]],
  374. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  375. }
  376. // PGOGEN-LABEL: @conditional_operator()
  377. // PGOUSE-LABEL: @conditional_operator()
  378. // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 0
  379. void conditional_operator() {
  380. int i = 100;
  381. // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 1
  382. // PGOUSE: br {{.*}} !prof ![[CO1:[0-9]+]]
  383. int j = i < 50 ? i : 1;
  384. // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 2
  385. // PGOUSE: br {{.*}} !prof ![[CO2:[0-9]+]]
  386. int k = i ?: 0;
  387. // PGOGEN-NOT: store {{.*}} @[[COC]],
  388. // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  389. }
  390. // PGOGEN-LABEL: @do_fallthrough()
  391. // PGOUSE-LABEL: @do_fallthrough()
  392. // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 0
  393. void do_fallthrough() {
  394. // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 1
  395. // PGOUSE: br {{.*}} !prof ![[DF1:[0-9]+]]
  396. for (int i = 0; i < 10; ++i) {
  397. int j = 0;
  398. // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 2
  399. do {
  400. // The number of exits out of this do-loop via the break statement
  401. // exceeds the counter value for the loop (which does not include the
  402. // fallthrough count). Make sure that does not violate any assertions.
  403. // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 3
  404. // PGOUSE: br {{.*}} !prof ![[DF3:[0-9]+]]
  405. if (i < 8) break;
  406. j++;
  407. // PGOUSE: br {{.*}} !prof ![[DF2:[0-9]+]]
  408. } while (j < 2);
  409. }
  410. }
  411. // PGOGEN-LABEL: @static_func()
  412. // PGOUSE-LABEL: @static_func()
  413. // PGOGEN: store {{.*}} @[[STC]], i64 0, i64 0
  414. static void static_func() {
  415. // PGOGEN: store {{.*}} @[[STC]], i64 0, i64 1
  416. // PGOUSE: br {{.*}} !prof ![[ST1:[0-9]+]]
  417. for (int i = 0; i < 10; ++i) {
  418. }
  419. }
  420. // PGOUSE-DAG: ![[SL1]] = !{!"branch_weights", i32 101, i32 2}
  421. // PGOUSE-DAG: ![[SL2]] = !{!"branch_weights", i32 101, i32 2}
  422. // PGOUSE-DAG: ![[SL3]] = !{!"branch_weights", i32 76, i32 2}
  423. // PGOUSE-DAG: ![[EE1]] = !{!"branch_weights", i32 1, i32 2}
  424. // PGOUSE-DAG: ![[EE2]] = !{!"branch_weights", i32 52, i32 1}
  425. // PGOUSE-DAG: ![[EE3]] = !{!"branch_weights", i32 2, i32 51}
  426. // PGOUSE-DAG: ![[EE4]] = !{!"branch_weights", i32 26, i32 26}
  427. // PGOUSE-DAG: ![[EE5]] = !{!"branch_weights", i32 2, i32 1}
  428. // PGOUSE-DAG: ![[EE6]] = !{!"branch_weights", i32 2, i32 26}
  429. // PGOUSE-DAG: ![[EE7]] = !{!"branch_weights", i32 26, i32 1}
  430. // PGOUSE-DAG: ![[IF1]] = !{!"branch_weights", i32 101, i32 2}
  431. // PGOUSE-DAG: ![[IF2]] = !{!"branch_weights", i32 51, i32 51}
  432. // PGOUSE-DAG: ![[IF3]] = !{!"branch_weights", i32 51, i32 1}
  433. // PGOUSE-DAG: ![[IF4]] = !{!"branch_weights", i32 34, i32 18}
  434. // PGOUSE-DAG: ![[IF5]] = !{!"branch_weights", i32 34, i32 1}
  435. // PGOUSE-DAG: ![[IF6]] = !{!"branch_weights", i32 17, i32 2}
  436. // PGOUSE-DAG: ![[IF7]] = !{!"branch_weights", i32 100, i32 2}
  437. // PGOUSE-DAG: ![[IF8]] = !{!"branch_weights", i32 100, i32 2}
  438. // PGOUSE-DAG: ![[JM1]] = !{!"branch_weights", i32 2, i32 1}
  439. // PGOUSE-DAG: ![[JM2]] = !{!"branch_weights", i32 1, i32 2}
  440. // PGOUSE-DAG: ![[JM3]] = !{!"branch_weights", i32 1, i32 2}
  441. // PGOUSE-DAG: ![[JM4]] = !{!"branch_weights", i32 1, i32 2}
  442. // PGOUSE-DAG: ![[JM5]] = !{!"branch_weights", i32 3, i32 2}
  443. // PGOUSE-DAG: ![[JM6]] = !{!"branch_weights", i32 1, i32 2}
  444. // PGOUSE-DAG: ![[JM7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2}
  445. // PGOUSE-DAG: ![[JM8]] = !{!"branch_weights", i32 11, i32 2}
  446. // PGOUSE-DAG: ![[JM9]] = !{!"branch_weights", i32 10, i32 2}
  447. // PGOUSE-DAG: ![[SW1]] = !{!"branch_weights", i32 16, i32 1}
  448. // PGOUSE-DAG: ![[SW2]] = !{!"branch_weights", i32 6, i32 2, i32 3, i32 4, i32 5}
  449. // PGOUSE-DAG: ![[SW3]] = !{!"branch_weights", i32 1, i32 2}
  450. // PGOUSE-DAG: ![[SW4]] = !{!"branch_weights", i32 3, i32 2}
  451. // PGOUSE-DAG: ![[SW5]] = !{!"branch_weights", i32 4, i32 1}
  452. // PGOUSE-DAG: ![[SW6]] = !{!"branch_weights", i32 5, i32 1}
  453. // PGOUSE-DAG: ![[SW7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2, i32 2}
  454. // PGOUSE-DAG: ![[SW8]] = !{!"branch_weights", i32 5, i32 1}
  455. // PGOUSE-DAG: ![[SW9]] = !{!"branch_weights", i32 2, i32 5}
  456. // PGOUSE-DAG: ![[BS1]] = !{!"branch_weights", i32 33, i32 2}
  457. // PGOUSE-DAG: ![[BS2]] = !{!"branch_weights", i32 29, i32 2, i32 2, i32 2, i32 2, i32 1}
  458. // PGOUSE-DAG: ![[BS3]] = !{!"branch_weights", i32 1, i32 2}
  459. // PGOUSE-DAG: ![[BS4]] = !{!"branch_weights", i32 2, i32 2}
  460. // PGOUSE-DAG: ![[BS5]] = !{!"branch_weights", i32 12, i32 1}
  461. // PGOUSE-DAG: ![[BS6]] = !{!"branch_weights", i32 12, i32 3}
  462. // PGOUSE-DAG: ![[BS7]] = !{!"branch_weights", i32 2, i32 1}
  463. // PGOUSE-DAG: ![[BS8]] = !{!"branch_weights", i32 16, i32 1}
  464. // PGOUSE-DAG: ![[BS9]] = !{!"branch_weights", i32 16, i32 14}
  465. // PGOUSE-DAG: ![[BS10]] = !{!"branch_weights", i32 2, i32 1}
  466. // PGOUSE-DAG: ![[BS11]] = !{!"branch_weights", i32 3, i32 1}
  467. // PGOUSE-DAG: ![[BO1]] = !{!"branch_weights", i32 101, i32 2}
  468. // PGOUSE-DAG: ![[BO2]] = !{!"branch_weights", i32 67, i32 35}
  469. // PGOUSE-DAG: ![[BO3]] = !{!"branch_weights", i32 67, i32 35}
  470. // PGOUSE-DAG: ![[BO4]] = !{!"branch_weights", i32 67, i32 35}
  471. // PGOUSE-DAG: ![[BO5]] = !{!"branch_weights", i32 18, i32 18}
  472. // PGOUSE-DAG: ![[BO6]] = !{!"branch_weights", i32 51, i32 51}
  473. // PGOUSE-DAG: ![[BO7]] = !{!"branch_weights", i32 34, i32 18}
  474. // PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 52, i32 1}
  475. // PGOUSE-DAG: ![[BL2]] = !{!"branch_weights", i32 51, i32 2}
  476. // PGOUSE-DAG: ![[BL3]] = !{!"branch_weights", i32 26, i32 27}
  477. // PGOUSE-DAG: ![[BL4]] = !{!"branch_weights", i32 51, i32 2}
  478. // PGOUSE-DAG: ![[BL5]] = !{!"branch_weights", i32 52, i32 1}
  479. // PGOUSE-DAG: ![[BL6]] = !{!"branch_weights", i32 51, i32 2}
  480. // PGOUSE-DAG: ![[BL7]] = !{!"branch_weights", i32 26, i32 27}
  481. // PGOUSE-DAG: ![[BL8]] = !{!"branch_weights", i32 51, i32 2}
  482. // PGOUSE-DAG: ![[CO1]] = !{!"branch_weights", i32 1, i32 2}
  483. // PGOUSE-DAG: ![[CO2]] = !{!"branch_weights", i32 2, i32 1}
  484. // PGOUSE-DAG: ![[DF1]] = !{!"branch_weights", i32 11, i32 2}
  485. // PGOUSE-DAG: ![[DF2]] = !{!"branch_weights", i32 3, i32 3}
  486. // PGOUSE-DAG: ![[DF3]] = !{!"branch_weights", i32 9, i32 5}
  487. // PGOUSE-DAG: ![[ST1]] = !{!"branch_weights", i32 11, i32 2}
  488. int main(int argc, const char *argv[]) {
  489. simple_loops();
  490. conditionals();
  491. early_exits();
  492. jumps();
  493. switches();
  494. big_switch();
  495. boolean_operators();
  496. boolop_loops();
  497. conditional_operator();
  498. do_fallthrough();
  499. static_func();
  500. return 0;
  501. }