Dan Gohman | 79cb840 | 2009-09-25 23:10:17 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -simplify-libcalls -S | FileCheck %s |
Dan Gohman | 22cb657 | 2009-09-26 01:11:57 +0000 | [diff] [blame] | 2 | ; rdar://7251832 |
Dan Gohman | 79cb840 | 2009-09-25 23:10:17 +0000 | [diff] [blame] | 3 | |
| 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 Gohman | 76926b6 | 2009-09-26 18:10:13 +0000 | [diff] [blame] | 8 | ; CHECK: %sqrtf = call float @sqrtf(float %x) nounwind readonly |
| 9 | ; CHECK: %fabsf = call float @fabsf(float %sqrtf) nounwind readonly |
Benjamin Kramer | a9390a4 | 2011-09-27 20:39:19 +0000 | [diff] [blame] | 10 | ; CHECK: %1 = fcmp oeq float %x, 0xFFF0000000000000 |
| 11 | ; CHECK: %retval = select i1 %1, float 0x7FF0000000000000, float %fabsf |
| 12 | ; CHECK: ret float %retval |
Dan Gohman | 79cb840 | 2009-09-25 23:10:17 +0000 | [diff] [blame] | 13 | |
| 14 | define float @foo(float %x) nounwind { |
Dan Gohman | 76926b6 | 2009-09-26 18:10:13 +0000 | [diff] [blame] | 15 | %retval = call float @powf(float %x, float 0.5) |
Dan Gohman | 79cb840 | 2009-09-25 23:10:17 +0000 | [diff] [blame] | 16 | ret float %retval |
| 17 | } |
| 18 | |
| 19 | ; CHECK: define double @doo(double %x) nounwind { |
Dan Gohman | 76926b6 | 2009-09-26 18:10:13 +0000 | [diff] [blame] | 20 | ; CHECK: %sqrt = call double @sqrt(double %x) nounwind readonly |
| 21 | ; CHECK: %fabs = call double @fabs(double %sqrt) nounwind readonly |
Benjamin Kramer | a9390a4 | 2011-09-27 20:39:19 +0000 | [diff] [blame] | 22 | ; CHECK: %1 = fcmp oeq double %x, 0xFFF0000000000000 |
| 23 | ; CHECK: %retval = select i1 %1, double 0x7FF0000000000000, double %fabs |
| 24 | ; CHECK: ret double %retval |
Dan Gohman | 79cb840 | 2009-09-25 23:10:17 +0000 | [diff] [blame] | 25 | ; CHECK: } |
| 26 | |
| 27 | define double @doo(double %x) nounwind { |
Dan Gohman | 76926b6 | 2009-09-26 18:10:13 +0000 | [diff] [blame] | 28 | %retval = call double @pow(double %x, double 0.5) |
Dan Gohman | 79cb840 | 2009-09-25 23:10:17 +0000 | [diff] [blame] | 29 | ret double %retval |
| 30 | } |
| 31 | |
| 32 | declare float @powf(float, float) nounwind readonly |
| 33 | declare double @pow(double, double) nounwind readonly |