win-math.ll 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. ; RUN: opt -O2 -S -mtriple=i386-pc-win32 < %s | FileCheck %s -check-prefix=WIN32
  2. ; RUN: opt -O2 -S -mtriple=x86_64-pc-win32 < %s | FileCheck %s -check-prefix=WIN64
  3. ; RUN: opt -O2 -S -mtriple=i386-pc-mingw32 < %s | FileCheck %s -check-prefix=MINGW32
  4. ; RUN: opt -O2 -S -mtriple=x86_64-pc-mingw32 < %s | FileCheck %s -check-prefix=MINGW64
  5. ; x86 win32 msvcrt does not provide entry points for single-precision libm.
  6. ; x86-64 win32 msvcrt does (except for fabsf)
  7. ; msvcrt does not provide C99 math, but mingw32 does.
  8. declare double @acos(double %x)
  9. define float @float_acos(float %x) nounwind readnone {
  10. ; WIN32-LABEL: @float_acos(
  11. ; WIN32-NOT: float @acosf
  12. ; WIN32: double @acos
  13. %1 = fpext float %x to double
  14. %2 = call double @acos(double %1)
  15. %3 = fptrunc double %2 to float
  16. ret float %3
  17. }
  18. declare double @asin(double %x)
  19. define float @float_asin(float %x) nounwind readnone {
  20. ; WIN32-LABEL: @float_asin(
  21. ; WIN32-NOT: float @asinf
  22. ; WIN32: double @asin
  23. %1 = fpext float %x to double
  24. %2 = call double @asin(double %1)
  25. %3 = fptrunc double %2 to float
  26. ret float %3
  27. }
  28. declare double @atan(double %x)
  29. define float @float_atan(float %x) nounwind readnone {
  30. ; WIN32-LABEL: @float_atan(
  31. ; WIN32-NOT: float @atanf
  32. ; WIN32: double @atan
  33. %1 = fpext float %x to double
  34. %2 = call double @atan(double %1)
  35. %3 = fptrunc double %2 to float
  36. ret float %3
  37. }
  38. declare double @atan2(double %x, double %y)
  39. define float @float_atan2(float %x, float %y) nounwind readnone {
  40. ; WIN32-LABEL: @float_atan2(
  41. ; WIN32-NOT: float @atan2f
  42. ; WIN32: double @atan2
  43. %1 = fpext float %x to double
  44. %2 = fpext float %y to double
  45. %3 = call double @atan2(double %1, double %2)
  46. %4 = fptrunc double %3 to float
  47. ret float %4
  48. }
  49. declare double @ceil(double %x)
  50. define float @float_ceil(float %x) nounwind readnone {
  51. ; WIN32-LABEL: @float_ceil(
  52. ; WIN32-NOT: float @ceilf
  53. ; WIN32: double @ceil
  54. ; WIN64-LABEL: @float_ceil(
  55. ; WIN64: float @ceilf
  56. ; WIN64-NOT: double @ceil
  57. ; MINGW32-LABEL: @float_ceil(
  58. ; MINGW32: float @ceilf
  59. ; MINGW32-NOT: double @ceil
  60. ; MINGW64-LABEL: @float_ceil(
  61. ; MINGW64: float @ceilf
  62. ; MINGW64-NOT: double @ceil
  63. %1 = fpext float %x to double
  64. %2 = call double @ceil(double %1)
  65. %3 = fptrunc double %2 to float
  66. ret float %3
  67. }
  68. declare double @_copysign(double %x)
  69. define float @float_copysign(float %x) nounwind readnone {
  70. ; WIN32-LABEL: @float_copysign(
  71. ; WIN32-NOT: float @copysignf
  72. ; WIN32-NOT: float @_copysignf
  73. ; WIN32: double @_copysign
  74. %1 = fpext float %x to double
  75. %2 = call double @_copysign(double %1)
  76. %3 = fptrunc double %2 to float
  77. ret float %3
  78. }
  79. declare double @cos(double %x)
  80. define float @float_cos(float %x) nounwind readnone {
  81. ; WIN32-LABEL: @float_cos(
  82. ; WIN32-NOT: float @cosf
  83. ; WIN32: double @cos
  84. %1 = fpext float %x to double
  85. %2 = call double @cos(double %1)
  86. %3 = fptrunc double %2 to float
  87. ret float %3
  88. }
  89. declare double @cosh(double %x)
  90. define float @float_cosh(float %x) nounwind readnone {
  91. ; WIN32-LABEL: @float_cosh(
  92. ; WIN32-NOT: float @coshf
  93. ; WIN32: double @cosh
  94. %1 = fpext float %x to double
  95. %2 = call double @cosh(double %1)
  96. %3 = fptrunc double %2 to float
  97. ret float %3
  98. }
  99. declare double @exp(double %x, double %y)
  100. define float @float_exp(float %x, float %y) nounwind readnone {
  101. ; WIN32-LABEL: @float_exp(
  102. ; WIN32-NOT: float @expf
  103. ; WIN32: double @exp
  104. %1 = fpext float %x to double
  105. %2 = fpext float %y to double
  106. %3 = call double @exp(double %1, double %2)
  107. %4 = fptrunc double %3 to float
  108. ret float %4
  109. }
  110. declare double @fabs(double %x, double %y)
  111. define float @float_fabs(float %x, float %y) nounwind readnone {
  112. ; WIN32-LABEL: @float_fabs(
  113. ; WIN32-NOT: float @fabsf
  114. ; WIN32: double @fabs
  115. ; WIN64-LABEL: @float_fabs(
  116. ; WIN64-NOT: float @fabsf
  117. ; WIN64: double @fabs
  118. %1 = fpext float %x to double
  119. %2 = fpext float %y to double
  120. %3 = call double @fabs(double %1, double %2)
  121. %4 = fptrunc double %3 to float
  122. ret float %4
  123. }
  124. declare double @floor(double %x)
  125. define float @float_floor(float %x) nounwind readnone {
  126. ; WIN32-LABEL: @float_floor(
  127. ; WIN32-NOT: float @floorf
  128. ; WIN32: double @floor
  129. ; WIN64-LABEL: @float_floor(
  130. ; WIN64: float @floorf
  131. ; WIN64-NOT: double @floor
  132. ; MINGW32-LABEL: @float_floor(
  133. ; MINGW32: float @floorf
  134. ; MINGW32-NOT: double @floor
  135. ; MINGW64-LABEL: @float_floor(
  136. ; MINGW64: float @floorf
  137. ; MINGW64-NOT: double @floor
  138. %1 = fpext float %x to double
  139. %2 = call double @floor(double %1)
  140. %3 = fptrunc double %2 to float
  141. ret float %3
  142. }
  143. declare double @fmod(double %x, double %y)
  144. define float @float_fmod(float %x, float %y) nounwind readnone {
  145. ; WIN32-LABEL: @float_fmod(
  146. ; WIN32-NOT: float @fmodf
  147. ; WIN32: double @fmod
  148. %1 = fpext float %x to double
  149. %2 = fpext float %y to double
  150. %3 = call double @fmod(double %1, double %2)
  151. %4 = fptrunc double %3 to float
  152. ret float %4
  153. }
  154. declare double @log(double %x)
  155. define float @float_log(float %x) nounwind readnone {
  156. ; WIN32-LABEL: @float_log(
  157. ; WIN32-NOT: float @logf
  158. ; WIN32: double @log
  159. %1 = fpext float %x to double
  160. %2 = call double @log(double %1)
  161. %3 = fptrunc double %2 to float
  162. ret float %3
  163. }
  164. declare double @pow(double %x, double %y)
  165. define float @float_pow(float %x, float %y) nounwind readnone {
  166. ; WIN32-LABEL: @float_pow(
  167. ; WIN32-NOT: float @powf
  168. ; WIN32: double @pow
  169. %1 = fpext float %x to double
  170. %2 = fpext float %y to double
  171. %3 = call double @pow(double %1, double %2)
  172. %4 = fptrunc double %3 to float
  173. ret float %4
  174. }
  175. declare double @sin(double %x)
  176. define float @float_sin(float %x) nounwind readnone {
  177. ; WIN32-LABEL: @float_sin(
  178. ; WIN32-NOT: float @sinf
  179. ; WIN32: double @sin
  180. %1 = fpext float %x to double
  181. %2 = call double @sin(double %1)
  182. %3 = fptrunc double %2 to float
  183. ret float %3
  184. }
  185. declare double @sinh(double %x)
  186. define float @float_sinh(float %x) nounwind readnone {
  187. ; WIN32-LABEL: @float_sinh(
  188. ; WIN32-NOT: float @sinhf
  189. ; WIN32: double @sinh
  190. %1 = fpext float %x to double
  191. %2 = call double @sinh(double %1)
  192. %3 = fptrunc double %2 to float
  193. ret float %3
  194. }
  195. declare double @sqrt(double %x)
  196. define float @float_sqrt(float %x) nounwind readnone {
  197. ; WIN32-LABEL: @float_sqrt(
  198. ; WIN32-NOT: float @sqrtf
  199. ; WIN32: double @sqrt
  200. ; WIN64-LABEL: @float_sqrt(
  201. ; WIN64: float @sqrtf
  202. ; WIN64-NOT: double @sqrt
  203. ; MINGW32-LABEL: @float_sqrt(
  204. ; MINGW32: float @sqrtf
  205. ; MINGW32-NOT: double @sqrt
  206. ; MINGW64-LABEL: @float_sqrt(
  207. ; MINGW64: float @sqrtf
  208. ; MINGW64-NOT: double @sqrt
  209. %1 = fpext float %x to double
  210. %2 = call double @sqrt(double %1)
  211. %3 = fptrunc double %2 to float
  212. ret float %3
  213. }
  214. declare double @tan(double %x)
  215. define float @float_tan(float %x) nounwind readnone {
  216. ; WIN32-LABEL: @float_tan(
  217. ; WIN32-NOT: float @tanf
  218. ; WIN32: double @tan
  219. %1 = fpext float %x to double
  220. %2 = call double @tan(double %1)
  221. %3 = fptrunc double %2 to float
  222. ret float %3
  223. }
  224. declare double @tanh(double %x)
  225. define float @float_tanh(float %x) nounwind readnone {
  226. ; WIN32-LABEL: @float_tanh(
  227. ; WIN32-NOT: float @tanhf
  228. ; WIN32: double @tanh
  229. %1 = fpext float %x to double
  230. %2 = call double @tanh(double %1)
  231. %3 = fptrunc double %2 to float
  232. ret float %3
  233. }
  234. ; win32 does not have round; mingw32 does
  235. declare double @round(double %x)
  236. define float @float_round(float %x) nounwind readnone {
  237. ; WIN32-LABEL: @float_round(
  238. ; WIN32-NOT: float @roundf
  239. ; WIN32: double @round
  240. ; WIN64-LABEL: @float_round(
  241. ; WIN64-NOT: float @roundf
  242. ; WIN64: double @round
  243. ; MINGW32-LABEL: @float_round(
  244. ; MINGW32: float @roundf
  245. ; MINGW32-NOT: double @round
  246. ; MINGW64-LABEL: @float_round(
  247. ; MINGW64: float @roundf
  248. ; MINGW64-NOT: double @round
  249. %1 = fpext float %x to double
  250. %2 = call double @round(double %1)
  251. %3 = fptrunc double %2 to float
  252. ret float %3
  253. }
  254. declare float @powf(float, float)
  255. ; win32 lacks sqrtf&fabsf, win64 lacks fabsf
  256. define float @float_powsqrt(float %x) nounwind readnone {
  257. ; WIN32-LABEL: @float_powsqrt(
  258. ; WIN32-NOT: float @sqrtf
  259. ; WIN32: float @powf
  260. ; WIN64-LABEL: @float_powsqrt(
  261. ; WIN64-NOT: float @sqrtf
  262. ; WIN64: float @powf
  263. ; MINGW32-LABEL: @float_powsqrt(
  264. ; MINGW32: float @sqrtf
  265. ; MINGW32: float @fabsf
  266. ; MINGW32-NOT: float @powf
  267. ; MINGW64-LABEL: @float_powsqrt(
  268. ; MINGW64: float @sqrtf
  269. ; MINGW64: float @fabsf
  270. ; MINGW64-NOT: float @powf
  271. %1 = call float @powf(float %x, float 0.5)
  272. ret float %1
  273. }