fold-builtin-fma.ll 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ; RUN: opt -instsimplify -S < %s | FileCheck %s
  2. ; Fixes PR20832
  3. ; Make sure that we correctly fold a fused multiply-add where operands
  4. ; are all finite constants and addend is zero.
  5. declare double @llvm.fma.f64(double, double, double)
  6. define double @PR20832() {
  7. %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0.0)
  8. ret double %1
  9. }
  10. ; CHECK-LABEL: @PR20832(
  11. ; CHECK: ret double 5.600000e+01
  12. ; Test builtin fma with all finite non-zero constants.
  13. define double @test_all_finite() {
  14. %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 5.0)
  15. ret double %1
  16. }
  17. ; CHECK-LABEL: @test_all_finite(
  18. ; CHECK: ret double 6.100000e+01
  19. ; Test builtin fma with a +/-NaN addend.
  20. define double @test_NaN_addend() {
  21. %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0x7FF8000000000000)
  22. ret double %1
  23. }
  24. ; CHECK-LABEL: @test_NaN_addend(
  25. ; CHECK: ret double 0x7FF8000000000000
  26. define double @test_NaN_addend_2() {
  27. %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0xFFF8000000000000)
  28. ret double %1
  29. }
  30. ; CHECK-LABEL: @test_NaN_addend_2(
  31. ; CHECK: ret double 0xFFF8000000000000
  32. ; Test builtin fma with a +/-Inf addend.
  33. define double @test_Inf_addend() {
  34. %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0x7FF0000000000000)
  35. ret double %1
  36. }
  37. ; CHECK-LABEL: @test_Inf_addend(
  38. ; CHECK: ret double 0x7FF0000000000000
  39. define double @test_Inf_addend_2() {
  40. %1 = call double @llvm.fma.f64(double 7.0, double 8.0, double 0xFFF0000000000000)
  41. ret double %1
  42. }
  43. ; CHECK-LABEL: @test_Inf_addend_2(
  44. ; CHECK: ret double 0xFFF0000000000000
  45. ; Test builtin fma with one of the operands to the multiply being +/-NaN.
  46. define double @test_NaN_1() {
  47. %1 = call double @llvm.fma.f64(double 0x7FF8000000000000, double 8.0, double 0.0)
  48. ret double %1
  49. }
  50. ; CHECK-LABEL: @test_NaN_1(
  51. ; CHECK: ret double 0x7FF8000000000000
  52. define double @test_NaN_2() {
  53. %1 = call double @llvm.fma.f64(double 7.0, double 0x7FF8000000000000, double 0.0)
  54. ret double %1
  55. }
  56. ; CHECK-LABEL: @test_NaN_2(
  57. ; CHECK: ret double 0x7FF8000000000000
  58. define double @test_NaN_3() {
  59. %1 = call double @llvm.fma.f64(double 0xFFF8000000000000, double 8.0, double 0.0)
  60. ret double %1
  61. }
  62. ; CHECK-LABEL: @test_NaN_3(
  63. ; CHECK: ret double 0x7FF8000000000000
  64. define double @test_NaN_4() {
  65. %1 = call double @llvm.fma.f64(double 7.0, double 0xFFF8000000000000, double 0.0)
  66. ret double %1
  67. }
  68. ; CHECK-LABEL: @test_NaN_4(
  69. ; CHECK: ret double 0x7FF8000000000000
  70. ; Test builtin fma with one of the operands to the multiply being +/-Inf.
  71. define double @test_Inf_1() {
  72. %1 = call double @llvm.fma.f64(double 0x7FF0000000000000, double 8.0, double 0.0)
  73. ret double %1
  74. }
  75. ; CHECK-LABEL: @test_Inf_1(
  76. ; CHECK: ret double 0x7FF0000000000000
  77. define double @test_Inf_2() {
  78. %1 = call double @llvm.fma.f64(double 7.0, double 0x7FF0000000000000, double 0.0)
  79. ret double %1
  80. }
  81. ; CHECK-LABEL: @test_Inf_2(
  82. ; CHECK: ret double 0x7FF0000000000000
  83. define double @test_Inf_3() {
  84. %1 = call double @llvm.fma.f64(double 0xFFF0000000000000, double 8.0, double 0.0)
  85. ret double %1
  86. }
  87. ; CHECK-LABEL: @test_Inf_3(
  88. ; CHECK: ret double 0xFFF0000000000000
  89. define double @test_Inf_4() {
  90. %1 = call double @llvm.fma.f64(double 7.0, double 0xFFF0000000000000, double 0.0)
  91. ret double %1
  92. }
  93. ; CHECK-LABEL: @test_Inf_4(
  94. ; CHECK: ret double 0xFFF0000000000000