double-float-shrink-1.ll 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  3. target triple = "x86_64-unknown-linux-gnu"
  4. ; Check for and against shrinkage when using the
  5. ; unsafe-fp-math function attribute on a math lib
  6. ; function. This optimization may be overridden by
  7. ; the -enable-double-float-shrink option.
  8. ; PR17850: http://llvm.org/bugs/show_bug.cgi?id=17850
  9. define float @acos_test(float %f) {
  10. %conv = fpext float %f to double
  11. %call = call double @acos(double %conv)
  12. %conv1 = fptrunc double %call to float
  13. ret float %conv1
  14. ; CHECK-LABEL: acos_test
  15. ; CHECK: call float @acosf(float %f)
  16. }
  17. define double @acos_test2(float %f) {
  18. %conv = fpext float %f to double
  19. %call = call double @acos(double %conv)
  20. ret double %call
  21. ; CHECK-LABEL: acos_test2
  22. ; CHECK: call double @acos(double %conv)
  23. }
  24. define float @acosh_test(float %f) {
  25. %conv = fpext float %f to double
  26. %call = call double @acosh(double %conv)
  27. %conv1 = fptrunc double %call to float
  28. ret float %conv1
  29. ; CHECK-LABEL: acosh_test
  30. ; CHECK: call float @acoshf(float %f)
  31. }
  32. define double @acosh_test2(float %f) {
  33. %conv = fpext float %f to double
  34. %call = call double @acosh(double %conv)
  35. ret double %call
  36. ; CHECK-LABEL: acosh_test2
  37. ; CHECK: call double @acosh(double %conv)
  38. }
  39. define float @asin_test(float %f) {
  40. %conv = fpext float %f to double
  41. %call = call double @asin(double %conv)
  42. %conv1 = fptrunc double %call to float
  43. ret float %conv1
  44. ; CHECK-LABEL: asin_test
  45. ; CHECK: call float @asinf(float %f)
  46. }
  47. define double @asin_test2(float %f) {
  48. %conv = fpext float %f to double
  49. %call = call double @asin(double %conv)
  50. ret double %call
  51. ; CHECK-LABEL: asin_test2
  52. ; CHECK: call double @asin(double %conv)
  53. }
  54. define float @asinh_test(float %f) {
  55. %conv = fpext float %f to double
  56. %call = call double @asinh(double %conv)
  57. %conv1 = fptrunc double %call to float
  58. ret float %conv1
  59. ; CHECK-LABEL: asinh_test
  60. ; CHECK: call float @asinhf(float %f)
  61. }
  62. define double @asinh_test2(float %f) {
  63. %conv = fpext float %f to double
  64. %call = call double @asinh(double %conv)
  65. ret double %call
  66. ; CHECK-LABEL: asinh_test2
  67. ; CHECK: call double @asinh(double %conv)
  68. }
  69. define float @atan_test(float %f) {
  70. %conv = fpext float %f to double
  71. %call = call double @atan(double %conv)
  72. %conv1 = fptrunc double %call to float
  73. ret float %conv1
  74. ; CHECK-LABEL: atan_test
  75. ; CHECK: call float @atanf(float %f)
  76. }
  77. define double @atan_test2(float %f) {
  78. %conv = fpext float %f to double
  79. %call = call double @atan(double %conv)
  80. ret double %call
  81. ; CHECK-LABEL: atan_test2
  82. ; CHECK: call double @atan(double %conv)
  83. }
  84. define float @atanh_test(float %f) {
  85. %conv = fpext float %f to double
  86. %call = call double @atanh(double %conv)
  87. %conv1 = fptrunc double %call to float
  88. ret float %conv1
  89. ; CHECK-LABEL: atanh_test
  90. ; CHECK: call float @atanhf(float %f)
  91. }
  92. define double @atanh_test2(float %f) {
  93. %conv = fpext float %f to double
  94. %call = call double @atanh(double %conv)
  95. ret double %call
  96. ; CHECK-LABEL: atanh_test2
  97. ; CHECK: call double @atanh(double %conv)
  98. }
  99. define float @cbrt_test(float %f) {
  100. %conv = fpext float %f to double
  101. %call = call double @cbrt(double %conv)
  102. %conv1 = fptrunc double %call to float
  103. ret float %conv1
  104. ; CHECK-LABEL: cbrt_test
  105. ; CHECK: call float @cbrtf(float %f)
  106. }
  107. define double @cbrt_test2(float %f) {
  108. %conv = fpext float %f to double
  109. %call = call double @cbrt(double %conv)
  110. ret double %call
  111. ; CHECK-LABEL: cbrt_test2
  112. ; CHECK: call double @cbrt(double %conv)
  113. }
  114. define float @exp_test(float %f) {
  115. %conv = fpext float %f to double
  116. %call = call double @exp(double %conv)
  117. %conv1 = fptrunc double %call to float
  118. ret float %conv1
  119. ; CHECK-LABEL: exp_test
  120. ; CHECK: call float @expf(float %f)
  121. }
  122. define double @exp_test2(float %f) {
  123. %conv = fpext float %f to double
  124. %call = call double @exp(double %conv)
  125. ret double %call
  126. ; CHECK-LABEL: exp_test2
  127. ; CHECK: call double @exp(double %conv)
  128. }
  129. define float @expm1_test(float %f) {
  130. %conv = fpext float %f to double
  131. %call = call double @expm1(double %conv)
  132. %conv1 = fptrunc double %call to float
  133. ret float %conv1
  134. ; CHECK-LABEL: expm1_test
  135. ; CHECK: call float @expm1f(float %f)
  136. }
  137. define double @expm1_test2(float %f) {
  138. %conv = fpext float %f to double
  139. %call = call double @expm1(double %conv)
  140. ret double %call
  141. ; CHECK-LABEL: expm1_test2
  142. ; CHECK: call double @expm1(double %conv)
  143. }
  144. define float @exp10_test(float %f) {
  145. %conv = fpext float %f to double
  146. %call = call double @exp10(double %conv)
  147. %conv1 = fptrunc double %call to float
  148. ret float %conv1
  149. ; CHECK-LABEL: exp10_test
  150. ; CHECK: call double @exp10(double %conv)
  151. }
  152. define double @exp10_test2(float %f) {
  153. %conv = fpext float %f to double
  154. %call = call double @exp10(double %conv)
  155. ret double %call
  156. ; CHECK-LABEL: exp10_test2
  157. ; CHECK: call double @exp10(double %conv)
  158. }
  159. define float @log_test(float %f) {
  160. %conv = fpext float %f to double
  161. %call = call double @log(double %conv)
  162. %conv1 = fptrunc double %call to float
  163. ret float %conv1
  164. ; CHECK-LABEL: log_test
  165. ; CHECK: call float @logf(float %f)
  166. }
  167. define double @log_test2(float %f) {
  168. %conv = fpext float %f to double
  169. %call = call double @log(double %conv)
  170. ret double %call
  171. ; CHECK-LABEL: log_test2
  172. ; CHECK: call double @log(double %conv)
  173. }
  174. define float @log10_test(float %f) {
  175. %conv = fpext float %f to double
  176. %call = call double @log10(double %conv)
  177. %conv1 = fptrunc double %call to float
  178. ret float %conv1
  179. ; CHECK-LABEL: log10_test
  180. ; CHECK: call float @log10f(float %f)
  181. }
  182. define double @log10_test2(float %f) {
  183. %conv = fpext float %f to double
  184. %call = call double @log10(double %conv)
  185. ret double %call
  186. ; CHECK-LABEL: log10_test2
  187. ; CHECK: call double @log10(double %conv)
  188. }
  189. define float @log1p_test(float %f) {
  190. %conv = fpext float %f to double
  191. %call = call double @log1p(double %conv)
  192. %conv1 = fptrunc double %call to float
  193. ret float %conv1
  194. ; CHECK-LABEL: log1p_test
  195. ; CHECK: call float @log1pf(float %f)
  196. }
  197. define double @log1p_test2(float %f) {
  198. %conv = fpext float %f to double
  199. %call = call double @log1p(double %conv)
  200. ret double %call
  201. ; CHECK-LABEL: log1p_test2
  202. ; CHECK: call double @log1p(double %conv)
  203. }
  204. define float @log2_test(float %f) {
  205. %conv = fpext float %f to double
  206. %call = call double @log2(double %conv)
  207. %conv1 = fptrunc double %call to float
  208. ret float %conv1
  209. ; CHECK-LABEL: log2_test
  210. ; CHECK: call float @log2f(float %f)
  211. }
  212. define double @log2_test2(float %f) {
  213. %conv = fpext float %f to double
  214. %call = call double @log2(double %conv)
  215. ret double %call
  216. ; CHECK-LABEL: log2_test2
  217. ; CHECK: call double @log2(double %conv)
  218. }
  219. define float @logb_test(float %f) {
  220. %conv = fpext float %f to double
  221. %call = call double @logb(double %conv)
  222. %conv1 = fptrunc double %call to float
  223. ret float %conv1
  224. ; CHECK-LABEL: logb_test
  225. ; CHECK: call float @logbf(float %f)
  226. }
  227. define double @logb_test2(float %f) {
  228. %conv = fpext float %f to double
  229. %call = call double @logb(double %conv)
  230. ret double %call
  231. ; CHECK-LABEL: logb_test2
  232. ; CHECK: call double @logb(double %conv)
  233. }
  234. define float @sin_test(float %f) {
  235. %conv = fpext float %f to double
  236. %call = call double @sin(double %conv)
  237. %conv1 = fptrunc double %call to float
  238. ret float %conv1
  239. ; CHECK-LABEL: sin_test
  240. ; CHECK: call float @sinf(float %f)
  241. }
  242. define double @sin_test2(float %f) {
  243. %conv = fpext float %f to double
  244. %call = call double @sin(double %conv)
  245. ret double %call
  246. ; CHECK-LABEL: sin_test2
  247. ; CHECK: call double @sin(double %conv)
  248. }
  249. define float @sqrt_test(float %f) {
  250. %conv = fpext float %f to double
  251. %call = call double @sqrt(double %conv)
  252. %conv1 = fptrunc double %call to float
  253. ret float %conv1
  254. ; CHECK-LABEL: sqrt_test
  255. ; CHECK: call float @sqrtf(float %f)
  256. }
  257. define double @sqrt_test2(float %f) {
  258. %conv = fpext float %f to double
  259. %call = call double @sqrt(double %conv)
  260. ret double %call
  261. ; CHECK-LABEL: sqrt_test2
  262. ; CHECK: call double @sqrt(double %conv)
  263. }
  264. define float @sqrt_int_test(float %f) {
  265. %conv = fpext float %f to double
  266. %call = call double @llvm.sqrt.f64(double %conv)
  267. %conv1 = fptrunc double %call to float
  268. ret float %conv1
  269. ; CHECK-LABEL: sqrt_int_test
  270. ; CHECK: call float @llvm.sqrt.f32(float %f)
  271. }
  272. define double @sqrt_int_test2(float %f) {
  273. %conv = fpext float %f to double
  274. %call = call double @llvm.sqrt.f64(double %conv)
  275. ret double %call
  276. ; CHECK-LABEL: sqrt_int_test2
  277. ; CHECK: call double @llvm.sqrt.f64(double %conv)
  278. }
  279. define float @tan_test(float %f) {
  280. %conv = fpext float %f to double
  281. %call = call double @tan(double %conv)
  282. %conv1 = fptrunc double %call to float
  283. ret float %conv1
  284. ; CHECK-LABEL: tan_test
  285. ; CHECK: call float @tanf(float %f)
  286. }
  287. define double @tan_test2(float %f) {
  288. %conv = fpext float %f to double
  289. %call = call double @tan(double %conv)
  290. ret double %call
  291. ; CHECK-LABEL: tan_test2
  292. ; CHECK: call double @tan(double %conv)
  293. }
  294. define float @tanh_test(float %f) {
  295. %conv = fpext float %f to double
  296. %call = call double @tanh(double %conv)
  297. %conv1 = fptrunc double %call to float
  298. ret float %conv1
  299. ; CHECK-LABEL: tanh_test
  300. ; CHECK: call float @tanhf(float %f)
  301. }
  302. define double @tanh_test2(float %f) {
  303. %conv = fpext float %f to double
  304. %call = call double @tanh(double %conv)
  305. ret double %call
  306. ; CHECK-LABEL: tanh_test2
  307. ; CHECK: call double @tanh(double %conv)
  308. }
  309. declare double @tanh(double) #1
  310. declare double @tan(double) #1
  311. ; sqrt is a special case: the shrinking optimization
  312. ; is valid even without unsafe-fp-math.
  313. declare double @sqrt(double)
  314. declare double @llvm.sqrt.f64(double)
  315. declare double @sin(double) #1
  316. declare double @log2(double) #1
  317. declare double @log1p(double) #1
  318. declare double @log10(double) #1
  319. declare double @log(double) #1
  320. declare double @logb(double) #1
  321. declare double @exp10(double) #1
  322. declare double @expm1(double) #1
  323. declare double @exp(double) #1
  324. declare double @cbrt(double) #1
  325. declare double @atanh(double) #1
  326. declare double @atan(double) #1
  327. declare double @acos(double) #1
  328. declare double @acosh(double) #1
  329. declare double @asin(double) #1
  330. declare double @asinh(double) #1
  331. attributes #1 = { "unsafe-fp-math"="true" }