blob: 669b414531af013355ce06348ea38e666c0a800b [file] [log] [blame]
Dan Gohmanb99d6f92009-09-25 23:10:17 +00001; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
Dan Gohman40dcae42009-09-26 01:11:57 +00002; rdar://7251832
Dan Gohmanb99d6f92009-09-25 23:10:17 +00003
4; SimplifyLibcalls should optimize pow(x, 0.5) to sqrt plus code to handle
5; special cases. The readonly attribute on the call should be preserved.
6
7; CHECK: define float @foo(float %x) nounwind {
Dan Gohmanc156b7b2009-09-26 18:10:13 +00008; CHECK: %sqrtf = call float @sqrtf(float %x) nounwind readonly
9; CHECK: %fabsf = call float @fabsf(float %sqrtf) nounwind readonly
Dan Gohmanb99d6f92009-09-25 23:10:17 +000010; CHECK: %tmp = fcmp oeq float %x, 0xFFF0000000000000
11; CHECK: %tmp1 = select i1 %tmp, float 0x7FF0000000000000, float %fabsf
12; CHECK: ret float %tmp1
13
14define float @foo(float %x) nounwind {
Dan Gohmanc156b7b2009-09-26 18:10:13 +000015 %retval = call float @powf(float %x, float 0.5)
Dan Gohmanb99d6f92009-09-25 23:10:17 +000016 ret float %retval
17}
18
19; CHECK: define double @doo(double %x) nounwind {
Dan Gohmanc156b7b2009-09-26 18:10:13 +000020; CHECK: %sqrt = call double @sqrt(double %x) nounwind readonly
21; CHECK: %fabs = call double @fabs(double %sqrt) nounwind readonly
Dan Gohmanb99d6f92009-09-25 23:10:17 +000022; CHECK: %tmp = fcmp oeq double %x, 0xFFF0000000000000
23; CHECK: %tmp1 = select i1 %tmp, double 0x7FF0000000000000, double %fabs
24; CHECK: ret double %tmp1
25; CHECK: }
26
27define double @doo(double %x) nounwind {
Dan Gohmanc156b7b2009-09-26 18:10:13 +000028 %retval = call double @pow(double %x, double 0.5)
Dan Gohmanb99d6f92009-09-25 23:10:17 +000029 ret double %retval
30}
31
32declare float @powf(float, float) nounwind readonly
33declare double @pow(double, double) nounwind readonly