Sanjay Patel | 2580c95 | 2016-12-08 20:23:56 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 3 | |
Sanjay Patel | 49b7dc2 | 2018-03-12 15:47:32 +0000 | [diff] [blame] | 4 | define <2 x float> @fsub_negzero_vec_undef_elts(<2 x float> %x) { |
| 5 | ; CHECK-LABEL: @fsub_negzero_vec_undef_elts( |
Sanjay Patel | a0d8d12 | 2018-03-12 18:17:01 +0000 | [diff] [blame] | 6 | ; CHECK-NEXT: ret <2 x float> [[X:%.*]] |
Sanjay Patel | 49b7dc2 | 2018-03-12 15:47:32 +0000 | [diff] [blame] | 7 | ; |
| 8 | %r = fsub nsz <2 x float> %x, <float undef, float -0.0> |
| 9 | ret <2 x float> %r |
| 10 | } |
| 11 | |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 12 | ; fsub -0.0, (fsub -0.0, X) ==> X |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 13 | define float @fsub_-0_-0_x(float %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 14 | ; CHECK-LABEL: @fsub_-0_-0_x( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 15 | ; CHECK-NEXT: ret float [[A:%.*]] |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 16 | ; |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 17 | %t1 = fsub float -0.0, %a |
| 18 | %ret = fsub float -0.0, %t1 |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 19 | ret float %ret |
| 20 | } |
| 21 | |
Sanjay Patel | 66911b1 | 2018-02-26 23:23:02 +0000 | [diff] [blame] | 22 | define <2 x float> @fsub_-0_-0_x_vec(<2 x float> %a) { |
| 23 | ; CHECK-LABEL: @fsub_-0_-0_x_vec( |
| 24 | ; CHECK-NEXT: ret <2 x float> [[A:%.*]] |
| 25 | ; |
| 26 | %t1 = fsub <2 x float> <float -0.0, float -0.0>, %a |
| 27 | %ret = fsub <2 x float> <float -0.0, float -0.0>, %t1 |
| 28 | ret <2 x float> %ret |
| 29 | } |
| 30 | |
| 31 | define <2 x float> @fsub_-0_-0_x_vec_undef_elts(<2 x float> %a) { |
| 32 | ; CHECK-LABEL: @fsub_-0_-0_x_vec_undef_elts( |
Sanjay Patel | a0d8d12 | 2018-03-12 18:17:01 +0000 | [diff] [blame] | 33 | ; CHECK-NEXT: ret <2 x float> [[A:%.*]] |
Sanjay Patel | 66911b1 | 2018-02-26 23:23:02 +0000 | [diff] [blame] | 34 | ; |
| 35 | %t1 = fsub <2 x float> <float undef, float -0.0>, %a |
| 36 | %ret = fsub <2 x float> <float -0.0, float undef>, %t1 |
| 37 | ret <2 x float> %ret |
| 38 | } |
| 39 | |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 40 | ; fsub 0.0, (fsub -0.0, X) != X |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 41 | define float @fsub_0_-0_x(float %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 42 | ; CHECK-LABEL: @fsub_0_-0_x( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 43 | ; CHECK-NEXT: [[T1:%.*]] = fsub float 0.000000e+00, [[A:%.*]] |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 44 | ; CHECK-NEXT: [[RET:%.*]] = fsub float -0.000000e+00, [[T1]] |
| 45 | ; CHECK-NEXT: ret float [[RET]] |
| 46 | ; |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 47 | %t1 = fsub float 0.0, %a |
| 48 | %ret = fsub float -0.0, %t1 |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 49 | ret float %ret |
| 50 | } |
| 51 | |
| 52 | ; fsub -0.0, (fsub 0.0, X) != X |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 53 | define float @fsub_-0_0_x(float %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 54 | ; CHECK-LABEL: @fsub_-0_0_x( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 55 | ; CHECK-NEXT: [[T1:%.*]] = fsub float -0.000000e+00, [[A:%.*]] |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 56 | ; CHECK-NEXT: [[RET:%.*]] = fsub float 0.000000e+00, [[T1]] |
| 57 | ; CHECK-NEXT: ret float [[RET]] |
| 58 | ; |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 59 | %t1 = fsub float -0.0, %a |
| 60 | %ret = fsub float 0.0, %t1 |
Benjamin Kramer | f5b2a47 | 2016-02-29 11:12:23 +0000 | [diff] [blame] | 61 | ret float %ret |
| 62 | } |
| 63 | |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 64 | ; fsub X, 0 ==> X |
Sanjay Patel | c84b48e | 2018-03-25 17:48:20 +0000 | [diff] [blame^] | 65 | define float @fsub_x_0(float %x) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 66 | ; CHECK-LABEL: @fsub_x_0( |
Sanjay Patel | c84b48e | 2018-03-25 17:48:20 +0000 | [diff] [blame^] | 67 | ; CHECK-NEXT: ret float [[X:%.*]] |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 68 | ; |
Sanjay Patel | c84b48e | 2018-03-25 17:48:20 +0000 | [diff] [blame^] | 69 | %r = fsub float %x, 0.0 |
| 70 | ret float %r |
| 71 | } |
| 72 | |
| 73 | define <2 x float> @fsub_x_0_vec_undef(<2 x float> %x) { |
| 74 | ; CHECK-LABEL: @fsub_x_0_vec_undef( |
| 75 | ; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> [[X:%.*]], <float undef, float 0.000000e+00> |
| 76 | ; CHECK-NEXT: ret <2 x float> [[R]] |
| 77 | ; |
| 78 | %r = fsub <2 x float> %x, <float undef, float 0.0> |
| 79 | ret <2 x float> %r |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | ; fadd X, -0 ==> X |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 83 | define float @fadd_x_n0(float %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 84 | ; CHECK-LABEL: @fadd_x_n0( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 85 | ; CHECK-NEXT: ret float [[A:%.*]] |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 86 | ; |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 87 | %ret = fadd float %a, -0.0 |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 88 | ret float %ret |
| 89 | } |
| 90 | |
Sanjay Patel | 66911b1 | 2018-02-26 23:23:02 +0000 | [diff] [blame] | 91 | define <2 x float> @fadd_x_n0_vec_undef_elt(<2 x float> %a) { |
| 92 | ; CHECK-LABEL: @fadd_x_n0_vec_undef_elt( |
Sanjay Patel | a0d8d12 | 2018-03-12 18:17:01 +0000 | [diff] [blame] | 93 | ; CHECK-NEXT: ret <2 x float> [[A:%.*]] |
Sanjay Patel | 66911b1 | 2018-02-26 23:23:02 +0000 | [diff] [blame] | 94 | ; |
| 95 | %ret = fadd <2 x float> %a, <float -0.0, float undef> |
| 96 | ret <2 x float> %ret |
| 97 | } |
| 98 | |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 99 | ; fmul X, 1.0 ==> X |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 100 | define double @fmul_X_1(double %a) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 101 | ; CHECK-LABEL: @fmul_X_1( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 102 | ; CHECK-NEXT: ret double [[A:%.*]] |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 103 | ; |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 104 | %b = fmul double 1.0, %a |
Michael Ilseman | bb6f691 | 2012-12-12 00:27:46 +0000 | [diff] [blame] | 105 | ret double %b |
| 106 | } |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 107 | |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 108 | ; PR2642 |
| 109 | define <4 x float> @fmul_X_1_vec(<4 x float> %x) { |
| 110 | ; CHECK-LABEL: @fmul_X_1_vec( |
| 111 | ; CHECK-NEXT: ret <4 x float> [[X:%.*]] |
| 112 | ; |
| 113 | %m = fmul <4 x float> %x, <float 1.0, float 1.0, float 1.0, float 1.0> |
| 114 | ret <4 x float> %m |
| 115 | } |
| 116 | |
Sanjay Patel | 2580c95 | 2016-12-08 20:23:56 +0000 | [diff] [blame] | 117 | ; fdiv X, 1.0 ==> X |
| 118 | define float @fdiv_x_1(float %a) { |
| 119 | ; CHECK-LABEL: @fdiv_x_1( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 120 | ; CHECK-NEXT: ret float [[A:%.*]] |
Sanjay Patel | 2580c95 | 2016-12-08 20:23:56 +0000 | [diff] [blame] | 121 | ; |
| 122 | %ret = fdiv float %a, 1.0 |
| 123 | ret float %ret |
| 124 | } |
| 125 | |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 126 | ; We can't optimize away the fadd in this test because the input |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 127 | ; value to the function and subsequently to the fadd may be -0.0. |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 128 | ; In that one special case, the result of the fadd should be +0.0 |
| 129 | ; rather than the first parameter of the fadd. |
| 130 | |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 131 | ; Fragile test warning: We need 6 sqrt calls to trigger the bug |
| 132 | ; because the internal logic has a magic recursion limit of 6. |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 133 | ; This is presented without any explanation or ability to customize. |
| 134 | |
| 135 | declare float @sqrtf(float) |
| 136 | |
| 137 | define float @PR22688(float %x) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 138 | ; CHECK-LABEL: @PR22688( |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 139 | ; CHECK-NEXT: [[TMP1:%.*]] = call float @sqrtf(float [[X:%.*]]) |
Sanjay Patel | 2580c95 | 2016-12-08 20:23:56 +0000 | [diff] [blame] | 140 | ; CHECK-NEXT: [[TMP2:%.*]] = call float @sqrtf(float [[TMP1]]) |
| 141 | ; CHECK-NEXT: [[TMP3:%.*]] = call float @sqrtf(float [[TMP2]]) |
| 142 | ; CHECK-NEXT: [[TMP4:%.*]] = call float @sqrtf(float [[TMP3]]) |
| 143 | ; CHECK-NEXT: [[TMP5:%.*]] = call float @sqrtf(float [[TMP4]]) |
| 144 | ; CHECK-NEXT: [[TMP6:%.*]] = call float @sqrtf(float [[TMP5]]) |
| 145 | ; CHECK-NEXT: [[TMP7:%.*]] = fadd float [[TMP6]], 0.000000e+00 |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 146 | ; CHECK-NEXT: ret float [[TMP7]] |
| 147 | ; |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 148 | %1 = call float @sqrtf(float %x) |
| 149 | %2 = call float @sqrtf(float %1) |
| 150 | %3 = call float @sqrtf(float %2) |
| 151 | %4 = call float @sqrtf(float %3) |
| 152 | %5 = call float @sqrtf(float %4) |
| 153 | %6 = call float @sqrtf(float %5) |
| 154 | %7 = fadd float %6, 0.0 |
| 155 | ret float %7 |
Sanjay Patel | 40eaa8d | 2015-02-25 18:00:15 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 158 | declare float @llvm.fabs.f32(float) |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 159 | declare <2 x float> @llvm.fabs.v2f32(<2 x float>) |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 160 | declare float @llvm.sqrt.f32(float) |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 161 | |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 162 | define float @fabs_select_positive_constants(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 163 | ; CHECK-LABEL: @fabs_select_positive_constants( |
| 164 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 165 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 |
| 166 | ; CHECK-NEXT: ret float [[SELECT]] |
| 167 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 168 | %cmp = icmp eq i32 %c, 0 |
| 169 | %select = select i1 %cmp, float 1.0, float 2.0 |
| 170 | %fabs = call float @llvm.fabs.f32(float %select) |
| 171 | ret float %fabs |
| 172 | } |
| 173 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 174 | define <2 x float> @fabs_select_positive_constants_vector(i32 %c) { |
| 175 | ; CHECK-LABEL: @fabs_select_positive_constants_vector( |
| 176 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 177 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> <float 2.000000e+00, float 2.000000e+00> |
Craig Topper | 69c8972 | 2018-02-26 22:33:17 +0000 | [diff] [blame] | 178 | ; CHECK-NEXT: ret <2 x float> [[SELECT]] |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 179 | ; |
| 180 | %cmp = icmp eq i32 %c, 0 |
| 181 | %select = select i1 %cmp, <2 x float> <float 1.0, float 1.0>, <2 x float> <float 2.0, float 2.0> |
| 182 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 183 | ret <2 x float> %fabs |
| 184 | } |
| 185 | |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 186 | define float @fabs_select_constant_variable(i32 %c, float %x) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 187 | ; CHECK-LABEL: @fabs_select_constant_variable( |
| 188 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 189 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 1.000000e+00, float [[X:%.*]] |
| 190 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 191 | ; CHECK-NEXT: ret float [[FABS]] |
| 192 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 193 | %cmp = icmp eq i32 %c, 0 |
| 194 | %select = select i1 %cmp, float 1.0, float %x |
| 195 | %fabs = call float @llvm.fabs.f32(float %select) |
| 196 | ret float %fabs |
| 197 | } |
| 198 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 199 | define <2 x float> @fabs_select_constant_variable_vector(i32 %c, <2 x float> %x) { |
| 200 | ; CHECK-LABEL: @fabs_select_constant_variable_vector( |
| 201 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 202 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> [[X:%.*]] |
| 203 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 204 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 205 | ; |
| 206 | %cmp = icmp eq i32 %c, 0 |
| 207 | %select = select i1 %cmp, <2 x float> <float 1.0, float 1.0>, <2 x float> %x |
| 208 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 209 | ret <2 x float> %fabs |
| 210 | } |
| 211 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 212 | define float @fabs_select_neg0_pos0(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 213 | ; CHECK-LABEL: @fabs_select_neg0_pos0( |
| 214 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 215 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float -0.000000e+00, float 0.000000e+00 |
| 216 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 217 | ; CHECK-NEXT: ret float [[FABS]] |
| 218 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 219 | %cmp = icmp eq i32 %c, 0 |
| 220 | %select = select i1 %cmp, float -0.0, float 0.0 |
| 221 | %fabs = call float @llvm.fabs.f32(float %select) |
| 222 | ret float %fabs |
| 223 | } |
| 224 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 225 | define <2 x float> @fabs_select_neg0_pos0_vector(i32 %c) { |
| 226 | ; CHECK-LABEL: @fabs_select_neg0_pos0_vector( |
| 227 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 228 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float -0.000000e+00, float -0.000000e+00>, <2 x float> zeroinitializer |
| 229 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 230 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 231 | ; |
| 232 | %cmp = icmp eq i32 %c, 0 |
| 233 | %select = select i1 %cmp, <2 x float> <float -0.0, float -0.0>, <2 x float> <float 0.0, float 0.0> |
| 234 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 235 | ret <2 x float> %fabs |
| 236 | } |
| 237 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 238 | define float @fabs_select_neg0_neg1(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 239 | ; CHECK-LABEL: @fabs_select_neg0_neg1( |
| 240 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 241 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float -0.000000e+00, float -1.000000e+00 |
| 242 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 243 | ; CHECK-NEXT: ret float [[FABS]] |
| 244 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 245 | %cmp = icmp eq i32 %c, 0 |
| 246 | %select = select i1 %cmp, float -0.0, float -1.0 |
| 247 | %fabs = call float @llvm.fabs.f32(float %select) |
| 248 | ret float %fabs |
| 249 | } |
| 250 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 251 | define <2 x float> @fabs_select_neg0_neg1_vector(i32 %c) { |
| 252 | ; CHECK-LABEL: @fabs_select_neg0_neg1_vector( |
| 253 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 254 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float -0.000000e+00, float -0.000000e+00>, <2 x float> <float -1.000000e+00, float -1.000000e+00> |
| 255 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 256 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 257 | ; |
| 258 | %cmp = icmp eq i32 %c, 0 |
| 259 | %select = select i1 %cmp, <2 x float> <float -0.0, float -0.0>, <2 x float> <float -1.0, float -1.0> |
| 260 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 261 | ret <2 x float> %fabs |
| 262 | } |
| 263 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 264 | define float @fabs_select_nan_nan(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 265 | ; CHECK-LABEL: @fabs_select_nan_nan( |
| 266 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 267 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0x7FF8000000000000, float 0x7FF8000100000000 |
| 268 | ; CHECK-NEXT: ret float [[SELECT]] |
| 269 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 270 | %cmp = icmp eq i32 %c, 0 |
| 271 | %select = select i1 %cmp, float 0x7FF8000000000000, float 0x7FF8000100000000 |
| 272 | %fabs = call float @llvm.fabs.f32(float %select) |
| 273 | ret float %fabs |
| 274 | } |
| 275 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 276 | define <2 x float> @fabs_select_nan_nan_vector(i32 %c) { |
| 277 | ; CHECK-LABEL: @fabs_select_nan_nan_vector( |
| 278 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 279 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> <float 0x7FF8000100000000, float 0x7FF8000100000000> |
Craig Topper | 69c8972 | 2018-02-26 22:33:17 +0000 | [diff] [blame] | 280 | ; CHECK-NEXT: ret <2 x float> [[SELECT]] |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 281 | ; |
| 282 | %cmp = icmp eq i32 %c, 0 |
| 283 | %select = select i1 %cmp, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> <float 0x7FF8000100000000, float 0x7FF8000100000000> |
| 284 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 285 | ret <2 x float> %fabs |
| 286 | } |
| 287 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 288 | define float @fabs_select_negnan_nan(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 289 | ; CHECK-LABEL: @fabs_select_negnan_nan( |
| 290 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 291 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float 0x7FF8000000000000 |
| 292 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 293 | ; CHECK-NEXT: ret float [[FABS]] |
| 294 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 295 | %cmp = icmp eq i32 %c, 0 |
| 296 | %select = select i1 %cmp, float 0xFFF8000000000000, float 0x7FF8000000000000 |
| 297 | %fabs = call float @llvm.fabs.f32(float %select) |
| 298 | ret float %fabs |
| 299 | } |
| 300 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 301 | define <2 x float> @fabs_select_negnan_nan_vector(i32 %c) { |
| 302 | ; CHECK-LABEL: @fabs_select_negnan_nan_vector( |
| 303 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 304 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000> |
| 305 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 306 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 307 | ; |
| 308 | %cmp = icmp eq i32 %c, 0 |
| 309 | %select = select i1 %cmp, <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000> |
| 310 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 311 | ret <2 x float> %fabs |
| 312 | } |
| 313 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 314 | define float @fabs_select_negnan_negnan(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 315 | ; CHECK-LABEL: @fabs_select_negnan_negnan( |
| 316 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 317 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float 0x7FF8000100000000 |
| 318 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 319 | ; CHECK-NEXT: ret float [[FABS]] |
| 320 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 321 | %cmp = icmp eq i32 %c, 0 |
| 322 | %select = select i1 %cmp, float 0xFFF8000000000000, float 0x7FF8000100000000 |
| 323 | %fabs = call float @llvm.fabs.f32(float %select) |
| 324 | ret float %fabs |
| 325 | } |
| 326 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 327 | define <2 x float> @fabs_select_negnan_negnan_vector(i32 %c) { |
| 328 | ; CHECK-LABEL: @fabs_select_negnan_negnan_vector( |
| 329 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 330 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float 0x7FF8000100000000, float 0x7FF8000100000000> |
| 331 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 332 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 333 | ; |
| 334 | %cmp = icmp eq i32 %c, 0 |
| 335 | %select = select i1 %cmp, <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float 0x7FF8000100000000, float 0x7FF8000100000000> |
| 336 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 337 | ret <2 x float> %fabs |
| 338 | } |
| 339 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 340 | define float @fabs_select_negnan_negzero(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 341 | ; CHECK-LABEL: @fabs_select_negnan_negzero( |
| 342 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 343 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float -0.000000e+00 |
| 344 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 345 | ; CHECK-NEXT: ret float [[FABS]] |
| 346 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 347 | %cmp = icmp eq i32 %c, 0 |
| 348 | %select = select i1 %cmp, float 0xFFF8000000000000, float -0.0 |
| 349 | %fabs = call float @llvm.fabs.f32(float %select) |
| 350 | ret float %fabs |
| 351 | } |
| 352 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 353 | define <2 x float> @fabs_select_negnan_negzero_vector(i32 %c) { |
| 354 | ; CHECK-LABEL: @fabs_select_negnan_negzero_vector( |
| 355 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 356 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float -0.000000e+00, float -0.000000e+00> |
| 357 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 358 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 359 | ; |
| 360 | %cmp = icmp eq i32 %c, 0 |
| 361 | %select = select i1 %cmp, <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float -0.0, float -0.0> |
| 362 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 363 | ret <2 x float> %fabs |
| 364 | } |
| 365 | |
Craig Topper | 2b8f051 | 2018-02-25 06:51:51 +0000 | [diff] [blame] | 366 | define float @fabs_select_negnan_zero(i32 %c) { |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 367 | ; CHECK-LABEL: @fabs_select_negnan_zero( |
| 368 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 369 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float 0.000000e+00 |
| 370 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) |
| 371 | ; CHECK-NEXT: ret float [[FABS]] |
| 372 | ; |
Matt Arsenault | 1e0edbf | 2017-01-11 00:33:24 +0000 | [diff] [blame] | 373 | %cmp = icmp eq i32 %c, 0 |
| 374 | %select = select i1 %cmp, float 0xFFF8000000000000, float 0.0 |
| 375 | %fabs = call float @llvm.fabs.f32(float %select) |
| 376 | ret float %fabs |
| 377 | } |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 378 | |
Craig Topper | aee341e | 2018-02-25 06:51:52 +0000 | [diff] [blame] | 379 | define <2 x float> @fabs_select_negnan_zero_vector(i32 %c) { |
| 380 | ; CHECK-LABEL: @fabs_select_negnan_zero_vector( |
| 381 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 382 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> zeroinitializer |
| 383 | ; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) |
| 384 | ; CHECK-NEXT: ret <2 x float> [[FABS]] |
| 385 | ; |
| 386 | %cmp = icmp eq i32 %c, 0 |
| 387 | %select = select i1 %cmp, <2 x float> <float 0xFFF8000000000000, float 0xFFF8000000000000>, <2 x float> <float 0.0, float 0.0> |
| 388 | %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %select) |
| 389 | ret <2 x float> %fabs |
| 390 | } |
| 391 | |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 392 | ; The fabs can't be eliminated because llvm.sqrt.f32 may return -0 or NaN with |
| 393 | ; an arbitrary sign bit. |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 394 | define float @fabs_sqrt(float %a) { |
| 395 | ; CHECK-LABEL: @fabs_sqrt( |
| 396 | ; CHECK-NEXT: [[SQRT:%.*]] = call float @llvm.sqrt.f32(float [[A:%.*]]) |
| 397 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) |
| 398 | ; CHECK-NEXT: ret float [[FABS]] |
| 399 | ; |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 400 | %sqrt = call float @llvm.sqrt.f32(float %a) |
| 401 | %fabs = call float @llvm.fabs.f32(float %sqrt) |
| 402 | ret float %fabs |
| 403 | } |
| 404 | |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 405 | ; The fabs can't be eliminated because the nnan sqrt may still return -0. |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 406 | define float @fabs_sqrt_nnan(float %a) { |
| 407 | ; CHECK-LABEL: @fabs_sqrt_nnan( |
| 408 | ; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.sqrt.f32(float [[A:%.*]]) |
| 409 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) |
| 410 | ; CHECK-NEXT: ret float [[FABS]] |
| 411 | ; |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 412 | %sqrt = call nnan float @llvm.sqrt.f32(float %a) |
| 413 | %fabs = call float @llvm.fabs.f32(float %sqrt) |
| 414 | ret float %fabs |
| 415 | } |
| 416 | |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 417 | ; The fabs can't be eliminated because the nsz sqrt may still return NaN. |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 418 | define float @fabs_sqrt_nsz(float %a) { |
| 419 | ; CHECK-LABEL: @fabs_sqrt_nsz( |
| 420 | ; CHECK-NEXT: [[SQRT:%.*]] = call nsz float @llvm.sqrt.f32(float [[A:%.*]]) |
| 421 | ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]]) |
| 422 | ; CHECK-NEXT: ret float [[FABS]] |
| 423 | ; |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 424 | %sqrt = call nsz float @llvm.sqrt.f32(float %a) |
| 425 | %fabs = call float @llvm.fabs.f32(float %sqrt) |
| 426 | ret float %fabs |
| 427 | } |
| 428 | |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 429 | ; The fabs can be eliminated because we're nsz and nnan. |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 430 | define float @fabs_sqrt_nnan_nsz(float %a) { |
| 431 | ; CHECK-LABEL: @fabs_sqrt_nnan_nsz( |
| 432 | ; CHECK-NEXT: [[SQRT:%.*]] = call nnan nsz float @llvm.sqrt.f32(float [[A:%.*]]) |
| 433 | ; CHECK-NEXT: ret float [[SQRT]] |
| 434 | ; |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 435 | %sqrt = call nnan nsz float @llvm.sqrt.f32(float %a) |
| 436 | %fabs = call float @llvm.fabs.f32(float %sqrt) |
| 437 | ret float %fabs |
| 438 | } |
| 439 | |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 440 | ; The second fabs can be eliminated because the operand to sqrt cannot be -0. |
Sanjay Patel | b13fcd5 | 2018-02-13 18:22:53 +0000 | [diff] [blame] | 441 | define float @fabs_sqrt_nnan_fabs(float %a) { |
| 442 | ; CHECK-LABEL: @fabs_sqrt_nnan_fabs( |
| 443 | ; CHECK-NEXT: [[B:%.*]] = call float @llvm.fabs.f32(float [[A:%.*]]) |
| 444 | ; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.sqrt.f32(float [[B]]) |
| 445 | ; CHECK-NEXT: ret float [[SQRT]] |
| 446 | ; |
Justin Lebar | 7e3184c | 2017-01-26 00:10:26 +0000 | [diff] [blame] | 447 | %b = call float @llvm.fabs.f32(float %a) |
| 448 | %sqrt = call nnan float @llvm.sqrt.f32(float %b) |
| 449 | %fabs = call float @llvm.fabs.f32(float %sqrt) |
| 450 | ret float %fabs |
| 451 | } |
Craig Topper | 3019910 | 2018-02-27 19:53:45 +0000 | [diff] [blame] | 452 | |
| 453 | define float @fabs_select_positive_constants_vector_extract(i32 %c) { |
| 454 | ; CHECK-LABEL: @fabs_select_positive_constants_vector_extract( |
| 455 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 |
| 456 | ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> <float 2.000000e+00, float 2.000000e+00> |
| 457 | ; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <2 x float> [[SELECT]], i32 0 |
| 458 | ; CHECK-NEXT: ret float [[EXTRACT]] |
| 459 | ; |
| 460 | %cmp = icmp eq i32 %c, 0 |
| 461 | %select = select i1 %cmp, <2 x float> <float 1.0, float 1.0>, <2 x float> <float 2.0, float 2.0> |
| 462 | %extract = extractelement <2 x float> %select, i32 0 |
| 463 | %fabs = call float @llvm.fabs.f32(float %extract) |
| 464 | ret float %fabs |
| 465 | } |