floating-point-arithmetic.ll 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ; RUN: opt < %s -instsimplify -S | FileCheck %s
  2. ; fsub 0, (fsub 0, X) ==> X
  3. ; CHECK-LABEL: @fsub_0_0_x(
  4. define float @fsub_0_0_x(float %a) {
  5. %t1 = fsub float -0.0, %a
  6. %ret = fsub float -0.0, %t1
  7. ; CHECK: ret float %a
  8. ret float %ret
  9. }
  10. ; fsub X, 0 ==> X
  11. ; CHECK-LABEL: @fsub_x_0(
  12. define float @fsub_x_0(float %a) {
  13. %ret = fsub float %a, 0.0
  14. ; CHECK: ret float %a
  15. ret float %ret
  16. }
  17. ; fadd X, -0 ==> X
  18. ; CHECK-LABEL: @fadd_x_n0(
  19. define float @fadd_x_n0(float %a) {
  20. %ret = fadd float %a, -0.0
  21. ; CHECK: ret float %a
  22. ret float %ret
  23. }
  24. ; fmul X, 1.0 ==> X
  25. ; CHECK-LABEL: @fmul_X_1(
  26. define double @fmul_X_1(double %a) {
  27. %b = fmul double 1.000000e+00, %a ; <double> [#uses=1]
  28. ; CHECK: ret double %a
  29. ret double %b
  30. }
  31. ; We can't optimize away the fadd in this test because the input
  32. ; value to the function and subsequently to the fadd may be -0.0.
  33. ; In that one special case, the result of the fadd should be +0.0
  34. ; rather than the first parameter of the fadd.
  35. ; Fragile test warning: We need 6 sqrt calls to trigger the bug
  36. ; because the internal logic has a magic recursion limit of 6.
  37. ; This is presented without any explanation or ability to customize.
  38. declare float @sqrtf(float)
  39. define float @PR22688(float %x) {
  40. %1 = call float @sqrtf(float %x)
  41. %2 = call float @sqrtf(float %1)
  42. %3 = call float @sqrtf(float %2)
  43. %4 = call float @sqrtf(float %3)
  44. %5 = call float @sqrtf(float %4)
  45. %6 = call float @sqrtf(float %5)
  46. %7 = fadd float %6, 0.0
  47. ret float %7
  48. ; CHECK-LABEL: @PR22688(
  49. ; CHECK: fadd float %6, 0.0
  50. }