1; RUN: opt -S -instcombine < %s | FileCheck %s 2 3define float @test1(float %x) nounwind readnone ssp { 4entry: 5; CHECK-LABEL: @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 18define float @test2(float %x) nounwind readnone ssp { 19entry: 20; CHECK-LABEL: @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. 35define float @test3(float* %v) nounwind uwtable ssp { 36entry: 37; CHECK-LABEL: @test3( 38; CHECK: sqrt( 39; CHECK-NOT: sqrtf( 40; CHECK: fptrunc 41 %arrayidx13 = getelementptr inbounds float, float* %v, i64 2 42 %tmp14 = load float, 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 47 %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 55