1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=FUNC %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=FUNC %s 3*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=R600 -check-prefix=FUNC %s 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker; Run with unsafe-fp-math to make sure nothing tries to turn this into 1 / rsqrt(x) 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}v_safe_fsqrt_f32: 9*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 {{v[0-9]+, v[0-9]+}} 10*9880d681SAndroid Build Coastguard Workerdefine void @v_safe_fsqrt_f32(float addrspace(1)* %out, float addrspace(1)* %in) #1 { 11*9880d681SAndroid Build Coastguard Worker %r0 = load float, float addrspace(1)* %in 12*9880d681SAndroid Build Coastguard Worker %r1 = call float @llvm.sqrt.f32(float %r0) 13*9880d681SAndroid Build Coastguard Worker store float %r1, float addrspace(1)* %out 14*9880d681SAndroid Build Coastguard Worker ret void 15*9880d681SAndroid Build Coastguard Worker} 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}v_unsafe_fsqrt_f32: 18*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 {{v[0-9]+, v[0-9]+}} 19*9880d681SAndroid Build Coastguard Workerdefine void @v_unsafe_fsqrt_f32(float addrspace(1)* %out, float addrspace(1)* %in) #2 { 20*9880d681SAndroid Build Coastguard Worker %r0 = load float, float addrspace(1)* %in 21*9880d681SAndroid Build Coastguard Worker %r1 = call float @llvm.sqrt.f32(float %r0) 22*9880d681SAndroid Build Coastguard Worker store float %r1, float addrspace(1)* %out 23*9880d681SAndroid Build Coastguard Worker ret void 24*9880d681SAndroid Build Coastguard Worker} 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}s_sqrt_f32: 28*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker; R600: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[2].Z 31*9880d681SAndroid Build Coastguard Worker; R600: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[2].Z, PS 32*9880d681SAndroid Build Coastguard Workerdefine void @s_sqrt_f32(float addrspace(1)* %out, float %in) #1 { 33*9880d681SAndroid Build Coastguard Workerentry: 34*9880d681SAndroid Build Coastguard Worker %fdiv = call float @llvm.sqrt.f32(float %in) 35*9880d681SAndroid Build Coastguard Worker store float %fdiv, float addrspace(1)* %out 36*9880d681SAndroid Build Coastguard Worker ret void 37*9880d681SAndroid Build Coastguard Worker} 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}s_sqrt_v2f32: 40*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 41*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[2].W 44*9880d681SAndroid Build Coastguard Worker; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[2].W, PS 45*9880d681SAndroid Build Coastguard Worker; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].X 46*9880d681SAndroid Build Coastguard Worker; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].X, PS 47*9880d681SAndroid Build Coastguard Workerdefine void @s_sqrt_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %in) #1 { 48*9880d681SAndroid Build Coastguard Workerentry: 49*9880d681SAndroid Build Coastguard Worker %fdiv = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %in) 50*9880d681SAndroid Build Coastguard Worker store <2 x float> %fdiv, <2 x float> addrspace(1)* %out 51*9880d681SAndroid Build Coastguard Worker ret void 52*9880d681SAndroid Build Coastguard Worker} 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}s_sqrt_v4f32: 55*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 56*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 57*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 58*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].Y 61*9880d681SAndroid Build Coastguard Worker; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].Y, PS 62*9880d681SAndroid Build Coastguard Worker; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].Z 63*9880d681SAndroid Build Coastguard Worker; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].Z, PS 64*9880d681SAndroid Build Coastguard Worker; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].W 65*9880d681SAndroid Build Coastguard Worker; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].W, PS 66*9880d681SAndroid Build Coastguard Worker; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[4].X 67*9880d681SAndroid Build Coastguard Worker; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[4].X, PS 68*9880d681SAndroid Build Coastguard Workerdefine void @s_sqrt_v4f32(<4 x float> addrspace(1)* %out, <4 x float> %in) #1 { 69*9880d681SAndroid Build Coastguard Workerentry: 70*9880d681SAndroid Build Coastguard Worker %fdiv = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %in) 71*9880d681SAndroid Build Coastguard Worker store <4 x float> %fdiv, <4 x float> addrspace(1)* %out 72*9880d681SAndroid Build Coastguard Worker ret void 73*9880d681SAndroid Build Coastguard Worker} 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}elim_redun_check_neg0: 76*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 77*9880d681SAndroid Build Coastguard Worker; GCN-NOT: v_cndmask 78*9880d681SAndroid Build Coastguard Workerdefine void @elim_redun_check_neg0(float addrspace(1)* %out, float %in) #1 { 79*9880d681SAndroid Build Coastguard Workerentry: 80*9880d681SAndroid Build Coastguard Worker %sqrt = call float @llvm.sqrt.f32(float %in) 81*9880d681SAndroid Build Coastguard Worker %cmp = fcmp olt float %in, -0.000000e+00 82*9880d681SAndroid Build Coastguard Worker %res = select i1 %cmp, float 0x7FF8000000000000, float %sqrt 83*9880d681SAndroid Build Coastguard Worker store float %res, float addrspace(1)* %out 84*9880d681SAndroid Build Coastguard Worker ret void 85*9880d681SAndroid Build Coastguard Worker} 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}elim_redun_check_pos0: 88*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 89*9880d681SAndroid Build Coastguard Worker; GCN-NOT: v_cndmask 90*9880d681SAndroid Build Coastguard Workerdefine void @elim_redun_check_pos0(float addrspace(1)* %out, float %in) #1 { 91*9880d681SAndroid Build Coastguard Workerentry: 92*9880d681SAndroid Build Coastguard Worker %sqrt = call float @llvm.sqrt.f32(float %in) 93*9880d681SAndroid Build Coastguard Worker %cmp = fcmp olt float %in, 0.000000e+00 94*9880d681SAndroid Build Coastguard Worker %res = select i1 %cmp, float 0x7FF8000000000000, float %sqrt 95*9880d681SAndroid Build Coastguard Worker store float %res, float addrspace(1)* %out 96*9880d681SAndroid Build Coastguard Worker ret void 97*9880d681SAndroid Build Coastguard Worker} 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}elim_redun_check_ult: 100*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 101*9880d681SAndroid Build Coastguard Worker; GCN-NOT: v_cndmask 102*9880d681SAndroid Build Coastguard Workerdefine void @elim_redun_check_ult(float addrspace(1)* %out, float %in) #1 { 103*9880d681SAndroid Build Coastguard Workerentry: 104*9880d681SAndroid Build Coastguard Worker %sqrt = call float @llvm.sqrt.f32(float %in) 105*9880d681SAndroid Build Coastguard Worker %cmp = fcmp ult float %in, -0.000000e+00 106*9880d681SAndroid Build Coastguard Worker %res = select i1 %cmp, float 0x7FF8000000000000, float %sqrt 107*9880d681SAndroid Build Coastguard Worker store float %res, float addrspace(1)* %out 108*9880d681SAndroid Build Coastguard Worker ret void 109*9880d681SAndroid Build Coastguard Worker} 110*9880d681SAndroid Build Coastguard Worker 111*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}elim_redun_check_v2: 112*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 113*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 114*9880d681SAndroid Build Coastguard Worker; GCN-NOT: v_cndmask 115*9880d681SAndroid Build Coastguard Workerdefine void @elim_redun_check_v2(<2 x float> addrspace(1)* %out, <2 x float> %in) #1 { 116*9880d681SAndroid Build Coastguard Workerentry: 117*9880d681SAndroid Build Coastguard Worker %sqrt = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %in) 118*9880d681SAndroid Build Coastguard Worker %cmp = fcmp olt <2 x float> %in, <float -0.000000e+00, float -0.000000e+00> 119*9880d681SAndroid Build Coastguard Worker %res = select <2 x i1> %cmp, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> %sqrt 120*9880d681SAndroid Build Coastguard Worker store <2 x float> %res, <2 x float> addrspace(1)* %out 121*9880d681SAndroid Build Coastguard Worker ret void 122*9880d681SAndroid Build Coastguard Worker} 123*9880d681SAndroid Build Coastguard Worker 124*9880d681SAndroid Build Coastguard Worker; FUNC-LABEL: {{^}}elim_redun_check_v2_ult 125*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 126*9880d681SAndroid Build Coastguard Worker; GCN: v_sqrt_f32_e32 127*9880d681SAndroid Build Coastguard Worker; GCN-NOT: v_cndmask 128*9880d681SAndroid Build Coastguard Workerdefine void @elim_redun_check_v2_ult(<2 x float> addrspace(1)* %out, <2 x float> %in) #1 { 129*9880d681SAndroid Build Coastguard Workerentry: 130*9880d681SAndroid Build Coastguard Worker %sqrt = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %in) 131*9880d681SAndroid Build Coastguard Worker %cmp = fcmp ult <2 x float> %in, <float -0.000000e+00, float -0.000000e+00> 132*9880d681SAndroid Build Coastguard Worker %res = select <2 x i1> %cmp, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> %sqrt 133*9880d681SAndroid Build Coastguard Worker store <2 x float> %res, <2 x float> addrspace(1)* %out 134*9880d681SAndroid Build Coastguard Worker ret void 135*9880d681SAndroid Build Coastguard Worker} 136*9880d681SAndroid Build Coastguard Worker 137*9880d681SAndroid Build Coastguard Workerdeclare float @llvm.sqrt.f32(float %in) #0 138*9880d681SAndroid Build Coastguard Workerdeclare <2 x float> @llvm.sqrt.v2f32(<2 x float> %in) #0 139*9880d681SAndroid Build Coastguard Workerdeclare <4 x float> @llvm.sqrt.v4f32(<4 x float> %in) #0 140*9880d681SAndroid Build Coastguard Worker 141*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind readnone } 142*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind "unsafe-fp-math"="false" } 143*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind "unsafe-fp-math"="true" } 144