Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | |
| 3 | ; fsub 0, (fsub 0, X) ==> X |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 4 | ; CHECK-LABEL: @fsub_0_0_x( |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 5 | define float @fsub_0_0_x(float %a) { |
| 6 | %t1 = fsub float -0.0, %a |
| 7 | %ret = fsub float -0.0, %t1 |
| 8 | |
| 9 | ; CHECK: ret float %a |
| 10 | ret float %ret |
| 11 | } |
| 12 | |
| 13 | ; fsub X, 0 ==> X |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 14 | ; CHECK-LABEL: @fsub_x_0( |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 15 | define float @fsub_x_0(float %a) { |
| 16 | %ret = fsub float %a, 0.0 |
Benjamin Kramer | b50682e | 2013-04-11 12:41:41 +0000 | [diff] [blame] | 17 | ; CHECK: ret float %a |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 18 | ret float %ret |
| 19 | } |
| 20 | |
| 21 | ; fadd X, -0 ==> X |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 22 | ; CHECK-LABEL: @fadd_x_n0( |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 23 | define float @fadd_x_n0(float %a) { |
| 24 | %ret = fadd float %a, -0.0 |
Benjamin Kramer | b50682e | 2013-04-11 12:41:41 +0000 | [diff] [blame] | 25 | ; CHECK: ret float %a |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 26 | ret float %ret |
| 27 | } |
| 28 | |
| 29 | ; fmul X, 1.0 ==> X |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 30 | ; CHECK-LABEL: @fmul_X_1( |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 31 | define double @fmul_X_1(double %a) { |
| 32 | %b = fmul double 1.000000e+00, %a ; <double> [#uses=1] |
| 33 | ; CHECK: ret double %a |
| 34 | ret double %b |
| 35 | } |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 36 | |
| 37 | ; We can't optimize away the fadd in this test because the input |
| 38 | ; value to the function and subsequently to the fadd may be -0.0. |
| 39 | ; In that one special case, the result of the fadd should be +0.0 |
| 40 | ; rather than the first parameter of the fadd. |
| 41 | |
| 42 | ; Fragile test warning: We need 6 sqrt calls to trigger the bug |
| 43 | ; because the internal logic has a magic recursion limit of 6. |
| 44 | ; This is presented without any explanation or ability to customize. |
| 45 | |
| 46 | declare float @sqrtf(float) |
| 47 | |
| 48 | define float @PR22688(float %x) { |
| 49 | %1 = call float @sqrtf(float %x) |
| 50 | %2 = call float @sqrtf(float %1) |
| 51 | %3 = call float @sqrtf(float %2) |
| 52 | %4 = call float @sqrtf(float %3) |
| 53 | %5 = call float @sqrtf(float %4) |
| 54 | %6 = call float @sqrtf(float %5) |
| 55 | %7 = fadd float %6, 0.0 |
| 56 | ret float %7 |
| 57 | |
| 58 | ; CHECK-LABEL: @PR22688( |
| 59 | ; CHECK: fadd float %6, 0.0 |
| 60 | } |
| 61 | |