1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s 3 4; Test against PR36600: https://bugs.llvm.org/show_bug.cgi?id=36600 5; This is not fabs. If X = -0.0, it should return -0.0 not 0.0. 6 7define double @not_fabs(double %x) #0 { 8; CHECK-LABEL: not_fabs: 9; CHECK: // %bb.0: 10; CHECK-NEXT: fneg d1, d0 11; CHECK-NEXT: fcmp d0, #0.0 12; CHECK-NEXT: fcsel d0, d1, d0, le 13; CHECK-NEXT: ret 14 %cmp = fcmp nnan ole double %x, 0.0 15 %sub = fsub nnan double -0.0, %x 16 %cond = select i1 %cmp, double %sub, double %x 17 ret double %cond 18} 19 20; Try again with different type, predicate, and compare constant. 21 22define float @still_not_fabs(float %x) #0 { 23; CHECK-LABEL: still_not_fabs: 24; CHECK: // %bb.0: 25; CHECK-NEXT: mov w8, #-2147483648 26; CHECK-NEXT: fmov s2, w8 27; CHECK-NEXT: fneg s1, s0 28; CHECK-NEXT: fcmp s0, s2 29; CHECK-NEXT: fcsel s0, s0, s1, ge 30; CHECK-NEXT: ret 31 %cmp = fcmp nnan oge float %x, -0.0 32 %sub = fsub nnan float -0.0, %x 33 %cond = select i1 %cmp, float %x, float %sub 34 ret float %cond 35} 36 37define float @nabsf(float %a) { 38; CHECK-LABEL: nabsf: 39; CHECK: // %bb.0: 40; CHECK-NEXT: fabs s0, s0 41; CHECK-NEXT: fneg s0, s0 42; CHECK-NEXT: ret 43 %conv = bitcast float %a to i32 44 %and = or i32 %conv, -2147483648 45 %conv1 = bitcast i32 %and to float 46 ret float %conv1 47} 48 49define double @nabsd(double %a) { 50; CHECK-LABEL: nabsd: 51; CHECK: // %bb.0: 52; CHECK-NEXT: fabs d0, d0 53; CHECK-NEXT: fneg d0, d0 54; CHECK-NEXT: ret 55 %conv = bitcast double %a to i64 56 %and = or i64 %conv, -9223372036854775808 57 %conv1 = bitcast i64 %and to double 58 ret double %conv1 59} 60 61define <4 x float> @nabsv4f32(<4 x float> %a) { 62; CHECK-LABEL: nabsv4f32: 63; CHECK: // %bb.0: 64; CHECK-NEXT: orr v0.4s, #128, lsl #24 65; CHECK-NEXT: ret 66 %conv = bitcast <4 x float> %a to <4 x i32> 67 %and = or <4 x i32> %conv, <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648> 68 %conv1 = bitcast <4 x i32> %and to <4 x float> 69 ret <4 x float> %conv1 70} 71 72define <2 x double> @nabsv2d64(<2 x double> %a) { 73; CHECK-LABEL: nabsv2d64: 74; CHECK: // %bb.0: 75; CHECK-NEXT: mov x8, #-9223372036854775808 76; CHECK-NEXT: dup v1.2d, x8 77; CHECK-NEXT: orr v0.16b, v0.16b, v1.16b 78; CHECK-NEXT: ret 79 %conv = bitcast <2 x double> %a to <2 x i64> 80 %and = or <2 x i64> %conv, <i64 -9223372036854775808, i64 -9223372036854775808> 81 %conv1 = bitcast <2 x i64> %and to <2 x double> 82 ret <2 x double> %conv1 83} 84 85attributes #0 = { "no-nans-fp-math"="true" } 86 87