1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -instcombine < %s | FileCheck %s 3 4define float @test1(float %x) nounwind readnone ssp { 5; CHECK-LABEL: @test1( 6; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X:%.*]]) #3 7; CHECK-NEXT: ret float [[SQRTF]] 8; 9 %conv = fpext float %x to double 10 %call = tail call double @sqrt(double %conv) readnone nounwind 11 %conv1 = fptrunc double %call to float 12 ret float %conv1 13} 14 15; PR8096 16 17define float @test2(float %x) nounwind readnone ssp { 18; CHECK-LABEL: @test2( 19; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X:%.*]]) #3 20; CHECK-NEXT: ret float [[SQRTF]] 21; 22 %conv = fpext float %x to double 23 %call = tail call double @sqrt(double %conv) nounwind 24 %conv1 = fptrunc double %call to float 25 ret float %conv1 26} 27 28; rdar://9763193 29; Can't fold (fptrunc (sqrt (fpext x))) -> (sqrtf x) since there is another 30; use of sqrt result. 31 32define float @test3(float* %v) nounwind uwtable ssp { 33; CHECK-LABEL: @test3( 34; CHECK-NEXT: [[CALL34:%.*]] = call double @sqrt(double 0x7FF8000000000000) #3 35; CHECK-NEXT: [[CALL36:%.*]] = call i32 @foo(double [[CALL34]]) #4 36; CHECK-NEXT: [[CONV38:%.*]] = fptrunc double [[CALL34]] to float 37; CHECK-NEXT: ret float [[CONV38]] 38; 39 %arrayidx13 = getelementptr inbounds float, float* %v, i64 2 40 %tmp14 = load float, float* %arrayidx13 41 %mul18 = fmul float %tmp14, %tmp14 42 %add19 = fadd float undef, %mul18 43 %conv = fpext float %add19 to double 44 %call34 = call double @sqrt(double %conv) readnone 45 %call36 = call i32 (double) @foo(double %call34) nounwind 46 %conv38 = fptrunc double %call34 to float 47 ret float %conv38 48} 49 50; PR43347 - https://bugs.llvm.org/show_bug.cgi?id=43347 51 52define void @0(float %f) { 53; CHECK-LABEL: @0( 54; CHECK-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[F:%.*]]) #2 55; CHECK-NEXT: ret void 56; 57 %d = fpext float %f to double 58 %r = call double @sqrt(double %d) 59 ret void 60} 61 62declare i32 @foo(double) 63declare double @sqrt(double) readnone 64