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