1 ; RUN: opt -S -passes=instcombine -o - %s | FileCheck %s
3 ; Test that fast math lib call simplification of double math function to float
4 ; equivalent doesn't occur when the calling function matches the float
5 ; equivalent math function. Otherwise this can cause the generation of infinite
6 ; loops when compiled with -O2/3 and fast math.
10 ; extern double exp(double x);
11 ; inline float expf(float x) { return (float) exp((double) x); }
12 ; float fn(float f) { return expf(f); }
14 ; IR generated with command:
16 ; clang -cc1 -O2 -ffast-math -emit-llvm -disable-llvm-passes -triple x86_64-unknown-unknown -o - <srcfile>
18 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-unknown-unknown"
21 ; Function Attrs: nounwind
22 define float @fn(float %f) #0 {
23 ; CHECK: define float @fn(
24 ; CHECK: call fast float @expf(
25 %f.addr = alloca float, align 4
26 store float %f, ptr %f.addr, align 4, !tbaa !1
27 %1 = load float, ptr %f.addr, align 4, !tbaa !1
28 %call = call fast float @expf(float %1) #3
32 ; Function Attrs: inlinehint nounwind readnone
33 define available_externally float @expf(float %x) #1 {
34 ; CHECK: define available_externally float @expf(
36 ; CHECK: call fast double @exp(
37 ; CHECK: fptrunc double
38 %x.addr = alloca float, align 4
39 store float %x, ptr %x.addr, align 4, !tbaa !1
40 %1 = load float, ptr %x.addr, align 4, !tbaa !1
41 %conv = fpext float %1 to double
42 %call = call fast double @exp(double %conv) #3
43 %conv1 = fptrunc double %call to float
47 ; Function Attrs: nounwind readnone
48 declare double @exp(double) #2
50 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
51 attributes #1 = { inlinehint nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
52 attributes #2 = { nounwind readnone }
56 !0 = !{!"clang version 5.0.0"}
58 !2 = !{!"float", !3, i64 0}
59 !3 = !{!"omnipotent char", !4, i64 0}
60 !4 = !{!"Simple C/C++ TBAA"}