nocapture.ll 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ; RUN: opt < %s -functionattrs -S | FileCheck %s
  2. @g = global i32* null ; <i32**> [#uses=1]
  3. ; CHECK: define i32* @c1(i32* readnone %q)
  4. define i32* @c1(i32* %q) {
  5. ret i32* %q
  6. }
  7. ; CHECK: define void @c2(i32* %q)
  8. ; It would also be acceptable to mark %q as readnone. Update @c3 too.
  9. define void @c2(i32* %q) {
  10. store i32* %q, i32** @g
  11. ret void
  12. }
  13. ; CHECK: define void @c3(i32* %q)
  14. define void @c3(i32* %q) {
  15. call void @c2(i32* %q)
  16. ret void
  17. }
  18. ; CHECK: define i1 @c4(i32* %q, i32 %bitno)
  19. define i1 @c4(i32* %q, i32 %bitno) {
  20. %tmp = ptrtoint i32* %q to i32
  21. %tmp2 = lshr i32 %tmp, %bitno
  22. %bit = trunc i32 %tmp2 to i1
  23. br i1 %bit, label %l1, label %l0
  24. l0:
  25. ret i1 0 ; escaping value not caught by def-use chaining.
  26. l1:
  27. ret i1 1 ; escaping value not caught by def-use chaining.
  28. }
  29. @lookup_table = global [2 x i1] [ i1 0, i1 1 ]
  30. ; CHECK: define i1 @c5(i32* %q, i32 %bitno)
  31. define i1 @c5(i32* %q, i32 %bitno) {
  32. %tmp = ptrtoint i32* %q to i32
  33. %tmp2 = lshr i32 %tmp, %bitno
  34. %bit = and i32 %tmp2, 1
  35. ; subtle escape mechanism follows
  36. %lookup = getelementptr [2 x i1], [2 x i1]* @lookup_table, i32 0, i32 %bit
  37. %val = load i1, i1* %lookup
  38. ret i1 %val
  39. }
  40. declare void @throw_if_bit_set(i8*, i8) readonly
  41. ; CHECK: define i1 @c6(i8* readonly %q, i8 %bit)
  42. define i1 @c6(i8* %q, i8 %bit) personality i32 (...)* @__gxx_personality_v0 {
  43. invoke void @throw_if_bit_set(i8* %q, i8 %bit)
  44. to label %ret0 unwind label %ret1
  45. ret0:
  46. ret i1 0
  47. ret1:
  48. %exn = landingpad {i8*, i32}
  49. cleanup
  50. ret i1 1
  51. }
  52. declare i32 @__gxx_personality_v0(...)
  53. define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
  54. %tmp = ptrtoint i32* %q to i32
  55. %tmp2 = lshr i32 %tmp, %bitno
  56. %bit = and i32 %tmp2, 1
  57. %lookup = getelementptr [2 x i1], [2 x i1]* @lookup_table, i32 0, i32 %bit
  58. ret i1* %lookup
  59. }
  60. ; CHECK: define i1 @c7(i32* readonly %q, i32 %bitno)
  61. define i1 @c7(i32* %q, i32 %bitno) {
  62. %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
  63. %val = load i1, i1* %ptr
  64. ret i1 %val
  65. }
  66. ; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b)
  67. define i32 @nc1(i32* %q, i32* %p, i1 %b) {
  68. e:
  69. br label %l
  70. l:
  71. %x = phi i32* [ %p, %e ]
  72. %y = phi i32* [ %q, %e ]
  73. %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
  74. %tmp2 = select i1 %b, i32* %tmp, i32* %y
  75. %val = load i32, i32* %tmp2 ; <i32> [#uses=1]
  76. store i32 0, i32* %tmp
  77. store i32* %y, i32** @g
  78. ret i32 %val
  79. }
  80. ; CHECK: define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* nocapture %p, i1 %b)
  81. define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* %p, i1 %b) {
  82. e:
  83. br label %l
  84. l:
  85. %x = phi i32 addrspace(1)* [ %p, %e ]
  86. %y = phi i32* [ %q, %e ]
  87. %tmp = addrspacecast i32 addrspace(1)* %x to i32* ; <i32*> [#uses=2]
  88. %tmp2 = select i1 %b, i32* %tmp, i32* %y
  89. %val = load i32, i32* %tmp2 ; <i32> [#uses=1]
  90. store i32 0, i32* %tmp
  91. store i32* %y, i32** @g
  92. ret i32 %val
  93. }
  94. ; CHECK: define void @nc2(i32* nocapture %p, i32* %q)
  95. define void @nc2(i32* %p, i32* %q) {
  96. %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
  97. ret void
  98. }
  99. ; CHECK: define void @nc3(void ()* nocapture %p)
  100. define void @nc3(void ()* %p) {
  101. call void %p()
  102. ret void
  103. }
  104. declare void @external(i8*) readonly nounwind
  105. ; CHECK: define void @nc4(i8* nocapture readonly %p)
  106. define void @nc4(i8* %p) {
  107. call void @external(i8* %p)
  108. ret void
  109. }
  110. ; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p)
  111. define void @nc5(void (i8*)* %f, i8* %p) {
  112. call void %f(i8* %p) readonly nounwind
  113. call void %f(i8* nocapture %p)
  114. ret void
  115. }
  116. ; CHECK: define void @test1_1(i8* nocapture readnone %x1_1, i8* %y1_1)
  117. ; It would be acceptable to add readnone to %y1_1 and %y1_2.
  118. define void @test1_1(i8* %x1_1, i8* %y1_1) {
  119. call i8* @test1_2(i8* %x1_1, i8* %y1_1)
  120. store i32* null, i32** @g
  121. ret void
  122. }
  123. ; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8* %y1_2)
  124. define i8* @test1_2(i8* %x1_2, i8* %y1_2) {
  125. call void @test1_1(i8* %x1_2, i8* %y1_2)
  126. store i32* null, i32** @g
  127. ret i8* %y1_2
  128. }
  129. ; CHECK: define void @test2(i8* nocapture readnone %x2)
  130. define void @test2(i8* %x2) {
  131. call void @test2(i8* %x2)
  132. store i32* null, i32** @g
  133. ret void
  134. }
  135. ; CHECK: define void @test3(i8* nocapture readnone %x3, i8* nocapture readnone %y3, i8* nocapture readnone %z3)
  136. define void @test3(i8* %x3, i8* %y3, i8* %z3) {
  137. call void @test3(i8* %z3, i8* %y3, i8* %x3)
  138. store i32* null, i32** @g
  139. ret void
  140. }
  141. ; CHECK: define void @test4_1(i8* %x4_1)
  142. define void @test4_1(i8* %x4_1) {
  143. call i8* @test4_2(i8* %x4_1, i8* %x4_1, i8* %x4_1)
  144. store i32* null, i32** @g
  145. ret void
  146. }
  147. ; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8* readnone %y4_2, i8* nocapture readnone %z4_2)
  148. define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) {
  149. call void @test4_1(i8* null)
  150. store i32* null, i32** @g
  151. ret i8* %y4_2
  152. }
  153. declare i8* @test5_1(i8* %x5_1)
  154. ; CHECK: define void @test5_2(i8* %x5_2)
  155. define void @test5_2(i8* %x5_2) {
  156. call i8* @test5_1(i8* %x5_2)
  157. store i32* null, i32** @g
  158. ret void
  159. }
  160. declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...)
  161. ; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2)
  162. define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) {
  163. call void (i8*, i8*, ...) @test6_1(i8* %x6_2, i8* %y6_2, i8* %z6_2)
  164. store i32* null, i32** @g
  165. ret void
  166. }