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