sqrt.ll 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ; RUN: opt -S -instcombine < %s | FileCheck %s
  2. define float @test1(float %x) nounwind readnone ssp {
  3. entry:
  4. ; CHECK-LABEL: @test1(
  5. ; CHECK-NOT: fpext
  6. ; CHECK-NOT: sqrt(
  7. ; CHECK: sqrtf(
  8. ; CHECK-NOT: fptrunc
  9. %conv = fpext float %x to double ; <double> [#uses=1]
  10. %call = tail call double @sqrt(double %conv) readnone nounwind ; <double> [#uses=1]
  11. %conv1 = fptrunc double %call to float ; <float> [#uses=1]
  12. ; CHECK: ret float
  13. ret float %conv1
  14. }
  15. ; PR8096
  16. define float @test2(float %x) nounwind readnone ssp {
  17. entry:
  18. ; CHECK-LABEL: @test2(
  19. ; CHECK-NOT: fpext
  20. ; CHECK-NOT: sqrt(
  21. ; CHECK: sqrtf(
  22. ; CHECK-NOT: fptrunc
  23. %conv = fpext float %x to double ; <double> [#uses=1]
  24. %call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1]
  25. %conv1 = fptrunc double %call to float ; <float> [#uses=1]
  26. ; CHECK: ret float
  27. ret float %conv1
  28. }
  29. ; rdar://9763193
  30. ; Can't fold (fptrunc (sqrt (fpext x))) -> (sqrtf x) since there is another
  31. ; use of sqrt result.
  32. define float @test3(float* %v) nounwind uwtable ssp {
  33. entry:
  34. ; CHECK-LABEL: @test3(
  35. ; CHECK: sqrt(
  36. ; CHECK-NOT: sqrtf(
  37. ; CHECK: fptrunc
  38. %arrayidx13 = getelementptr inbounds float, float* %v, i64 2
  39. %tmp14 = load float, float* %arrayidx13
  40. %mul18 = fmul float %tmp14, %tmp14
  41. %add19 = fadd float undef, %mul18
  42. %conv = fpext float %add19 to double
  43. %call34 = call double @sqrt(double %conv) readnone
  44. %call36 = call i32 (double) @foo(double %call34) nounwind
  45. %conv38 = fptrunc double %call34 to float
  46. ret float %conv38
  47. }
  48. declare i32 @foo(double)
  49. declare double @sqrt(double) readnone