call.ll 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. ; Ignore stderr, we expect warnings there
  2. ; RUN: opt < %s -instcombine 2> /dev/null -S | FileCheck %s
  3. target datalayout = "E-p:64:64:64-p1:16:16:16-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
  4. ; Simple case, argument translatable without changing the value
  5. declare void @test1a(i8*)
  6. define void @test1(i32* %A) {
  7. ; CHECK-LABEL: @test1(
  8. ; CHECK: %1 = bitcast i32* %A to i8*
  9. ; CHECK: call void @test1a(i8* %1)
  10. ; CHECK: ret void
  11. call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
  12. ret void
  13. }
  14. ; Should not do because of change in address space of the parameter
  15. define void @test1_as1_illegal(i32 addrspace(1)* %A) {
  16. ; CHECK-LABEL: @test1_as1_illegal(
  17. ; CHECK: call void bitcast
  18. call void bitcast (void (i8*)* @test1a to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A)
  19. ret void
  20. }
  21. ; Test1, but the argument has a different sized address-space
  22. declare void @test1a_as1(i8 addrspace(1)*)
  23. ; This one is OK to perform
  24. define void @test1_as1(i32 addrspace(1)* %A) {
  25. ; CHECK-LABEL: @test1_as1(
  26. ; CHECK: %1 = bitcast i32 addrspace(1)* %A to i8 addrspace(1)*
  27. ; CHECK: call void @test1a_as1(i8 addrspace(1)* %1)
  28. ; CHECK: ret void
  29. call void bitcast (void (i8 addrspace(1)*)* @test1a_as1 to void (i32 addrspace(1)*)*)(i32 addrspace(1)* %A )
  30. ret void
  31. }
  32. ; More complex case, translate argument because of resolution. This is safe
  33. ; because we have the body of the function
  34. define void @test2a(i8 %A) {
  35. ; CHECK-LABEL: @test2a(
  36. ; CHECK: ret void
  37. ret void
  38. }
  39. define i32 @test2(i32 %A) {
  40. ; CHECK-LABEL: @test2(
  41. ; CHECK: call void bitcast
  42. ; CHECK: ret i32 %A
  43. call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
  44. ret i32 %A
  45. }
  46. ; Resolving this should insert a cast from sbyte to int, following the C
  47. ; promotion rules.
  48. define void @test3a(i8, ...) {unreachable }
  49. define void @test3(i8 %A, i8 %B) {
  50. ; CHECK-LABEL: @test3(
  51. ; CHECK: %1 = zext i8 %B to i32
  52. ; CHECK: call void (i8, ...) @test3a(i8 %A, i32 %1)
  53. ; CHECK: ret void
  54. call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B)
  55. ret void
  56. }
  57. ; test conversion of return value...
  58. define i8 @test4a() {
  59. ; CHECK-LABEL: @test4a(
  60. ; CHECK: ret i8 0
  61. ret i8 0
  62. }
  63. define i32 @test4() {
  64. ; CHECK-LABEL: @test4(
  65. ; CHECK: call i32 bitcast
  66. %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( ) ; <i32> [#uses=1]
  67. ret i32 %X
  68. }
  69. ; test conversion of return value... no value conversion occurs so we can do
  70. ; this with just a prototype...
  71. declare i32 @test5a()
  72. define i32 @test5() {
  73. ; CHECK-LABEL: @test5(
  74. ; CHECK: %X = call i32 @test5a()
  75. ; CHECK: ret i32 %X
  76. %X = call i32 @test5a( ) ; <i32> [#uses=1]
  77. ret i32 %X
  78. }
  79. ; test addition of new arguments...
  80. declare i32 @test6a(i32)
  81. define i32 @test6() {
  82. ; CHECK-LABEL: @test6(
  83. ; CHECK: %X = call i32 @test6a(i32 0)
  84. ; CHECK: ret i32 %X
  85. %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
  86. ret i32 %X
  87. }
  88. ; test removal of arguments, only can happen with a function body
  89. define void @test7a() {
  90. ; CHECK-LABEL: @test7a(
  91. ; CHECK: ret void
  92. ret void
  93. }
  94. define void @test7() {
  95. ; CHECK-LABEL: @test7(
  96. ; CHECK: call void @test7a()
  97. ; CHECK: ret void
  98. call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
  99. ret void
  100. }
  101. ; rdar://7590304
  102. declare void @test8a()
  103. define i8* @test8() personality i32 (...)* @__gxx_personality_v0 {
  104. ; CHECK-LABEL: @test8(
  105. ; CHECK-NEXT: invoke void @test8a()
  106. ; Don't turn this into "unreachable": the callee and caller don't agree in
  107. ; calling conv, but the implementation of test8a may actually end up using the
  108. ; right calling conv.
  109. invoke void @test8a()
  110. to label %invoke.cont unwind label %try.handler
  111. invoke.cont: ; preds = %entry
  112. unreachable
  113. try.handler: ; preds = %entry
  114. %exn = landingpad {i8*, i32}
  115. cleanup
  116. ret i8* null
  117. }
  118. declare i32 @__gxx_personality_v0(...)
  119. ; Don't turn this into a direct call, because test9x is just a prototype and
  120. ; doing so will make it varargs.
  121. ; rdar://9038601
  122. declare i8* @test9x(i8*, i8*, ...) noredzone
  123. define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
  124. ; CHECK-LABEL: @test9
  125. entry:
  126. %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
  127. ret i8* %call
  128. ; CHECK-LABEL: @test9(
  129. ; CHECK: call i8* bitcast
  130. }
  131. ; Parameter that's a vector of pointers
  132. declare void @test10a(<2 x i8*>)
  133. define void @test10(<2 x i32*> %A) {
  134. ; CHECK-LABEL: @test10(
  135. ; CHECK: %1 = bitcast <2 x i32*> %A to <2 x i8*>
  136. ; CHECK: call void @test10a(<2 x i8*> %1)
  137. ; CHECK: ret void
  138. call void bitcast (void (<2 x i8*>)* @test10a to void (<2 x i32*>)*)(<2 x i32*> %A)
  139. ret void
  140. }
  141. ; Don't transform because different address spaces
  142. declare void @test10a_mixed_as(<2 x i8 addrspace(1)*>)
  143. define void @test10_mixed_as(<2 x i8*> %A) {
  144. ; CHECK-LABEL: @test10_mixed_as(
  145. ; CHECK: call void bitcast
  146. call void bitcast (void (<2 x i8 addrspace(1)*>)* @test10a_mixed_as to void (<2 x i8*>)*)(<2 x i8*> %A)
  147. ret void
  148. }
  149. ; Return type that's a pointer
  150. define i8* @test11a() {
  151. ret i8* zeroinitializer
  152. }
  153. define i32* @test11() {
  154. ; CHECK-LABEL: @test11(
  155. ; CHECK: %X = call i8* @test11a()
  156. ; CHECK: %1 = bitcast i8* %X to i32*
  157. %X = call i32* bitcast (i8* ()* @test11a to i32* ()*)()
  158. ret i32* %X
  159. }
  160. ; Return type that's a pointer with a different address space
  161. define i8 addrspace(1)* @test11a_mixed_as() {
  162. ret i8 addrspace(1)* zeroinitializer
  163. }
  164. define i8* @test11_mixed_as() {
  165. ; CHECK-LABEL: @test11_mixed_as(
  166. ; CHECK: call i8* bitcast
  167. %X = call i8* bitcast (i8 addrspace(1)* ()* @test11a_mixed_as to i8* ()*)()
  168. ret i8* %X
  169. }
  170. ; Return type that's a vector of pointers
  171. define <2 x i8*> @test12a() {
  172. ret <2 x i8*> zeroinitializer
  173. }
  174. define <2 x i32*> @test12() {
  175. ; CHECK-LABEL: @test12(
  176. ; CHECK: %X = call <2 x i8*> @test12a()
  177. ; CHECK: %1 = bitcast <2 x i8*> %X to <2 x i32*>
  178. %X = call <2 x i32*> bitcast (<2 x i8*> ()* @test12a to <2 x i32*> ()*)()
  179. ret <2 x i32*> %X
  180. }
  181. define <2 x i8 addrspace(1)*> @test12a_mixed_as() {
  182. ret <2 x i8 addrspace(1)*> zeroinitializer
  183. }
  184. define <2 x i8*> @test12_mixed_as() {
  185. ; CHECK-LABEL: @test12_mixed_as(
  186. ; CHECK: call <2 x i8*> bitcast
  187. %X = call <2 x i8*> bitcast (<2 x i8 addrspace(1)*> ()* @test12a_mixed_as to <2 x i8*> ()*)()
  188. ret <2 x i8*> %X
  189. }
  190. ; Mix parameter that's a vector of integers and pointers of the same size
  191. declare void @test13a(<2 x i64>)
  192. define void @test13(<2 x i32*> %A) {
  193. ; CHECK-LABEL: @test13(
  194. ; CHECK: call void bitcast
  195. call void bitcast (void (<2 x i64>)* @test13a to void (<2 x i32*>)*)(<2 x i32*> %A)
  196. ret void
  197. }
  198. ; Mix parameter that's a vector of integers and pointers of the same
  199. ; size, but the other way around
  200. declare void @test14a(<2 x i8*>)
  201. define void @test14(<2 x i64> %A) {
  202. ; CHECK-LABEL: @test14(
  203. ; CHECK: call void bitcast
  204. call void bitcast (void (<2 x i8*>)* @test14a to void (<2 x i64>)*)(<2 x i64> %A)
  205. ret void
  206. }
  207. ; Return type that's a vector
  208. define <2 x i16> @test15a() {
  209. ret <2 x i16> zeroinitializer
  210. }
  211. define i32 @test15() {
  212. ; CHECK-LABEL: @test15(
  213. ; CHECK: %X = call <2 x i16> @test15a()
  214. ; CHECK: %1 = bitcast <2 x i16> %X to i32
  215. %X = call i32 bitcast (<2 x i16> ()* @test15a to i32 ()*)( )
  216. ret i32 %X
  217. }
  218. define i32 @test16a() {
  219. ret i32 0
  220. }
  221. define <2 x i16> @test16() {
  222. ; CHECK-LABEL: @test16(
  223. ; CHECK: %X = call i32 @test16a()
  224. ; CHECK: %1 = bitcast i32 %X to <2 x i16>
  225. %X = call <2 x i16> bitcast (i32 ()* @test16a to <2 x i16> ()*)( )
  226. ret <2 x i16> %X
  227. }