floating-point-compare.ll 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ; RUN: opt < %s -instsimplify -S | FileCheck %s
  2. ; These tests choose arbitrarily between float and double,
  3. ; and between uge and olt, to give reasonble coverage
  4. ; without combinatorial explosion.
  5. declare float @llvm.fabs.f32(float)
  6. declare float @llvm.sqrt.f32(float)
  7. declare double @llvm.powi.f64(double,i32)
  8. declare float @llvm.exp.f32(float)
  9. declare double @llvm.exp2.f64(double)
  10. declare float @llvm.fma.f32(float,float,float)
  11. declare void @expect_equal(i1,i1)
  12. ; CHECK-LABEL: @orderedLessZeroTree(
  13. define i1 @orderedLessZeroTree(float,float,float,float) {
  14. %square = fmul float %0, %0
  15. %abs = call float @llvm.fabs.f32(float %1)
  16. %sqrt = call float @llvm.sqrt.f32(float %2)
  17. %fma = call float @llvm.fma.f32(float %3, float %3, float %sqrt)
  18. %div = fdiv float %square, %abs
  19. %rem = frem float %sqrt, %fma
  20. %add = fadd float %div, %rem
  21. %uge = fcmp uge float %add, 0.000000e+00
  22. ; CHECK: ret i1 true
  23. ret i1 %uge
  24. }
  25. ; CHECK-LABEL: @orderedLessZeroExpExt(
  26. define i1 @orderedLessZeroExpExt(float) {
  27. %a = call float @llvm.exp.f32(float %0)
  28. %b = fpext float %a to double
  29. %uge = fcmp uge double %b, 0.000000e+00
  30. ; CHECK: ret i1 true
  31. ret i1 %uge
  32. }
  33. ; CHECK-LABEL: @orderedLessZeroExp2Trunc(
  34. define i1 @orderedLessZeroExp2Trunc(double) {
  35. %a = call double @llvm.exp2.f64(double %0)
  36. %b = fptrunc double %a to float
  37. %olt = fcmp olt float %b, 0.000000e+00
  38. ; CHECK: ret i1 false
  39. ret i1 %olt
  40. }
  41. ; CHECK-LABEL: @orderedLessZeroPowi(
  42. define i1 @orderedLessZeroPowi(double,double) {
  43. ; Even constant exponent
  44. %a = call double @llvm.powi.f64(double %0, i32 2)
  45. %square = fmul double %1, %1
  46. ; Odd constant exponent with provably non-negative base
  47. %b = call double @llvm.powi.f64(double %square, i32 3)
  48. %c = fadd double %a, %b
  49. %olt = fcmp olt double %b, 0.000000e+00
  50. ; CHECK: ret i1 false
  51. ret i1 %olt
  52. }
  53. define i1 @nonans1(double %in1, double %in2) {
  54. %cmp = fcmp nnan uno double %in1, %in2
  55. ret i1 %cmp
  56. ; CHECK-LABEL: @nonans1
  57. ; CHECK-NEXT: ret i1 false
  58. }
  59. define i1 @nonans2(double %in1, double %in2) {
  60. %cmp = fcmp nnan ord double %in1, %in2
  61. ret i1 %cmp
  62. ; CHECK-LABEL: @nonans2
  63. ; CHECK-NEXT: ret i1 true
  64. }