float-shrink-compare.ll 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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-apple-macosx10.8.0"
  4. define i32 @test1(float %x, float %y) nounwind uwtable {
  5. %1 = fpext float %x to double
  6. %2 = call double @ceil(double %1) nounwind readnone
  7. %3 = fpext float %y to double
  8. %4 = fcmp oeq double %2, %3
  9. %5 = zext i1 %4 to i32
  10. ret i32 %5
  11. ; CHECK-LABEL: @test1(
  12. ; CHECK-NEXT: %ceilf = call float @ceilf(float %x)
  13. ; CHECK-NEXT: fcmp oeq float %ceilf, %y
  14. }
  15. define i32 @test2(float %x, float %y) nounwind uwtable {
  16. %1 = fpext float %x to double
  17. %2 = call double @fabs(double %1) nounwind readnone
  18. %3 = fpext float %y to double
  19. %4 = fcmp oeq double %2, %3
  20. %5 = zext i1 %4 to i32
  21. ret i32 %5
  22. ; CHECK-LABEL: @test2(
  23. ; CHECK-NEXT: %fabsf = call float @fabsf(float %x)
  24. ; CHECK-NEXT: fcmp oeq float %fabsf, %y
  25. }
  26. define i32 @test3(float %x, float %y) nounwind uwtable {
  27. %1 = fpext float %x to double
  28. %2 = call double @floor(double %1) nounwind readnone
  29. %3 = fpext float %y to double
  30. %4 = fcmp oeq double %2, %3
  31. %5 = zext i1 %4 to i32
  32. ret i32 %5
  33. ; CHECK-LABEL: @test3(
  34. ; CHECK-NEXT: %floorf = call float @floorf(float %x)
  35. ; CHECK-NEXT: fcmp oeq float %floorf, %y
  36. }
  37. define i32 @test4(float %x, float %y) nounwind uwtable {
  38. %1 = fpext float %x to double
  39. %2 = call double @nearbyint(double %1) nounwind
  40. %3 = fpext float %y to double
  41. %4 = fcmp oeq double %2, %3
  42. %5 = zext i1 %4 to i32
  43. ret i32 %5
  44. ; CHECK-LABEL: @test4(
  45. ; CHECK-NEXT: %nearbyintf = call float @nearbyintf(float %x)
  46. ; CHECK-NEXT: fcmp oeq float %nearbyintf, %y
  47. }
  48. define i32 @test5(float %x, float %y) nounwind uwtable {
  49. %1 = fpext float %x to double
  50. %2 = call double @rint(double %1) nounwind
  51. %3 = fpext float %y to double
  52. %4 = fcmp oeq double %2, %3
  53. %5 = zext i1 %4 to i32
  54. ret i32 %5
  55. ; CHECK-LABEL: @test5(
  56. ; CHECK-NEXT: %rintf = call float @rintf(float %x)
  57. ; CHECK-NEXT: fcmp oeq float %rintf, %y
  58. }
  59. define i32 @test6(float %x, float %y) nounwind uwtable {
  60. %1 = fpext float %x to double
  61. %2 = call double @round(double %1) nounwind readnone
  62. %3 = fpext float %y to double
  63. %4 = fcmp oeq double %2, %3
  64. %5 = zext i1 %4 to i32
  65. ret i32 %5
  66. ; CHECK-LABEL: @test6(
  67. ; CHECK-NEXT: %roundf = call float @roundf(float %x)
  68. ; CHECK-NEXT: fcmp oeq float %roundf, %y
  69. }
  70. define i32 @test7(float %x, float %y) nounwind uwtable {
  71. %1 = fpext float %x to double
  72. %2 = call double @trunc(double %1) nounwind
  73. %3 = fpext float %y to double
  74. %4 = fcmp oeq double %2, %3
  75. %5 = zext i1 %4 to i32
  76. ret i32 %5
  77. ; CHECK-LABEL: @test7(
  78. ; CHECK-NEXT: %truncf = call float @truncf(float %x)
  79. ; CHECK-NEXT: fcmp oeq float %truncf, %y
  80. }
  81. define i32 @test8(float %x, float %y) nounwind uwtable {
  82. %1 = fpext float %y to double
  83. %2 = fpext float %x to double
  84. %3 = call double @ceil(double %2) nounwind readnone
  85. %4 = fcmp oeq double %1, %3
  86. %5 = zext i1 %4 to i32
  87. ret i32 %5
  88. ; CHECK-LABEL: @test8(
  89. ; CHECK-NEXT: %ceilf = call float @ceilf(float %x)
  90. ; CHECK-NEXT: fcmp oeq float %ceilf, %y
  91. }
  92. define i32 @test9(float %x, float %y) nounwind uwtable {
  93. %1 = fpext float %y to double
  94. %2 = fpext float %x to double
  95. %3 = call double @fabs(double %2) nounwind readnone
  96. %4 = fcmp oeq double %1, %3
  97. %5 = zext i1 %4 to i32
  98. ret i32 %5
  99. ; CHECK-LABEL: @test9(
  100. ; CHECK-NEXT: %fabsf = call float @fabsf(float %x)
  101. ; CHECK-NEXT: fcmp oeq float %fabsf, %y
  102. }
  103. define i32 @test10(float %x, float %y) nounwind uwtable {
  104. %1 = fpext float %y to double
  105. %2 = fpext float %x to double
  106. %3 = call double @floor(double %2) nounwind readnone
  107. %4 = fcmp oeq double %1, %3
  108. %5 = zext i1 %4 to i32
  109. ret i32 %5
  110. ; CHECK-LABEL: @test10(
  111. ; CHECK-NEXT: %floorf = call float @floorf(float %x)
  112. ; CHECK-NEXT: fcmp oeq float %floorf, %y
  113. }
  114. define i32 @test11(float %x, float %y) nounwind uwtable {
  115. %1 = fpext float %y to double
  116. %2 = fpext float %x to double
  117. %3 = call double @nearbyint(double %2) nounwind
  118. %4 = fcmp oeq double %1, %3
  119. %5 = zext i1 %4 to i32
  120. ret i32 %5
  121. ; CHECK-LABEL: @test11(
  122. ; CHECK-NEXT: %nearbyintf = call float @nearbyintf(float %x)
  123. ; CHECK-NEXT: fcmp oeq float %nearbyintf, %y
  124. }
  125. define i32 @test12(float %x, float %y) nounwind uwtable {
  126. %1 = fpext float %y to double
  127. %2 = fpext float %x to double
  128. %3 = call double @rint(double %2) nounwind
  129. %4 = fcmp oeq double %1, %3
  130. %5 = zext i1 %4 to i32
  131. ret i32 %5
  132. ; CHECK-LABEL: @test12(
  133. ; CHECK-NEXT: %rintf = call float @rintf(float %x)
  134. ; CHECK-NEXT: fcmp oeq float %rintf, %y
  135. }
  136. define i32 @test13(float %x, float %y) nounwind uwtable {
  137. %1 = fpext float %y to double
  138. %2 = fpext float %x to double
  139. %3 = call double @round(double %2) nounwind readnone
  140. %4 = fcmp oeq double %1, %3
  141. %5 = zext i1 %4 to i32
  142. ret i32 %5
  143. ; CHECK-LABEL: @test13(
  144. ; CHECK-NEXT: %roundf = call float @roundf(float %x)
  145. ; CHECK-NEXT: fcmp oeq float %roundf, %y
  146. }
  147. define i32 @test14(float %x, float %y) nounwind uwtable {
  148. %1 = fpext float %y to double
  149. %2 = fpext float %x to double
  150. %3 = call double @trunc(double %2) nounwind
  151. %4 = fcmp oeq double %1, %3
  152. %5 = zext i1 %4 to i32
  153. ret i32 %5
  154. ; CHECK-LABEL: @test14(
  155. ; CHECK-NEXT: %truncf = call float @truncf(float %x)
  156. ; CHECK-NEXT: fcmp oeq float %truncf, %y
  157. }
  158. define i32 @test15(float %x, float %y, float %z) nounwind uwtable {
  159. %1 = fpext float %x to double
  160. %2 = fpext float %y to double
  161. %3 = call double @fmin(double %1, double %2) nounwind
  162. %4 = fpext float %z to double
  163. %5 = fcmp oeq double %3, %4
  164. %6 = zext i1 %5 to i32
  165. ret i32 %6
  166. ; CHECK-LABEL: @test15(
  167. ; CHECK-NEXT: %fminf = call float @fminf(float %x, float %y)
  168. ; CHECK-NEXT: fcmp oeq float %fminf, %z
  169. }
  170. define i32 @test16(float %x, float %y, float %z) nounwind uwtable {
  171. %1 = fpext float %z to double
  172. %2 = fpext float %x to double
  173. %3 = fpext float %y to double
  174. %4 = call double @fmin(double %2, double %3) nounwind
  175. %5 = fcmp oeq double %1, %4
  176. %6 = zext i1 %5 to i32
  177. ret i32 %6
  178. ; CHECK-LABEL: @test16(
  179. ; CHECK-NEXT: %fminf = call float @fminf(float %x, float %y)
  180. ; CHECK-NEXT: fcmp oeq float %fminf, %z
  181. }
  182. define i32 @test17(float %x, float %y, float %z) nounwind uwtable {
  183. %1 = fpext float %x to double
  184. %2 = fpext float %y to double
  185. %3 = call double @fmax(double %1, double %2) nounwind
  186. %4 = fpext float %z to double
  187. %5 = fcmp oeq double %3, %4
  188. %6 = zext i1 %5 to i32
  189. ret i32 %6
  190. ; CHECK-LABEL: @test17(
  191. ; CHECK-NEXT: %fmaxf = call float @fmaxf(float %x, float %y)
  192. ; CHECK-NEXT: fcmp oeq float %fmaxf, %z
  193. }
  194. define i32 @test18(float %x, float %y, float %z) nounwind uwtable {
  195. %1 = fpext float %z to double
  196. %2 = fpext float %x to double
  197. %3 = fpext float %y to double
  198. %4 = call double @fmax(double %2, double %3) nounwind
  199. %5 = fcmp oeq double %1, %4
  200. %6 = zext i1 %5 to i32
  201. ret i32 %6
  202. ; CHECK-LABEL: @test18(
  203. ; CHECK-NEXT: %fmaxf = call float @fmaxf(float %x, float %y)
  204. ; CHECK-NEXT: fcmp oeq float %fmaxf, %z
  205. }
  206. define i32 @test19(float %x, float %y, float %z) nounwind uwtable {
  207. %1 = fpext float %x to double
  208. %2 = fpext float %y to double
  209. %3 = call double @copysign(double %1, double %2) nounwind
  210. %4 = fpext float %z to double
  211. %5 = fcmp oeq double %3, %4
  212. %6 = zext i1 %5 to i32
  213. ret i32 %6
  214. ; CHECK-LABEL: @test19(
  215. ; CHECK-NEXT: %copysignf = call float @copysignf(float %x, float %y)
  216. ; CHECK-NEXT: fcmp oeq float %copysignf, %z
  217. }
  218. define i32 @test20(float %x, float %y) nounwind uwtable {
  219. %1 = fpext float %y to double
  220. %2 = fpext float %x to double
  221. %3 = call double @fmin(double 1.000000e+00, double %2) nounwind
  222. %4 = fcmp oeq double %1, %3
  223. %5 = zext i1 %4 to i32
  224. ret i32 %5
  225. ; CHECK-LABEL: @test20(
  226. ; CHECK-NEXT: %fminf = call float @fminf(float 1.000000e+00, float %x)
  227. ; CHECK-NEXT: fcmp oeq float %fminf, %y
  228. }
  229. define i32 @test21(float %x, float %y) nounwind uwtable {
  230. %1 = fpext float %y to double
  231. %2 = fpext float %x to double
  232. %3 = call double @fmin(double 1.300000e+00, double %2) nounwind
  233. %4 = fcmp oeq double %1, %3
  234. %5 = zext i1 %4 to i32
  235. ret i32 %5
  236. ; should not be changed to fminf as the constant would loose precision
  237. ; CHECK-LABEL: @test21(
  238. ; CHECK: %3 = call double @fmin(double 1.300000e+00, double %2)
  239. }
  240. declare double @fabs(double) nounwind readnone
  241. declare double @ceil(double) nounwind readnone
  242. declare double @copysign(double, double) nounwind readnone
  243. declare double @floor(double) nounwind readnone
  244. declare double @nearbyint(double) nounwind readnone
  245. declare double @rint(double) nounwind readnone
  246. declare double @round(double) nounwind readnone
  247. declare double @trunc(double) nounwind readnone
  248. declare double @fmin(double, double) nounwind readnone
  249. declare double @fmax(double, double) nounwind readnone