2
0

rle.ll 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. ; RUN: opt < %s -default-data-layout="e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-n8:16:32" -basicaa -gvn -S -die | FileCheck %s
  2. ; RUN: opt < %s -default-data-layout="E-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-n32" -basicaa -gvn -S -die | FileCheck %s
  3. ;; Trivial RLE test.
  4. define i32 @test0(i32 %V, i32* %P) {
  5. store i32 %V, i32* %P
  6. %A = load i32, i32* %P
  7. ret i32 %A
  8. ; CHECK-LABEL: @test0(
  9. ; CHECK: ret i32 %V
  10. }
  11. ;;===----------------------------------------------------------------------===;;
  12. ;; Tests for crashers
  13. ;;===----------------------------------------------------------------------===;;
  14. ;; PR5016
  15. define i8 @crash0({i32, i32} %A, {i32, i32}* %P) {
  16. store {i32, i32} %A, {i32, i32}* %P
  17. %X = bitcast {i32, i32}* %P to i8*
  18. %Y = load i8, i8* %X
  19. ret i8 %Y
  20. }
  21. ;; No PR filed, crashed in CaptureTracker.
  22. declare void @helper()
  23. define void @crash1() {
  24. tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* undef, i64 undef, i32 1, i1 false) nounwind
  25. %tmp = load i8, i8* bitcast (void ()* @helper to i8*)
  26. %x = icmp eq i8 %tmp, 15
  27. ret void
  28. }
  29. ;;===----------------------------------------------------------------------===;;
  30. ;; Store -> Load and Load -> Load forwarding where src and dst are different
  31. ;; types, but where the base pointer is a must alias.
  32. ;;===----------------------------------------------------------------------===;;
  33. ;; i32 -> f32 forwarding.
  34. define float @coerce_mustalias1(i32 %V, i32* %P) {
  35. store i32 %V, i32* %P
  36. %P2 = bitcast i32* %P to float*
  37. %A = load float, float* %P2
  38. ret float %A
  39. ; CHECK-LABEL: @coerce_mustalias1(
  40. ; CHECK-NOT: load
  41. ; CHECK: ret float
  42. }
  43. ;; i32* -> float forwarding.
  44. define float @coerce_mustalias2(i32* %V, i32** %P) {
  45. store i32* %V, i32** %P
  46. %P2 = bitcast i32** %P to float*
  47. %A = load float, float* %P2
  48. ret float %A
  49. ; CHECK-LABEL: @coerce_mustalias2(
  50. ; CHECK-NOT: load
  51. ; CHECK: ret float
  52. }
  53. ;; float -> i32* forwarding.
  54. define i32* @coerce_mustalias3(float %V, float* %P) {
  55. store float %V, float* %P
  56. %P2 = bitcast float* %P to i32**
  57. %A = load i32*, i32** %P2
  58. ret i32* %A
  59. ; CHECK-LABEL: @coerce_mustalias3(
  60. ; CHECK-NOT: load
  61. ; CHECK: ret i32*
  62. }
  63. ;; i32 -> f32 load forwarding.
  64. define float @coerce_mustalias4(i32* %P, i1 %cond) {
  65. %A = load i32, i32* %P
  66. %P2 = bitcast i32* %P to float*
  67. %B = load float, float* %P2
  68. br i1 %cond, label %T, label %F
  69. T:
  70. ret float %B
  71. F:
  72. %X = bitcast i32 %A to float
  73. ret float %X
  74. ; CHECK-LABEL: @coerce_mustalias4(
  75. ; CHECK: %A = load i32, i32* %P
  76. ; CHECK-NOT: load
  77. ; CHECK: ret float
  78. ; CHECK: F:
  79. }
  80. ;; i32 -> i8 forwarding
  81. define i8 @coerce_mustalias5(i32 %V, i32* %P) {
  82. store i32 %V, i32* %P
  83. %P2 = bitcast i32* %P to i8*
  84. %A = load i8, i8* %P2
  85. ret i8 %A
  86. ; CHECK-LABEL: @coerce_mustalias5(
  87. ; CHECK-NOT: load
  88. ; CHECK: ret i8
  89. }
  90. ;; i64 -> float forwarding
  91. define float @coerce_mustalias6(i64 %V, i64* %P) {
  92. store i64 %V, i64* %P
  93. %P2 = bitcast i64* %P to float*
  94. %A = load float, float* %P2
  95. ret float %A
  96. ; CHECK-LABEL: @coerce_mustalias6(
  97. ; CHECK-NOT: load
  98. ; CHECK: ret float
  99. }
  100. ;; i64 -> i8* (32-bit) forwarding
  101. define i8* @coerce_mustalias7(i64 %V, i64* %P) {
  102. store i64 %V, i64* %P
  103. %P2 = bitcast i64* %P to i8**
  104. %A = load i8*, i8** %P2
  105. ret i8* %A
  106. ; CHECK-LABEL: @coerce_mustalias7(
  107. ; CHECK-NOT: load
  108. ; CHECK: ret i8*
  109. }
  110. ; memset -> i16 forwarding.
  111. define signext i16 @memset_to_i16_local(i16* %A) nounwind ssp {
  112. entry:
  113. %conv = bitcast i16* %A to i8*
  114. tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 1, i64 200, i32 1, i1 false)
  115. %arrayidx = getelementptr inbounds i16, i16* %A, i64 42
  116. %tmp2 = load i16, i16* %arrayidx
  117. ret i16 %tmp2
  118. ; CHECK-LABEL: @memset_to_i16_local(
  119. ; CHECK-NOT: load
  120. ; CHECK: ret i16 257
  121. }
  122. ; memset -> float forwarding.
  123. define float @memset_to_float_local(float* %A, i8 %Val) nounwind ssp {
  124. entry:
  125. %conv = bitcast float* %A to i8* ; <i8*> [#uses=1]
  126. tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 %Val, i64 400, i32 1, i1 false)
  127. %arrayidx = getelementptr inbounds float, float* %A, i64 42 ; <float*> [#uses=1]
  128. %tmp2 = load float, float* %arrayidx ; <float> [#uses=1]
  129. ret float %tmp2
  130. ; CHECK-LABEL: @memset_to_float_local(
  131. ; CHECK-NOT: load
  132. ; CHECK: zext
  133. ; CHECK-NEXT: shl
  134. ; CHECK-NEXT: or
  135. ; CHECK-NEXT: shl
  136. ; CHECK-NEXT: or
  137. ; CHECK-NEXT: bitcast
  138. ; CHECK-NEXT: ret float
  139. }
  140. ;; non-local memset -> i16 load forwarding.
  141. define i16 @memset_to_i16_nonlocal0(i16* %P, i1 %cond) {
  142. %P3 = bitcast i16* %P to i8*
  143. br i1 %cond, label %T, label %F
  144. T:
  145. tail call void @llvm.memset.p0i8.i64(i8* %P3, i8 1, i64 400, i32 1, i1 false)
  146. br label %Cont
  147. F:
  148. tail call void @llvm.memset.p0i8.i64(i8* %P3, i8 2, i64 400, i32 1, i1 false)
  149. br label %Cont
  150. Cont:
  151. %P2 = getelementptr i16, i16* %P, i32 4
  152. %A = load i16, i16* %P2
  153. ret i16 %A
  154. ; CHECK-LABEL: @memset_to_i16_nonlocal0(
  155. ; CHECK: Cont:
  156. ; CHECK-NEXT: %A = phi i16 [ 514, %F ], [ 257, %T ]
  157. ; CHECK-NOT: load
  158. ; CHECK: ret i16 %A
  159. }
  160. @GCst = constant {i32, float, i32 } { i32 42, float 14., i32 97 }
  161. @GCst_as1 = addrspace(1) constant {i32, float, i32 } { i32 42, float 14., i32 97 }
  162. ; memset -> float forwarding.
  163. define float @memcpy_to_float_local(float* %A) nounwind ssp {
  164. entry:
  165. %conv = bitcast float* %A to i8* ; <i8*> [#uses=1]
  166. tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %conv, i8* bitcast ({i32, float, i32 }* @GCst to i8*), i64 12, i32 1, i1 false)
  167. %arrayidx = getelementptr inbounds float, float* %A, i64 1 ; <float*> [#uses=1]
  168. %tmp2 = load float, float* %arrayidx ; <float> [#uses=1]
  169. ret float %tmp2
  170. ; CHECK-LABEL: @memcpy_to_float_local(
  171. ; CHECK-NOT: load
  172. ; CHECK: ret float 1.400000e+01
  173. }
  174. ; memcpy from address space 1
  175. define float @memcpy_to_float_local_as1(float* %A) nounwind ssp {
  176. entry:
  177. %conv = bitcast float* %A to i8* ; <i8*> [#uses=1]
  178. tail call void @llvm.memcpy.p0i8.p1i8.i64(i8* %conv, i8 addrspace(1)* bitcast ({i32, float, i32 } addrspace(1)* @GCst_as1 to i8 addrspace(1)*), i64 12, i32 1, i1 false)
  179. %arrayidx = getelementptr inbounds float, float* %A, i64 1 ; <float*> [#uses=1]
  180. %tmp2 = load float, float* %arrayidx ; <float> [#uses=1]
  181. ret float %tmp2
  182. ; CHECK-LABEL: @memcpy_to_float_local_as1(
  183. ; CHECK-NOT: load
  184. ; CHECK: ret float 1.400000e+01
  185. }
  186. ;; non-local i32/float -> i8 load forwarding.
  187. define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
  188. %P2 = bitcast i32* %P to float*
  189. %P3 = bitcast i32* %P to i8*
  190. br i1 %cond, label %T, label %F
  191. T:
  192. store i32 42, i32* %P
  193. br label %Cont
  194. F:
  195. store float 1.0, float* %P2
  196. br label %Cont
  197. Cont:
  198. %A = load i8, i8* %P3
  199. ret i8 %A
  200. ; CHECK-LABEL: @coerce_mustalias_nonlocal0(
  201. ; CHECK: Cont:
  202. ; CHECK: %A = phi i8 [
  203. ; CHECK-NOT: load
  204. ; CHECK: ret i8 %A
  205. }
  206. ;; non-local i32/float -> i8 load forwarding. This also tests that the "P3"
  207. ;; bitcast equivalence can be properly phi translated.
  208. define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) {
  209. %P2 = bitcast i32* %P to float*
  210. br i1 %cond, label %T, label %F
  211. T:
  212. store i32 42, i32* %P
  213. br label %Cont
  214. F:
  215. store float 1.0, float* %P2
  216. br label %Cont
  217. Cont:
  218. %P3 = bitcast i32* %P to i8*
  219. %A = load i8, i8* %P3
  220. ret i8 %A
  221. ; CHECK-LABEL: @coerce_mustalias_nonlocal1(
  222. ; CHECK: Cont:
  223. ; CHECK: %A = phi i8 [
  224. ; CHECK-NOT: load
  225. ; CHECK: ret i8 %A
  226. }
  227. ;; non-local i32 -> i8 partial redundancy load forwarding.
  228. define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
  229. %P3 = bitcast i32* %P to i8*
  230. br i1 %cond, label %T, label %F
  231. T:
  232. store i32 42, i32* %P
  233. br label %Cont
  234. F:
  235. br label %Cont
  236. Cont:
  237. %A = load i8, i8* %P3
  238. ret i8 %A
  239. ; CHECK-LABEL: @coerce_mustalias_pre0(
  240. ; CHECK: F:
  241. ; CHECK: load i8, i8* %P3
  242. ; CHECK: Cont:
  243. ; CHECK: %A = phi i8 [
  244. ; CHECK-NOT: load
  245. ; CHECK: ret i8 %A
  246. }
  247. ;;===----------------------------------------------------------------------===;;
  248. ;; Store -> Load and Load -> Load forwarding where src and dst are different
  249. ;; types, and the reload is an offset from the store pointer.
  250. ;;===----------------------------------------------------------------------===;;
  251. ;; i32 -> i8 forwarding.
  252. ;; PR4216
  253. define i8 @coerce_offset0(i32 %V, i32* %P) {
  254. store i32 %V, i32* %P
  255. %P2 = bitcast i32* %P to i8*
  256. %P3 = getelementptr i8, i8* %P2, i32 2
  257. %A = load i8, i8* %P3
  258. ret i8 %A
  259. ; CHECK-LABEL: @coerce_offset0(
  260. ; CHECK-NOT: load
  261. ; CHECK: ret i8
  262. }
  263. define i8 @coerce_offset0_addrspacecast(i32 %V, i32* %P) {
  264. store i32 %V, i32* %P
  265. %P2 = addrspacecast i32* %P to i8 addrspace(1)*
  266. %P3 = getelementptr i8, i8 addrspace(1)* %P2, i32 2
  267. %A = load i8, i8 addrspace(1)* %P3
  268. ret i8 %A
  269. ; CHECK-LABEL: @coerce_offset0_addrspacecast(
  270. ; CHECK-NOT: load
  271. ; CHECK: ret i8
  272. }
  273. ;; non-local i32/float -> i8 load forwarding.
  274. define i8 @coerce_offset_nonlocal0(i32* %P, i1 %cond) {
  275. %P2 = bitcast i32* %P to float*
  276. %P3 = bitcast i32* %P to i8*
  277. %P4 = getelementptr i8, i8* %P3, i32 2
  278. br i1 %cond, label %T, label %F
  279. T:
  280. store i32 57005, i32* %P
  281. br label %Cont
  282. F:
  283. store float 1.0, float* %P2
  284. br label %Cont
  285. Cont:
  286. %A = load i8, i8* %P4
  287. ret i8 %A
  288. ; CHECK-LABEL: @coerce_offset_nonlocal0(
  289. ; CHECK: Cont:
  290. ; CHECK: %A = phi i8 [
  291. ; CHECK-NOT: load
  292. ; CHECK: ret i8 %A
  293. }
  294. ;; non-local i32 -> i8 partial redundancy load forwarding.
  295. define i8 @coerce_offset_pre0(i32* %P, i1 %cond) {
  296. %P3 = bitcast i32* %P to i8*
  297. %P4 = getelementptr i8, i8* %P3, i32 2
  298. br i1 %cond, label %T, label %F
  299. T:
  300. store i32 42, i32* %P
  301. br label %Cont
  302. F:
  303. br label %Cont
  304. Cont:
  305. %A = load i8, i8* %P4
  306. ret i8 %A
  307. ; CHECK-LABEL: @coerce_offset_pre0(
  308. ; CHECK: F:
  309. ; CHECK: load i8, i8* %P4
  310. ; CHECK: Cont:
  311. ; CHECK: %A = phi i8 [
  312. ; CHECK-NOT: load
  313. ; CHECK: ret i8 %A
  314. }
  315. define i32 @chained_load(i32** %p, i32 %x, i32 %y) {
  316. block1:
  317. %A = alloca i32*
  318. %z = load i32*, i32** %p
  319. store i32* %z, i32** %A
  320. %cmp = icmp eq i32 %x, %y
  321. br i1 %cmp, label %block2, label %block3
  322. block2:
  323. %a = load i32*, i32** %p
  324. br label %block4
  325. block3:
  326. %b = load i32*, i32** %p
  327. br label %block4
  328. block4:
  329. %c = load i32*, i32** %p
  330. %d = load i32, i32* %c
  331. ret i32 %d
  332. ; CHECK-LABEL: @chained_load(
  333. ; CHECK: %z = load i32*, i32** %p
  334. ; CHECK-NOT: load
  335. ; CHECK: %d = load i32, i32* %z
  336. ; CHECK-NEXT: ret i32 %d
  337. }
  338. declare i1 @cond() readonly
  339. declare i1 @cond2() readonly
  340. define i32 @phi_trans2() {
  341. ; CHECK-LABEL: @phi_trans2(
  342. entry:
  343. %P = alloca i32, i32 400
  344. br label %F1
  345. F1:
  346. %A = phi i32 [1, %entry], [2, %F]
  347. %cond2 = call i1 @cond()
  348. br i1 %cond2, label %T1, label %TY
  349. T1:
  350. %P2 = getelementptr i32, i32* %P, i32 %A
  351. %x = load i32, i32* %P2
  352. %cond = call i1 @cond2()
  353. br i1 %cond, label %TX, label %F
  354. F:
  355. %P3 = getelementptr i32, i32* %P, i32 2
  356. store i32 17, i32* %P3
  357. store i32 42, i32* %P2 ; Provides "P[A]".
  358. br label %F1
  359. TX:
  360. ; This load should not be compiled to 'ret i32 42'. An overly clever
  361. ; implementation of GVN would see that we're returning 17 if the loop
  362. ; executes once or 42 if it executes more than that, but we'd have to do
  363. ; loop restructuring to expose this, and GVN shouldn't do this sort of CFG
  364. ; transformation.
  365. ; CHECK: TX:
  366. ; CHECK: ret i32 %x
  367. ret i32 %x
  368. TY:
  369. ret i32 0
  370. }
  371. define i32 @phi_trans3(i32* %p, i32 %x, i32 %y, i32 %z) {
  372. ; CHECK-LABEL: @phi_trans3(
  373. block1:
  374. %cmpxy = icmp eq i32 %x, %y
  375. br i1 %cmpxy, label %block2, label %block3
  376. block2:
  377. store i32 87, i32* %p
  378. br label %block4
  379. block3:
  380. %p2 = getelementptr i32, i32* %p, i32 43
  381. store i32 97, i32* %p2
  382. br label %block4
  383. block4:
  384. %A = phi i32 [-1, %block2], [42, %block3]
  385. br i1 %cmpxy, label %block5, label %exit
  386. ; CHECK: block4:
  387. ; CHECK-NEXT: %D = phi i32 [ 87, %block2 ], [ 97, %block3 ]
  388. ; CHECK-NOT: load
  389. block5:
  390. %B = add i32 %A, 1
  391. br i1 %cmpxy, label %block6, label %exit
  392. block6:
  393. %C = getelementptr i32, i32* %p, i32 %B
  394. br i1 %cmpxy, label %block7, label %exit
  395. block7:
  396. %D = load i32, i32* %C
  397. ret i32 %D
  398. ; CHECK: block7:
  399. ; CHECK-NEXT: ret i32 %D
  400. exit:
  401. ret i32 -1
  402. }
  403. define i8 @phi_trans4(i8* %p) {
  404. ; CHECK-LABEL: @phi_trans4(
  405. entry:
  406. %X3 = getelementptr i8, i8* %p, i32 192
  407. store i8 192, i8* %X3
  408. %X = getelementptr i8, i8* %p, i32 4
  409. %Y = load i8, i8* %X
  410. br label %loop
  411. loop:
  412. %i = phi i32 [4, %entry], [192, %loop]
  413. %X2 = getelementptr i8, i8* %p, i32 %i
  414. %Y2 = load i8, i8* %X2
  415. ; CHECK: loop:
  416. ; CHECK-NEXT: %Y2 = phi i8 [ %Y, %entry ], [ 0, %loop ]
  417. ; CHECK-NOT: load i8
  418. %cond = call i1 @cond2()
  419. %Z = bitcast i8 *%X3 to i32*
  420. store i32 0, i32* %Z
  421. br i1 %cond, label %loop, label %out
  422. out:
  423. %R = add i8 %Y, %Y2
  424. ret i8 %R
  425. }
  426. define i8 @phi_trans5(i8* %p) {
  427. ; CHECK-LABEL: @phi_trans5(
  428. entry:
  429. %X4 = getelementptr i8, i8* %p, i32 2
  430. store i8 19, i8* %X4
  431. %X = getelementptr i8, i8* %p, i32 4
  432. %Y = load i8, i8* %X
  433. br label %loop
  434. loop:
  435. %i = phi i32 [4, %entry], [3, %cont]
  436. %X2 = getelementptr i8, i8* %p, i32 %i
  437. %Y2 = load i8, i8* %X2 ; Ensure this load is not being incorrectly replaced.
  438. %cond = call i1 @cond2()
  439. br i1 %cond, label %cont, label %out
  440. cont:
  441. %Z = getelementptr i8, i8* %X2, i32 -1
  442. %Z2 = bitcast i8 *%Z to i32*
  443. store i32 50462976, i32* %Z2 ;; (1 << 8) | (2 << 16) | (3 << 24)
  444. ; CHECK: store i32
  445. ; CHECK-NEXT: getelementptr i8, i8* %p, i32 3
  446. ; CHECK-NEXT: load i8, i8*
  447. br label %loop
  448. out:
  449. %R = add i8 %Y, %Y2
  450. ret i8 %R
  451. }
  452. ; PR6642
  453. define i32 @memset_to_load() nounwind readnone {
  454. entry:
  455. %x = alloca [256 x i32], align 4 ; <[256 x i32]*> [#uses=2]
  456. %tmp = bitcast [256 x i32]* %x to i8* ; <i8*> [#uses=1]
  457. call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 1024, i32 4, i1 false)
  458. %arraydecay = getelementptr inbounds [256 x i32], [256 x i32]* %x, i32 0, i32 0 ; <i32*>
  459. %tmp1 = load i32, i32* %arraydecay ; <i32> [#uses=1]
  460. ret i32 %tmp1
  461. ; CHECK-LABEL: @memset_to_load(
  462. ; CHECK: ret i32 0
  463. }
  464. ;;===----------------------------------------------------------------------===;;
  465. ;; Load -> Load forwarding in partial alias case.
  466. ;;===----------------------------------------------------------------------===;;
  467. define i32 @load_load_partial_alias(i8* %P) nounwind ssp {
  468. entry:
  469. %0 = bitcast i8* %P to i32*
  470. %tmp2 = load i32, i32* %0
  471. %add.ptr = getelementptr inbounds i8, i8* %P, i64 1
  472. %tmp5 = load i8, i8* %add.ptr
  473. %conv = zext i8 %tmp5 to i32
  474. %add = add nsw i32 %tmp2, %conv
  475. ret i32 %add
  476. ; TEMPORARILYDISABLED-LABEL: @load_load_partial_alias(
  477. ; TEMPORARILYDISABLED: load i32, i32*
  478. ; TEMPORARILYDISABLED-NOT: load
  479. ; TEMPORARILYDISABLED: lshr i32 {{.*}}, 8
  480. ; TEMPORARILYDISABLED-NOT: load
  481. ; TEMPORARILYDISABLED: trunc i32 {{.*}} to i8
  482. ; TEMPORARILYDISABLED-NOT: load
  483. ; TEMPORARILYDISABLED: ret i32
  484. }
  485. ; Cross block partial alias case.
  486. define i32 @load_load_partial_alias_cross_block(i8* %P) nounwind ssp {
  487. entry:
  488. %xx = bitcast i8* %P to i32*
  489. %x1 = load i32, i32* %xx, align 4
  490. %cmp = icmp eq i32 %x1, 127
  491. br i1 %cmp, label %land.lhs.true, label %if.end
  492. land.lhs.true: ; preds = %entry
  493. %arrayidx4 = getelementptr inbounds i8, i8* %P, i64 1
  494. %tmp5 = load i8, i8* %arrayidx4, align 1
  495. %conv6 = zext i8 %tmp5 to i32
  496. ret i32 %conv6
  497. if.end:
  498. ret i32 52
  499. ; TEMPORARILY_DISABLED-LABEL: @load_load_partial_alias_cross_block(
  500. ; TEMPORARILY_DISABLED: land.lhs.true:
  501. ; TEMPORARILY_DISABLED-NOT: load i8
  502. ; TEMPORARILY_DISABLED: ret i32 %conv6
  503. }
  504. ;;===----------------------------------------------------------------------===;;
  505. ;; Load Widening
  506. ;;===----------------------------------------------------------------------===;;
  507. %widening1 = type { i32, i8, i8, i8, i8 }
  508. @f = global %widening1 zeroinitializer, align 4
  509. define i32 @test_widening1(i8* %P) nounwind ssp noredzone {
  510. entry:
  511. %tmp = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 1), align 4
  512. %conv = zext i8 %tmp to i32
  513. %tmp1 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 2), align 1
  514. %conv2 = zext i8 %tmp1 to i32
  515. %add = add nsw i32 %conv, %conv2
  516. ret i32 %add
  517. ; CHECK-LABEL: @test_widening1(
  518. ; CHECK-NOT: load
  519. ; CHECK: load i16, i16*
  520. ; CHECK-NOT: load
  521. ; CHECK: ret i32
  522. }
  523. define i32 @test_widening2() nounwind ssp noredzone {
  524. entry:
  525. %tmp = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 1), align 4
  526. %conv = zext i8 %tmp to i32
  527. %tmp1 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 2), align 1
  528. %conv2 = zext i8 %tmp1 to i32
  529. %add = add nsw i32 %conv, %conv2
  530. %tmp2 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 3), align 2
  531. %conv3 = zext i8 %tmp2 to i32
  532. %add2 = add nsw i32 %add, %conv3
  533. %tmp3 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 4), align 1
  534. %conv4 = zext i8 %tmp3 to i32
  535. %add3 = add nsw i32 %add2, %conv3
  536. ret i32 %add3
  537. ; CHECK-LABEL: @test_widening2(
  538. ; CHECK-NOT: load
  539. ; CHECK: load i32, i32*
  540. ; CHECK-NOT: load
  541. ; CHECK: ret i32
  542. }
  543. declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
  544. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
  545. declare void @llvm.memcpy.p0i8.p1i8.i64(i8* nocapture, i8 addrspace(1)* nocapture, i64, i32, i1) nounwind
  546. ;;===----------------------------------------------------------------------===;;
  547. ;; Load -> Store dependency which isn't interfered with by a call that happens
  548. ;; before the pointer was captured.
  549. ;;===----------------------------------------------------------------------===;;
  550. %class.X = type { [8 x i8] }
  551. @_ZTV1X = weak_odr constant [5 x i8*] zeroinitializer
  552. @_ZTV1Y = weak_odr constant [5 x i8*] zeroinitializer
  553. declare void @use()
  554. declare void @use3(i8***, i8**)
  555. ; PR8908
  556. define void @test_escape1() nounwind {
  557. %x = alloca i8**, align 8
  558. store i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTV1X, i64 0, i64 2), i8*** %x, align 8
  559. call void @use() nounwind
  560. %DEAD = load i8**, i8*** %x, align 8
  561. call void @use3(i8*** %x, i8** %DEAD) nounwind
  562. ret void
  563. ; CHECK: test_escape1
  564. ; CHECK-NOT: DEAD
  565. ; CHECK: ret
  566. }