blob: a351fe82173cf466a9348b160eaa1aea68f7dd50 [file] [log] [blame]
Eric Christophercee313d2019-04-17 04:52:47 +00001; RUN: opt -S -instcombine -o - %s | FileCheck %s
2
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.
7
8; Test case C source:
9;
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); }
13;
14; IR generated with command:
15;
16; clang -cc1 -O2 -ffast-math -emit-llvm -disable-llvm-passes -triple x86_64-unknown-unknown -o - <srcfile>
17
18target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
19target triple = "x86_64-unknown-unknown"
20
21; Function Attrs: nounwind
22define 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, float* %f.addr, align 4, !tbaa !1
27 %1 = load float, float* %f.addr, align 4, !tbaa !1
28 %call = call fast float @expf(float %1) #3
29 ret float %call
30}
31
32; Function Attrs: inlinehint nounwind readnone
33define available_externally float @expf(float %x) #1 {
34; CHECK: define available_externally float @expf(
35; CHECK: fpext float
36; CHECK: call fast double @exp(
37; CHECK: fptrunc double
38 %x.addr = alloca float, align 4
39 store float %x, float* %x.addr, align 4, !tbaa !1
40 %1 = load float, float* %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
44 ret float %conv1
45}
46
47; Function Attrs: nounwind readnone
48declare double @exp(double) #2
49
50attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" }
51attributes #1 = { inlinehint nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" }
52attributes #2 = { nounwind readnone }
53
54!llvm.ident = !{!0}
55
56!0 = !{!"clang version 5.0.0"}
57!1 = !{!2, !2, i64 0}
58!2 = !{!"float", !3, i64 0}
59!3 = !{!"omnipotent char", !4, i64 0}
60!4 = !{!"Simple C/C++ TBAA"}