Dmitri Gribenko | b137c9e | 2012-12-30 01:28:40 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -instcombine < %s | FileCheck %s |
Owen Anderson | 3ccd818 | 2010-07-19 08:14:26 +0000 | [diff] [blame] | 2 | |
Chris Lattner | 6e27b3e | 2010-09-07 20:01:38 +0000 | [diff] [blame] | 3 | define float @test1(float %x) nounwind readnone ssp { |
Owen Anderson | 3ccd818 | 2010-07-19 08:14:26 +0000 | [diff] [blame] | 4 | entry: |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 5 | ; CHECK-LABEL: @test1( |
Chris Lattner | 6e27b3e | 2010-09-07 20:01:38 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 6e27b3e | 2010-09-07 20:01:38 +0000 | [diff] [blame] | 17 | ; PR8096 |
| 18 | define float @test2(float %x) nounwind readnone ssp { |
| 19 | entry: |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 20 | ; CHECK-LABEL: @test2( |
Owen Anderson | 3ccd818 | 2010-07-19 08:14:26 +0000 | [diff] [blame] | 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 | } |
Evan Cheng | b94674b | 2011-07-13 19:08:16 +0000 | [diff] [blame] | 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: |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 37 | ; CHECK-LABEL: @test3( |
Evan Cheng | b94674b | 2011-07-13 19:08:16 +0000 | [diff] [blame] | 38 | ; CHECK: sqrt( |
| 39 | ; CHECK-NOT: sqrtf( |
| 40 | ; CHECK: fptrunc |
Evan Cheng | 4a40a74 | 2011-07-13 19:19:44 +0000 | [diff] [blame] | 41 | %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 Cheng | b94674b | 2011-07-13 19:08:16 +0000 | [diff] [blame] | 47 | %call36 = call i32 (double)* @foo(double %call34) nounwind |
| 48 | %conv38 = fptrunc double %call34 to float |
| 49 | ret float %conv38 |
| 50 | } |
| 51 | |
| 52 | declare i32 @foo(double) |
| 53 | |
| 54 | declare double @sqrt(double) readnone |