1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -instcombine -S | FileCheck %s 3 4; Make sure libcalls are replaced with intrinsic calls. 5 6declare float @llvm.fabs.f32(float) 7declare <2 x float> @llvm.fabs.v2f32(<2 x float>) 8declare double @llvm.fabs.f64(double) 9declare fp128 @llvm.fabs.f128(fp128) 10 11declare float @fabsf(float) 12declare double @fabs(double) 13declare fp128 @fabsl(fp128) 14declare float @llvm.fma.f32(float, float, float) 15declare float @llvm.fmuladd.f32(float, float, float) 16 17declare void @use(float) 18 19define float @replace_fabs_call_f32(float %x) { 20; CHECK-LABEL: @replace_fabs_call_f32( 21; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]]) 22; CHECK-NEXT: ret float [[FABSF]] 23; 24 %fabsf = tail call float @fabsf(float %x) 25 ret float %fabsf 26} 27 28define double @replace_fabs_call_f64(double %x) { 29; CHECK-LABEL: @replace_fabs_call_f64( 30; CHECK-NEXT: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]]) 31; CHECK-NEXT: ret double [[FABS]] 32; 33 %fabs = tail call double @fabs(double %x) 34 ret double %fabs 35} 36 37define fp128 @replace_fabs_call_f128(fp128 %x) { 38; CHECK-LABEL: @replace_fabs_call_f128( 39; CHECK-NEXT: [[FABSL:%.*]] = call fp128 @llvm.fabs.f128(fp128 [[X:%.*]]) 40; CHECK-NEXT: ret fp128 [[FABSL]] 41; 42 %fabsl = tail call fp128 @fabsl(fp128 %x) 43 ret fp128 %fabsl 44} 45 46; Make sure fast math flags are preserved when replacing the libcall. 47define float @fmf_replace_fabs_call_f32(float %x) { 48; CHECK-LABEL: @fmf_replace_fabs_call_f32( 49; CHECK-NEXT: [[FABSF:%.*]] = call nnan float @llvm.fabs.f32(float [[X:%.*]]) 50; CHECK-NEXT: ret float [[FABSF]] 51; 52 %fabsf = tail call nnan float @fabsf(float %x) 53 ret float %fabsf 54} 55 56; Make sure all intrinsic calls are eliminated when the input is known 57; positive. 58 59; The fabs cannot be eliminated because %x may be a NaN 60 61define float @square_fabs_intrinsic_f32(float %x) { 62; CHECK-LABEL: @square_fabs_intrinsic_f32( 63; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X:%.*]], [[X]] 64; CHECK-NEXT: [[FABSF:%.*]] = tail call float @llvm.fabs.f32(float [[MUL]]) 65; CHECK-NEXT: ret float [[FABSF]] 66; 67 %mul = fmul float %x, %x 68 %fabsf = tail call float @llvm.fabs.f32(float %mul) 69 ret float %fabsf 70} 71 72define double @square_fabs_intrinsic_f64(double %x) { 73; CHECK-LABEL: @square_fabs_intrinsic_f64( 74; CHECK-NEXT: [[MUL:%.*]] = fmul double [[X:%.*]], [[X]] 75; CHECK-NEXT: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[MUL]]) 76; CHECK-NEXT: ret double [[FABS]] 77; 78 %mul = fmul double %x, %x 79 %fabs = tail call double @llvm.fabs.f64(double %mul) 80 ret double %fabs 81} 82 83define fp128 @square_fabs_intrinsic_f128(fp128 %x) { 84; CHECK-LABEL: @square_fabs_intrinsic_f128( 85; CHECK-NEXT: [[MUL:%.*]] = fmul fp128 [[X:%.*]], [[X]] 86; CHECK-NEXT: [[FABSL:%.*]] = tail call fp128 @llvm.fabs.f128(fp128 [[MUL]]) 87; CHECK-NEXT: ret fp128 [[FABSL]] 88; 89 %mul = fmul fp128 %x, %x 90 %fabsl = tail call fp128 @llvm.fabs.f128(fp128 %mul) 91 ret fp128 %fabsl 92} 93 94define float @square_nnan_fabs_intrinsic_f32(float %x) { 95; CHECK-LABEL: @square_nnan_fabs_intrinsic_f32( 96; CHECK-NEXT: [[MUL:%.*]] = fmul nnan float [[X:%.*]], [[X]] 97; CHECK-NEXT: ret float [[MUL]] 98; 99 %mul = fmul nnan float %x, %x 100 %fabsf = call float @llvm.fabs.f32(float %mul) 101 ret float %fabsf 102} 103 104; Shrinking a library call to a smaller type should not be inhibited by nor inhibit the square optimization. 105 106define float @square_fabs_shrink_call1(float %x) { 107; CHECK-LABEL: @square_fabs_shrink_call1( 108; CHECK-NEXT: [[TMP1:%.*]] = fmul float [[X:%.*]], [[X]] 109; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.fabs.f32(float [[TMP1]]) 110; CHECK-NEXT: ret float [[TRUNC]] 111; 112 %ext = fpext float %x to double 113 %sq = fmul double %ext, %ext 114 %fabs = call double @fabs(double %sq) 115 %trunc = fptrunc double %fabs to float 116 ret float %trunc 117} 118 119define float @square_fabs_shrink_call2(float %x) { 120; CHECK-LABEL: @square_fabs_shrink_call2( 121; CHECK-NEXT: [[SQ:%.*]] = fmul float [[X:%.*]], [[X]] 122; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float [[SQ]]) 123; CHECK-NEXT: ret float [[TMP1]] 124; 125 %sq = fmul float %x, %x 126 %ext = fpext float %sq to double 127 %fabs = call double @fabs(double %ext) 128 %trunc = fptrunc double %fabs to float 129 ret float %trunc 130} 131 132define float @fabs_select_constant_negative_positive(i32 %c) { 133; CHECK-LABEL: @fabs_select_constant_negative_positive( 134; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 135; CHECK-NEXT: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 136; CHECK-NEXT: ret float [[FABS]] 137; 138 %cmp = icmp eq i32 %c, 0 139 %select = select i1 %cmp, float -1.0, float 2.0 140 %fabs = call float @llvm.fabs.f32(float %select) 141 ret float %fabs 142} 143 144define float @fabs_select_constant_positive_negative(i32 %c) { 145; CHECK-LABEL: @fabs_select_constant_positive_negative( 146; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 147; CHECK-NEXT: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 148; CHECK-NEXT: ret float [[FABS]] 149; 150 %cmp = icmp eq i32 %c, 0 151 %select = select i1 %cmp, float 1.0, float -2.0 152 %fabs = call float @llvm.fabs.f32(float %select) 153 ret float %fabs 154} 155 156define float @fabs_select_constant_negative_negative(i32 %c) { 157; CHECK-LABEL: @fabs_select_constant_negative_negative( 158; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 159; CHECK-NEXT: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 160; CHECK-NEXT: ret float [[FABS]] 161; 162 %cmp = icmp eq i32 %c, 0 163 %select = select i1 %cmp, float -1.0, float -2.0 164 %fabs = call float @llvm.fabs.f32(float %select) 165 ret float %fabs 166} 167 168define float @fabs_select_constant_neg0(i32 %c) { 169; CHECK-LABEL: @fabs_select_constant_neg0( 170; CHECK-NEXT: ret float 0.000000e+00 171; 172 %cmp = icmp eq i32 %c, 0 173 %select = select i1 %cmp, float -0.0, float 0.0 174 %fabs = call float @llvm.fabs.f32(float %select) 175 ret float %fabs 176} 177 178define float @fabs_select_var_constant_negative(i32 %c, float %x) { 179; CHECK-LABEL: @fabs_select_var_constant_negative( 180; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 181; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float [[X:%.*]], float -1.000000e+00 182; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) 183; CHECK-NEXT: ret float [[FABS]] 184; 185 %cmp = icmp eq i32 %c, 0 186 %select = select i1 %cmp, float %x, float -1.0 187 %fabs = call float @llvm.fabs.f32(float %select) 188 ret float %fabs 189} 190 191; The fabs cannot be eliminated because %x may be a NaN 192 193define float @square_fma_fabs_intrinsic_f32(float %x) { 194; CHECK-LABEL: @square_fma_fabs_intrinsic_f32( 195; CHECK-NEXT: [[FMA:%.*]] = call float @llvm.fma.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) 196; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[FMA]]) 197; CHECK-NEXT: ret float [[FABSF]] 198; 199 %fma = call float @llvm.fma.f32(float %x, float %x, float 1.0) 200 %fabsf = call float @llvm.fabs.f32(float %fma) 201 ret float %fabsf 202} 203 204; The fabs cannot be eliminated because %x may be a NaN 205 206define float @square_nnan_fma_fabs_intrinsic_f32(float %x) { 207; CHECK-LABEL: @square_nnan_fma_fabs_intrinsic_f32( 208; CHECK-NEXT: [[FMA:%.*]] = call nnan float @llvm.fma.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) 209; CHECK-NEXT: ret float [[FMA]] 210; 211 %fma = call nnan float @llvm.fma.f32(float %x, float %x, float 1.0) 212 %fabsf = call float @llvm.fabs.f32(float %fma) 213 ret float %fabsf 214} 215 216define float @square_fmuladd_fabs_intrinsic_f32(float %x) { 217; CHECK-LABEL: @square_fmuladd_fabs_intrinsic_f32( 218; CHECK-NEXT: [[FMULADD:%.*]] = call float @llvm.fmuladd.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) 219; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[FMULADD]]) 220; CHECK-NEXT: ret float [[FABSF]] 221; 222 %fmuladd = call float @llvm.fmuladd.f32(float %x, float %x, float 1.0) 223 %fabsf = call float @llvm.fabs.f32(float %fmuladd) 224 ret float %fabsf 225} 226 227define float @square_nnan_fmuladd_fabs_intrinsic_f32(float %x) { 228; CHECK-LABEL: @square_nnan_fmuladd_fabs_intrinsic_f32( 229; CHECK-NEXT: [[FMULADD:%.*]] = call nnan float @llvm.fmuladd.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) 230; CHECK-NEXT: ret float [[FMULADD]] 231; 232 %fmuladd = call nnan float @llvm.fmuladd.f32(float %x, float %x, float 1.0) 233 %fabsf = call float @llvm.fabs.f32(float %fmuladd) 234 ret float %fabsf 235} 236 237; Don't introduce a second fpext 238 239define double @multi_use_fabs_fpext(float %x) { 240; CHECK-LABEL: @multi_use_fabs_fpext( 241; CHECK-NEXT: [[FPEXT:%.*]] = fpext float [[X:%.*]] to double 242; CHECK-NEXT: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[FPEXT]]) 243; CHECK-NEXT: store volatile double [[FPEXT]], double* undef, align 8 244; CHECK-NEXT: ret double [[FABS]] 245; 246 %fpext = fpext float %x to double 247 %fabs = call double @llvm.fabs.f64(double %fpext) 248 store volatile double %fpext, double* undef 249 ret double %fabs 250} 251 252; Negative test for the fabs folds below: we require nnan, so 253; we won't always clear the sign bit of a NaN value. 254 255define double @select_fcmp_ole_zero(double %x) { 256; CHECK-LABEL: @select_fcmp_ole_zero( 257; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole double [[X:%.*]], 0.000000e+00 258; CHECK-NEXT: [[NEGX:%.*]] = fsub double 0.000000e+00, [[X]] 259; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] 260; CHECK-NEXT: ret double [[FABS]] 261; 262 %lezero = fcmp ole double %x, 0.0 263 %negx = fsub double 0.0, %x 264 %fabs = select i1 %lezero, double %negx, double %x 265 ret double %fabs 266} 267 268; X <= 0.0 ? (0.0 - X) : X --> fabs(X) 269 270define double @select_fcmp_nnan_ole_zero(double %x) { 271; CHECK-LABEL: @select_fcmp_nnan_ole_zero( 272; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]]) 273; CHECK-NEXT: ret double [[TMP1]] 274; 275 %lezero = fcmp ole double %x, 0.0 276 %negx = fsub nnan double 0.0, %x 277 %fabs = select i1 %lezero, double %negx, double %x 278 ret double %fabs 279} 280 281define double @select_nnan_fcmp_nnan_ole_zero(double %x) { 282; CHECK-LABEL: @select_nnan_fcmp_nnan_ole_zero( 283; CHECK-NEXT: [[TMP1:%.*]] = call nnan double @llvm.fabs.f64(double [[X:%.*]]) 284; CHECK-NEXT: ret double [[TMP1]] 285; 286 %lezero = fcmp ole double %x, 0.0 287 %negx = fsub nnan double 0.0, %x 288 %fabs = select nnan i1 %lezero, double %negx, double %x 289 ret double %fabs 290} 291 292; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 293 294define double @select_fcmp_nnan_ule_zero(double %x) { 295; CHECK-LABEL: @select_fcmp_nnan_ule_zero( 296; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]]) 297; CHECK-NEXT: ret double [[TMP1]] 298; 299 %lezero = fcmp ule double %x, 0.0 300 %negx = fsub nnan double 0.0, %x 301 %fabs = select i1 %lezero, double %negx, double %x 302 ret double %fabs 303} 304 305; Negative test - wrong predicate. 306 307define double @select_fcmp_nnan_olt_zero(double %x) { 308; CHECK-LABEL: @select_fcmp_nnan_olt_zero( 309; CHECK-NEXT: [[LEZERO:%.*]] = fcmp olt double [[X:%.*]], 0.000000e+00 310; CHECK-NEXT: [[NEGX:%.*]] = fsub nnan double 0.000000e+00, [[X]] 311; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] 312; CHECK-NEXT: ret double [[FABS]] 313; 314 %lezero = fcmp olt double %x, 0.0 315 %negx = fsub nnan double 0.0, %x 316 %fabs = select i1 %lezero, double %negx, double %x 317 ret double %fabs 318} 319 320; X <= -0.0 ? (0.0 - X) : X --> fabs(X) 321 322define <2 x float> @select_fcmp_nnan_ole_negzero(<2 x float> %x) { 323; CHECK-LABEL: @select_fcmp_nnan_ole_negzero( 324; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]]) 325; CHECK-NEXT: ret <2 x float> [[TMP1]] 326; 327 %lezero = fcmp ole <2 x float> %x, <float -0.0, float -0.0> 328 %negx = fsub nnan <2 x float> <float 0.0, float undef>, %x 329 %fabs = select <2 x i1> %lezero, <2 x float> %negx, <2 x float> %x 330 ret <2 x float> %fabs 331} 332 333define <2 x float> @select_nnan_fcmp_nnan_ole_negzero(<2 x float> %x) { 334; CHECK-LABEL: @select_nnan_fcmp_nnan_ole_negzero( 335; CHECK-NEXT: [[TMP1:%.*]] = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]]) 336; CHECK-NEXT: ret <2 x float> [[TMP1]] 337; 338 %lezero = fcmp ole <2 x float> %x, <float -0.0, float -0.0> 339 %negx = fsub nnan <2 x float> <float 0.0, float undef>, %x 340 %fabs = select nnan <2 x i1> %lezero, <2 x float> %negx, <2 x float> %x 341 ret <2 x float> %fabs 342} 343 344; X > 0.0 ? X : (0.0 - X) --> fabs(X) 345 346define fp128 @select_fcmp_nnan_ogt_zero(fp128 %x) { 347; CHECK-LABEL: @select_fcmp_nnan_ogt_zero( 348; CHECK-NEXT: [[TMP1:%.*]] = call fp128 @llvm.fabs.f128(fp128 [[X:%.*]]) 349; CHECK-NEXT: ret fp128 [[TMP1]] 350; 351 %gtzero = fcmp ogt fp128 %x, zeroinitializer 352 %negx = fsub nnan fp128 zeroinitializer, %x 353 %fabs = select i1 %gtzero, fp128 %x, fp128 %negx 354 ret fp128 %fabs 355} 356 357define fp128 @select_nnan_fcmp_nnan_ogt_zero(fp128 %x) { 358; CHECK-LABEL: @select_nnan_fcmp_nnan_ogt_zero( 359; CHECK-NEXT: [[TMP1:%.*]] = call nnan fp128 @llvm.fabs.f128(fp128 [[X:%.*]]) 360; CHECK-NEXT: ret fp128 [[TMP1]] 361; 362 %gtzero = fcmp ogt fp128 %x, zeroinitializer 363 %negx = fsub nnan fp128 zeroinitializer, %x 364 %fabs = select nnan i1 %gtzero, fp128 %x, fp128 %negx 365 ret fp128 %fabs 366} 367 368; X > -0.0 ? X : (0.0 - X) --> fabs(X) 369 370define half @select_fcmp_nnan_ogt_negzero(half %x) { 371; CHECK-LABEL: @select_fcmp_nnan_ogt_negzero( 372; CHECK-NEXT: [[TMP1:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]]) 373; CHECK-NEXT: ret half [[TMP1]] 374; 375 %gtzero = fcmp ogt half %x, -0.0 376 %negx = fsub nnan half 0.0, %x 377 %fabs = select i1 %gtzero, half %x, half %negx 378 ret half %fabs 379} 380 381define half @select_nnan_fcmp_nnan_ogt_negzero(half %x) { 382; CHECK-LABEL: @select_nnan_fcmp_nnan_ogt_negzero( 383; CHECK-NEXT: [[TMP1:%.*]] = call nnan half @llvm.fabs.f16(half [[X:%.*]]) 384; CHECK-NEXT: ret half [[TMP1]] 385; 386 %gtzero = fcmp ogt half %x, -0.0 387 %negx = fsub nnan half 0.0, %x 388 %fabs = select nnan i1 %gtzero, half %x, half %negx 389 ret half %fabs 390} 391 392; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 393 394define half @select_fcmp_nnan_ugt_negzero(half %x) { 395; CHECK-LABEL: @select_fcmp_nnan_ugt_negzero( 396; CHECK-NEXT: [[TMP1:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]]) 397; CHECK-NEXT: ret half [[TMP1]] 398; 399 %gtzero = fcmp ugt half %x, -0.0 400 %negx = fsub nnan half 0.0, %x 401 %fabs = select i1 %gtzero, half %x, half %negx 402 ret half %fabs 403} 404 405; Negative test - wrong predicate. 406 407define half @select_fcmp_nnan_oge_negzero(half %x) { 408; CHECK-LABEL: @select_fcmp_nnan_oge_negzero( 409; CHECK-NEXT: [[GTZERO:%.*]] = fcmp oge half [[X:%.*]], 0xH0000 410; CHECK-NEXT: [[NEGX:%.*]] = fsub nnan half 0xH0000, [[X]] 411; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]] 412; CHECK-NEXT: ret half [[FABS]] 413; 414 %gtzero = fcmp oge half %x, -0.0 415 %negx = fsub nnan half 0.0, %x 416 %fabs = select i1 %gtzero, half %x, half %negx 417 ret half %fabs 418} 419 420; X < 0.0 ? -X : X --> fabs(X) 421 422define double @select_fcmp_nnan_nsz_olt_zero(double %x) { 423; CHECK-LABEL: @select_fcmp_nnan_nsz_olt_zero( 424; CHECK-NEXT: [[LTZERO:%.*]] = fcmp olt double [[X:%.*]], 0.000000e+00 425; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz double [[X]] 426; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], double [[NEGX]], double [[X]] 427; CHECK-NEXT: ret double [[FABS]] 428; 429 %ltzero = fcmp olt double %x, 0.0 430 %negx = fsub nnan nsz double -0.0, %x 431 %fabs = select i1 %ltzero, double %negx, double %x 432 ret double %fabs 433} 434 435define double @select_nnan_nsz_fcmp_nnan_nsz_olt_zero(double %x) { 436; CHECK-LABEL: @select_nnan_nsz_fcmp_nnan_nsz_olt_zero( 437; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz double @llvm.fabs.f64(double [[X:%.*]]) 438; CHECK-NEXT: ret double [[TMP1]] 439; 440 %ltzero = fcmp olt double %x, 0.0 441 %negx = fsub nnan nsz double -0.0, %x 442 %fabs = select nnan nsz i1 %ltzero, double %negx, double %x 443 ret double %fabs 444} 445 446; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 447 448define double @select_fcmp_nnan_nsz_ult_zero(double %x) { 449; CHECK-LABEL: @select_fcmp_nnan_nsz_ult_zero( 450; CHECK-NEXT: [[LTZERO:%.*]] = fcmp ult double [[X:%.*]], 0.000000e+00 451; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz double [[X]] 452; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], double [[NEGX]], double [[X]] 453; CHECK-NEXT: ret double [[FABS]] 454; 455 %ltzero = fcmp ult double %x, 0.0 456 %negx = fsub nnan nsz double -0.0, %x 457 %fabs = select i1 %ltzero, double %negx, double %x 458 ret double %fabs 459} 460 461define double @select_fcmp_nnan_nsz_olt_zero_unary_fneg(double %x) { 462; CHECK-LABEL: @select_fcmp_nnan_nsz_olt_zero_unary_fneg( 463; CHECK-NEXT: [[LTZERO:%.*]] = fcmp olt double [[X:%.*]], 0.000000e+00 464; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz double [[X]] 465; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], double [[NEGX]], double [[X]] 466; CHECK-NEXT: ret double [[FABS]] 467; 468 %ltzero = fcmp olt double %x, 0.0 469 %negx = fneg nnan nsz double %x 470 %fabs = select i1 %ltzero, double %negx, double %x 471 ret double %fabs 472} 473 474; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 475 476define double @select_fcmp_nnan_nsz_ult_zero_unary_fneg(double %x) { 477; CHECK-LABEL: @select_fcmp_nnan_nsz_ult_zero_unary_fneg( 478; CHECK-NEXT: [[LTZERO:%.*]] = fcmp ult double [[X:%.*]], 0.000000e+00 479; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz double [[X]] 480; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], double [[NEGX]], double [[X]] 481; CHECK-NEXT: ret double [[FABS]] 482; 483 %ltzero = fcmp ult double %x, 0.0 484 %negx = fneg nnan nsz double %x 485 %fabs = select i1 %ltzero, double %negx, double %x 486 ret double %fabs 487} 488 489; X < -0.0 ? -X : X --> fabs(X) 490 491define float @select_fcmp_nnan_nsz_olt_negzero(float %x) { 492; CHECK-LABEL: @select_fcmp_nnan_nsz_olt_negzero( 493; CHECK-NEXT: [[LTZERO:%.*]] = fcmp olt float [[X:%.*]], 0.000000e+00 494; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan ninf nsz float [[X]] 495; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], float [[NEGX]], float [[X]] 496; CHECK-NEXT: ret float [[FABS]] 497; 498 %ltzero = fcmp olt float %x, -0.0 499 %negx = fsub nnan ninf nsz float -0.0, %x 500 %fabs = select i1 %ltzero, float %negx, float %x 501 ret float %fabs 502} 503 504define float @select_nnan_ninf_nsz_fcmp_nnan_nsz_olt_negzero(float %x) { 505; CHECK-LABEL: @select_nnan_ninf_nsz_fcmp_nnan_nsz_olt_negzero( 506; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf nsz float @llvm.fabs.f32(float [[X:%.*]]) 507; CHECK-NEXT: ret float [[TMP1]] 508; 509 %ltzero = fcmp olt float %x, -0.0 510 %negx = fsub nnan nsz float -0.0, %x 511 %fabs = select nnan ninf nsz i1 %ltzero, float %negx, float %x 512 ret float %fabs 513} 514 515; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 516 517define float @select_fcmp_nnan_nsz_ult_negzero(float %x) { 518; CHECK-LABEL: @select_fcmp_nnan_nsz_ult_negzero( 519; CHECK-NEXT: [[LTZERO:%.*]] = fcmp ult float [[X:%.*]], 0.000000e+00 520; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan ninf nsz float [[X]] 521; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], float [[NEGX]], float [[X]] 522; CHECK-NEXT: ret float [[FABS]] 523; 524 %ltzero = fcmp ult float %x, -0.0 525 %negx = fsub nnan ninf nsz float -0.0, %x 526 %fabs = select i1 %ltzero, float %negx, float %x 527 ret float %fabs 528} 529 530define float @select_fcmp_nnan_nsz_olt_negzero_unary_fneg(float %x) { 531; CHECK-LABEL: @select_fcmp_nnan_nsz_olt_negzero_unary_fneg( 532; CHECK-NEXT: [[LTZERO:%.*]] = fcmp olt float [[X:%.*]], 0.000000e+00 533; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan ninf nsz float [[X]] 534; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], float [[NEGX]], float [[X]] 535; CHECK-NEXT: ret float [[FABS]] 536; 537 %ltzero = fcmp olt float %x, -0.0 538 %negx = fneg nnan ninf nsz float %x 539 %fabs = select i1 %ltzero, float %negx, float %x 540 ret float %fabs 541} 542 543; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 544 545define float @select_fcmp_nnan_nsz_ult_negzero_unary_fneg(float %x) { 546; CHECK-LABEL: @select_fcmp_nnan_nsz_ult_negzero_unary_fneg( 547; CHECK-NEXT: [[LTZERO:%.*]] = fcmp ult float [[X:%.*]], 0.000000e+00 548; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan ninf nsz float [[X]] 549; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], float [[NEGX]], float [[X]] 550; CHECK-NEXT: ret float [[FABS]] 551; 552 %ltzero = fcmp ult float %x, -0.0 553 %negx = fneg nnan ninf nsz float %x 554 %fabs = select i1 %ltzero, float %negx, float %x 555 ret float %fabs 556} 557 558; X <= 0.0 ? -X : X --> fabs(X) 559 560define double @select_fcmp_nnan_nsz_ole_zero(double %x) { 561; CHECK-LABEL: @select_fcmp_nnan_nsz_ole_zero( 562; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole double [[X:%.*]], 0.000000e+00 563; CHECK-NEXT: [[NEGX:%.*]] = fneg fast double [[X]] 564; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] 565; CHECK-NEXT: ret double [[FABS]] 566; 567 %lezero = fcmp ole double %x, 0.0 568 %negx = fsub fast double -0.0, %x 569 %fabs = select i1 %lezero, double %negx, double %x 570 ret double %fabs 571} 572 573define double @select_fast_fcmp_nnan_nsz_ole_zero(double %x) { 574; CHECK-LABEL: @select_fast_fcmp_nnan_nsz_ole_zero( 575; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.fabs.f64(double [[X:%.*]]) 576; CHECK-NEXT: ret double [[TMP1]] 577; 578 %lezero = fcmp ole double %x, 0.0 579 %negx = fsub nnan nsz double -0.0, %x 580 %fabs = select fast i1 %lezero, double %negx, double %x 581 ret double %fabs 582} 583 584; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 585 586define double @select_fcmp_nnan_nsz_ule_zero(double %x) { 587; CHECK-LABEL: @select_fcmp_nnan_nsz_ule_zero( 588; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ule double [[X:%.*]], 0.000000e+00 589; CHECK-NEXT: [[NEGX:%.*]] = fneg fast double [[X]] 590; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] 591; CHECK-NEXT: ret double [[FABS]] 592; 593 %lezero = fcmp ule double %x, 0.0 594 %negx = fsub fast double -0.0, %x 595 %fabs = select i1 %lezero, double %negx, double %x 596 ret double %fabs 597} 598 599define double @select_fcmp_nnan_nsz_ole_zero_unary_fneg(double %x) { 600; CHECK-LABEL: @select_fcmp_nnan_nsz_ole_zero_unary_fneg( 601; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole double [[X:%.*]], 0.000000e+00 602; CHECK-NEXT: [[NEGX:%.*]] = fneg fast double [[X]] 603; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] 604; CHECK-NEXT: ret double [[FABS]] 605; 606 %lezero = fcmp ole double %x, 0.0 607 %negx = fneg fast double %x 608 %fabs = select i1 %lezero, double %negx, double %x 609 ret double %fabs 610} 611 612; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 613 614define double @select_fcmp_nnan_nsz_ule_zero_unary_fneg(double %x) { 615; CHECK-LABEL: @select_fcmp_nnan_nsz_ule_zero_unary_fneg( 616; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ule double [[X:%.*]], 0.000000e+00 617; CHECK-NEXT: [[NEGX:%.*]] = fneg fast double [[X]] 618; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] 619; CHECK-NEXT: ret double [[FABS]] 620; 621 %lezero = fcmp ule double %x, 0.0 622 %negx = fneg fast double %x 623 %fabs = select i1 %lezero, double %negx, double %x 624 ret double %fabs 625} 626 627; X <= -0.0 ? -X : X --> fabs(X) 628 629define float @select_fcmp_nnan_nsz_ole_negzero(float %x) { 630; CHECK-LABEL: @select_fcmp_nnan_nsz_ole_negzero( 631; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole float [[X:%.*]], 0.000000e+00 632; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz float [[X]] 633; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], float [[NEGX]], float [[X]] 634; CHECK-NEXT: ret float [[FABS]] 635; 636 %lezero = fcmp ole float %x, -0.0 637 %negx = fsub nnan nsz float -0.0, %x 638 %fabs = select i1 %lezero, float %negx, float %x 639 ret float %fabs 640} 641 642define float @select_nnan_nsz_fcmp_nnan_nsz_ole_negzero(float %x) { 643; CHECK-LABEL: @select_nnan_nsz_fcmp_nnan_nsz_ole_negzero( 644; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz float @llvm.fabs.f32(float [[X:%.*]]) 645; CHECK-NEXT: ret float [[TMP1]] 646; 647 %lezero = fcmp ole float %x, -0.0 648 %negx = fsub nnan nsz float -0.0, %x 649 %fabs = select nnan nsz i1 %lezero, float %negx, float %x 650 ret float %fabs 651} 652 653; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 654 655define float @select_fcmp_nnan_nsz_ule_negzero(float %x) { 656; CHECK-LABEL: @select_fcmp_nnan_nsz_ule_negzero( 657; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ule float [[X:%.*]], 0.000000e+00 658; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz float [[X]] 659; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], float [[NEGX]], float [[X]] 660; CHECK-NEXT: ret float [[FABS]] 661; 662 %lezero = fcmp ule float %x, -0.0 663 %negx = fsub nnan nsz float -0.0, %x 664 %fabs = select i1 %lezero, float %negx, float %x 665 ret float %fabs 666} 667 668define float @select_fcmp_nnan_nsz_ole_negzero_unary_fneg(float %x) { 669; CHECK-LABEL: @select_fcmp_nnan_nsz_ole_negzero_unary_fneg( 670; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole float [[X:%.*]], 0.000000e+00 671; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz float [[X]] 672; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], float [[NEGX]], float [[X]] 673; CHECK-NEXT: ret float [[FABS]] 674; 675 %lezero = fcmp ole float %x, -0.0 676 %negx = fneg nnan nsz float %x 677 %fabs = select i1 %lezero, float %negx, float %x 678 ret float %fabs 679} 680 681; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 682 683define float @select_fcmp_nnan_nsz_ule_negzero_unary_fneg(float %x) { 684; CHECK-LABEL: @select_fcmp_nnan_nsz_ule_negzero_unary_fneg( 685; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ule float [[X:%.*]], 0.000000e+00 686; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz float [[X]] 687; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], float [[NEGX]], float [[X]] 688; CHECK-NEXT: ret float [[FABS]] 689; 690 %lezero = fcmp ule float %x, -0.0 691 %negx = fneg nnan nsz float %x 692 %fabs = select i1 %lezero, float %negx, float %x 693 ret float %fabs 694} 695 696; X > 0.0 ? X : (0.0 - X) --> fabs(X) 697 698define <2 x float> @select_fcmp_nnan_nsz_ogt_zero(<2 x float> %x) { 699; CHECK-LABEL: @select_fcmp_nnan_nsz_ogt_zero( 700; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ogt <2 x float> [[X:%.*]], zeroinitializer 701; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz arcp <2 x float> [[X]] 702; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GTZERO]], <2 x float> [[X]], <2 x float> [[NEGX]] 703; CHECK-NEXT: ret <2 x float> [[FABS]] 704; 705 %gtzero = fcmp ogt <2 x float> %x, zeroinitializer 706 %negx = fsub nnan nsz arcp <2 x float> <float -0.0, float -0.0>, %x 707 %fabs = select <2 x i1> %gtzero, <2 x float> %x, <2 x float> %negx 708 ret <2 x float> %fabs 709} 710 711; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 712 713define <2 x float> @select_fcmp_nnan_nsz_ugt_zero(<2 x float> %x) { 714; CHECK-LABEL: @select_fcmp_nnan_nsz_ugt_zero( 715; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ugt <2 x float> [[X:%.*]], zeroinitializer 716; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz arcp <2 x float> [[X]] 717; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GTZERO]], <2 x float> [[X]], <2 x float> [[NEGX]] 718; CHECK-NEXT: ret <2 x float> [[FABS]] 719; 720 %gtzero = fcmp ugt <2 x float> %x, zeroinitializer 721 %negx = fsub nnan nsz arcp <2 x float> <float -0.0, float -0.0>, %x 722 %fabs = select <2 x i1> %gtzero, <2 x float> %x, <2 x float> %negx 723 ret <2 x float> %fabs 724} 725 726define <2 x float> @select_fcmp_nnan_nsz_ogt_zero_unary_fneg(<2 x float> %x) { 727; CHECK-LABEL: @select_fcmp_nnan_nsz_ogt_zero_unary_fneg( 728; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ogt <2 x float> [[X:%.*]], zeroinitializer 729; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz arcp <2 x float> [[X]] 730; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GTZERO]], <2 x float> [[X]], <2 x float> [[NEGX]] 731; CHECK-NEXT: ret <2 x float> [[FABS]] 732; 733 %gtzero = fcmp ogt <2 x float> %x, zeroinitializer 734 %negx = fneg nnan nsz arcp <2 x float> %x 735 %fabs = select <2 x i1> %gtzero, <2 x float> %x, <2 x float> %negx 736 ret <2 x float> %fabs 737} 738 739; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 740 741define <2 x float> @select_fcmp_nnan_nsz_ugt_zero_unary_fneg(<2 x float> %x) { 742; CHECK-LABEL: @select_fcmp_nnan_nsz_ugt_zero_unary_fneg( 743; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ugt <2 x float> [[X:%.*]], zeroinitializer 744; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz arcp <2 x float> [[X]] 745; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GTZERO]], <2 x float> [[X]], <2 x float> [[NEGX]] 746; CHECK-NEXT: ret <2 x float> [[FABS]] 747; 748 %gtzero = fcmp ugt <2 x float> %x, zeroinitializer 749 %negx = fneg nnan nsz arcp <2 x float> %x 750 %fabs = select <2 x i1> %gtzero, <2 x float> %x, <2 x float> %negx 751 ret <2 x float> %fabs 752} 753 754; X > -0.0 ? X : (0.0 - X) --> fabs(X) 755 756define half @select_fcmp_nnan_nsz_ogt_negzero(half %x) { 757; CHECK-LABEL: @select_fcmp_nnan_nsz_ogt_negzero( 758; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ogt half [[X:%.*]], 0xH0000 759; CHECK-NEXT: [[NEGX:%.*]] = fneg fast half [[X]] 760; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]] 761; CHECK-NEXT: ret half [[FABS]] 762; 763 %gtzero = fcmp ogt half %x, -0.0 764 %negx = fsub fast half 0.0, %x 765 %fabs = select i1 %gtzero, half %x, half %negx 766 ret half %fabs 767} 768 769; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 770 771define half @select_fcmp_nnan_nsz_ugt_negzero(half %x) { 772; CHECK-LABEL: @select_fcmp_nnan_nsz_ugt_negzero( 773; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ugt half [[X:%.*]], 0xH0000 774; CHECK-NEXT: [[NEGX:%.*]] = fneg fast half [[X]] 775; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]] 776; CHECK-NEXT: ret half [[FABS]] 777; 778 %gtzero = fcmp ugt half %x, -0.0 779 %negx = fsub fast half 0.0, %x 780 %fabs = select i1 %gtzero, half %x, half %negx 781 ret half %fabs 782} 783 784; X > 0.0 ? X : (0.0 - X) --> fabs(X) 785 786define <2 x double> @select_fcmp_nnan_nsz_oge_zero(<2 x double> %x) { 787; CHECK-LABEL: @select_fcmp_nnan_nsz_oge_zero( 788; CHECK-NEXT: [[GEZERO:%.*]] = fcmp oge <2 x double> [[X:%.*]], zeroinitializer 789; CHECK-NEXT: [[NEGX:%.*]] = fneg reassoc nnan nsz <2 x double> [[X]] 790; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GEZERO]], <2 x double> [[X]], <2 x double> [[NEGX]] 791; CHECK-NEXT: ret <2 x double> [[FABS]] 792; 793 %gezero = fcmp oge <2 x double> %x, zeroinitializer 794 %negx = fsub nnan nsz reassoc <2 x double> <double -0.0, double -0.0>, %x 795 %fabs = select <2 x i1> %gezero, <2 x double> %x, <2 x double> %negx 796 ret <2 x double> %fabs 797} 798 799; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 800 801define <2 x double> @select_fcmp_nnan_nsz_uge_zero(<2 x double> %x) { 802; CHECK-LABEL: @select_fcmp_nnan_nsz_uge_zero( 803; CHECK-NEXT: [[GEZERO:%.*]] = fcmp uge <2 x double> [[X:%.*]], zeroinitializer 804; CHECK-NEXT: [[NEGX:%.*]] = fneg reassoc nnan nsz <2 x double> [[X]] 805; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GEZERO]], <2 x double> [[X]], <2 x double> [[NEGX]] 806; CHECK-NEXT: ret <2 x double> [[FABS]] 807; 808 %gezero = fcmp uge <2 x double> %x, zeroinitializer 809 %negx = fsub nnan nsz reassoc <2 x double> <double -0.0, double -0.0>, %x 810 %fabs = select <2 x i1> %gezero, <2 x double> %x, <2 x double> %negx 811 ret <2 x double> %fabs 812} 813 814define <2 x double> @select_fcmp_nnan_nsz_oge_zero_unary_fneg(<2 x double> %x) { 815; CHECK-LABEL: @select_fcmp_nnan_nsz_oge_zero_unary_fneg( 816; CHECK-NEXT: [[GEZERO:%.*]] = fcmp oge <2 x double> [[X:%.*]], zeroinitializer 817; CHECK-NEXT: [[NEGX:%.*]] = fneg reassoc nnan nsz <2 x double> [[X]] 818; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GEZERO]], <2 x double> [[X]], <2 x double> [[NEGX]] 819; CHECK-NEXT: ret <2 x double> [[FABS]] 820; 821 %gezero = fcmp oge <2 x double> %x, zeroinitializer 822 %negx = fneg nnan nsz reassoc <2 x double> %x 823 %fabs = select <2 x i1> %gezero, <2 x double> %x, <2 x double> %negx 824 ret <2 x double> %fabs 825} 826 827; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 828 829define <2 x double> @select_fcmp_nnan_nsz_uge_zero_unary_fneg(<2 x double> %x) { 830; CHECK-LABEL: @select_fcmp_nnan_nsz_uge_zero_unary_fneg( 831; CHECK-NEXT: [[GEZERO:%.*]] = fcmp uge <2 x double> [[X:%.*]], zeroinitializer 832; CHECK-NEXT: [[NEGX:%.*]] = fneg reassoc nnan nsz <2 x double> [[X]] 833; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GEZERO]], <2 x double> [[X]], <2 x double> [[NEGX]] 834; CHECK-NEXT: ret <2 x double> [[FABS]] 835; 836 %gezero = fcmp uge <2 x double> %x, zeroinitializer 837 %negx = fneg nnan nsz reassoc <2 x double> %x 838 %fabs = select <2 x i1> %gezero, <2 x double> %x, <2 x double> %negx 839 ret <2 x double> %fabs 840} 841 842; X > -0.0 ? X : (0.0 - X) --> fabs(X) 843 844define half @select_fcmp_nnan_nsz_oge_negzero(half %x) { 845; CHECK-LABEL: @select_fcmp_nnan_nsz_oge_negzero( 846; CHECK-NEXT: [[GEZERO:%.*]] = fcmp oge half [[X:%.*]], 0xH0000 847; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz half [[X]] 848; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GEZERO]], half [[X]], half [[NEGX]] 849; CHECK-NEXT: ret half [[FABS]] 850; 851 %gezero = fcmp oge half %x, -0.0 852 %negx = fsub nnan nsz half -0.0, %x 853 %fabs = select i1 %gezero, half %x, half %negx 854 ret half %fabs 855} 856 857; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 858 859define half @select_fcmp_nnan_nsz_uge_negzero(half %x) { 860; CHECK-LABEL: @select_fcmp_nnan_nsz_uge_negzero( 861; CHECK-NEXT: [[GEZERO:%.*]] = fcmp uge half [[X:%.*]], 0xH0000 862; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz half [[X]] 863; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GEZERO]], half [[X]], half [[NEGX]] 864; CHECK-NEXT: ret half [[FABS]] 865; 866 %gezero = fcmp uge half %x, -0.0 867 %negx = fsub nnan nsz half -0.0, %x 868 %fabs = select i1 %gezero, half %x, half %negx 869 ret half %fabs 870} 871 872define half @select_fcmp_nnan_nsz_oge_negzero_unary_fneg(half %x) { 873; CHECK-LABEL: @select_fcmp_nnan_nsz_oge_negzero_unary_fneg( 874; CHECK-NEXT: [[GEZERO:%.*]] = fcmp oge half [[X:%.*]], 0xH0000 875; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz half [[X]] 876; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GEZERO]], half [[X]], half [[NEGX]] 877; CHECK-NEXT: ret half [[FABS]] 878; 879 %gezero = fcmp oge half %x, -0.0 880 %negx = fneg nnan nsz half %x 881 %fabs = select i1 %gezero, half %x, half %negx 882 ret half %fabs 883} 884 885; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. 886 887define half @select_fcmp_nnan_nsz_uge_negzero_unary_fneg(half %x) { 888; CHECK-LABEL: @select_fcmp_nnan_nsz_uge_negzero_unary_fneg( 889; CHECK-NEXT: [[GEZERO:%.*]] = fcmp uge half [[X:%.*]], 0xH0000 890; CHECK-NEXT: [[NEGX:%.*]] = fneg nnan nsz half [[X]] 891; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GEZERO]], half [[X]], half [[NEGX]] 892; CHECK-NEXT: ret half [[FABS]] 893; 894 %gezero = fcmp uge half %x, -0.0 895 %negx = fneg nnan nsz half %x 896 %fabs = select i1 %gezero, half %x, half %negx 897 ret half %fabs 898} 899 900define float @select_fneg(i1 %c, float %x) { 901; CHECK-LABEL: @select_fneg( 902; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]]) 903; CHECK-NEXT: ret float [[FABS]] 904; 905 %n = fneg float %x 906 %s = select i1 %c, float %n, float %x 907 %fabs = call float @llvm.fabs.f32(float %s) 908 ret float %fabs 909} 910 911define float @select_fneg_use1(i1 %c, float %x) { 912; CHECK-LABEL: @select_fneg_use1( 913; CHECK-NEXT: [[N:%.*]] = fneg float [[X:%.*]] 914; CHECK-NEXT: call void @use(float [[N]]) 915; CHECK-NEXT: [[FABS:%.*]] = call fast float @llvm.fabs.f32(float [[X]]) 916; CHECK-NEXT: ret float [[FABS]] 917; 918 %n = fneg float %x 919 call void @use(float %n) 920 %s = select i1 %c, float %x, float %n 921 %fabs = call fast float @llvm.fabs.f32(float %s) 922 ret float %fabs 923} 924 925define float @select_fneg_use2(i1 %c, float %x) { 926; CHECK-LABEL: @select_fneg_use2( 927; CHECK-NEXT: [[N:%.*]] = fneg arcp float [[X:%.*]] 928; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], float [[N]], float [[X]] 929; CHECK-NEXT: call void @use(float [[S]]) 930; CHECK-NEXT: [[FABS:%.*]] = call nnan nsz float @llvm.fabs.f32(float [[X]]) 931; CHECK-NEXT: ret float [[FABS]] 932; 933 %n = fneg arcp float %x 934 %s = select i1 %c, float %n, float %x 935 call void @use(float %s) 936 %fabs = call nnan nsz float @llvm.fabs.f32(float %s) 937 ret float %fabs 938} 939 940define <2 x float> @select_fneg_vec(<2 x i1> %c, <2 x float> %x) { 941; CHECK-LABEL: @select_fneg_vec( 942; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]]) 943; CHECK-NEXT: ret <2 x float> [[FABS]] 944; 945 %n = fneg <2 x float> %x 946 %s = select fast <2 x i1> %c, <2 x float> %x, <2 x float> %n 947 %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %s) 948 ret <2 x float> %fabs 949} 950