blob: 650b10c6e96692085bcf4dfad95a8cea44e0b553 [file] [log] [blame]
Dmitri Gribenkob137c9e2012-12-30 01:28:40 +00001; RUN: opt -S -instcombine < %s | FileCheck %s
Owen Anderson3ccd8182010-07-19 08:14:26 +00002
Chris Lattner6e27b3e2010-09-07 20:01:38 +00003define float @test1(float %x) nounwind readnone ssp {
Owen Anderson3ccd8182010-07-19 08:14:26 +00004entry:
Stephen Linc1c7a132013-07-14 01:42:54 +00005; CHECK-LABEL: @test1(
Chris Lattner6e27b3e2010-09-07 20:01:38 +00006; 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
Chris Lattner6e27b3e2010-09-07 20:01:38 +000017; PR8096
18define float @test2(float %x) nounwind readnone ssp {
19entry:
Stephen Linc1c7a132013-07-14 01:42:54 +000020; CHECK-LABEL: @test2(
Owen Anderson3ccd8182010-07-19 08:14:26 +000021; 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}
Evan Chengb94674b2011-07-13 19:08:16 +000031
32; rdar://9763193
33; Can't fold (fptrunc (sqrt (fpext x))) -> (sqrtf x) since there is another
34; use of sqrt result.
35define float @test3(float* %v) nounwind uwtable ssp {
36entry:
Stephen Linc1c7a132013-07-14 01:42:54 +000037; CHECK-LABEL: @test3(
Evan Chengb94674b2011-07-13 19:08:16 +000038; CHECK: sqrt(
39; CHECK-NOT: sqrtf(
40; CHECK: fptrunc
Evan Cheng4a40a742011-07-13 19:19:44 +000041 %arrayidx13 = getelementptr inbounds float* %v, i64 2
42 %tmp14 = load float* %arrayidx13
43 %mul18 = fmul float %tmp14, %tmp14
44 %add19 = fadd float undef, %mul18
45 %conv = fpext float %add19 to double
46 %call34 = call double @sqrt(double %conv) readnone
Evan Chengb94674b2011-07-13 19:08:16 +000047 %call36 = call i32 (double)* @foo(double %call34) nounwind
48 %conv38 = fptrunc double %call34 to float
49 ret float %conv38
50}
51
52declare i32 @foo(double)
53
54declare double @sqrt(double) readnone