1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s 2 3 ; Make sure (fmul (fadd x, x), c) -> (fmul x, (fmul 2.0, c)) doesn't 4 ; make add an instruction if the fadd has more than one use. 5 6 declare float @llvm.fabs.f32(float) #1 7 8 ; GCN-LABEL: {{^}}multiple_fadd_use_test: 9 ; GCN: v_max_legacy_f32_e64 [[A16:v[0-9]+]], 10 ; GCN: v_add_f32_e32 [[A17:v[0-9]+]], [[A16]], [[A16]] 11 ; GCN: v_mul_f32_e32 [[A18:v[0-9]+]], [[A17]], [[A17]] 12 ; GCN: v_mad_f32 [[A20:v[0-9]+]], -[[A18]], [[A17]], 1.0 13 ; GCN: buffer_store_dword [[A20]] 14 define void @multiple_fadd_use_test(float addrspace(1)* %out, float %x, float %y, float %z) #0 { 15 %a11 = fadd fast float %y, -1.0 16 %a12 = call float @llvm.fabs.f32(float %a11) 17 %a13 = fadd fast float %x, -1.0 18 %a14 = call float @llvm.fabs.f32(float %a13) 19 %a15 = fcmp ogt float %a12, %a14 20 %a16 = select i1 %a15, float %a12, float %a14 21 %a17 = fmul fast float %a16, 2.0 22 %a18 = fmul fast float %a17, %a17 23 %a19 = fmul fast float %a18, %a17 24 %a20 = fsub fast float 1.0, %a19 25 store float %a20, float addrspace(1)* %out 26 ret void 27 } 28 29 ; GCN-LABEL: {{^}}multiple_use_fadd_fmac 30 ; GCN-DAG: v_add_f32_e64 [[MUL2:v[0-9]+]], [[X:s[0-9]+]], s{{[0-9]+}} 31 ; GCN-DAG: v_mac_f32_e64 [[MAD:v[0-9]+]], 2.0, [[X]] 32 ; GCN-DAG: buffer_store_dword [[MUL2]] 33 ; GCN-DAG: buffer_store_dword [[MAD]] 34 ; GCN: s_endpgm 35 define void @multiple_use_fadd_fmac(float addrspace(1)* %out, float %x, float %y) #0 { 36 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 37 %mul2 = fmul fast float %x, 2.0 38 %mad = fadd fast float %mul2, %y 39 store float %mul2, float addrspace(1)* %out 40 store float %mad, float addrspace(1)* %out.gep.1 41 ret void 42 } 43 44 ; GCN-LABEL: {{^}}multiple_use_fadd_fmad: 45 ; GCN-DAG: v_add_f32_e64 [[MUL2:v[0-9]+]], |[[X:s[0-9]+]]|, |s{{[0-9]+}}| 46 ; GCN-DAG: v_mad_f32 [[MAD:v[0-9]+]], 2.0, |[[X]]|, v{{[0-9]+}} 47 ; GCN-DAG: buffer_store_dword [[MUL2]] 48 ; GCN-DAG: buffer_store_dword [[MAD]] 49 ; GCN: s_endpgm 50 define void @multiple_use_fadd_fmad(float addrspace(1)* %out, float %x, float %y) #0 { 51 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 52 %x.abs = call float @llvm.fabs.f32(float %x) 53 %mul2 = fmul fast float %x.abs, 2.0 54 %mad = fadd fast float %mul2, %y 55 store float %mul2, float addrspace(1)* %out 56 store float %mad, float addrspace(1)* %out.gep.1 57 ret void 58 } 59 60 ; GCN-LABEL: {{^}}multiple_use_fadd_multi_fmad: 61 ; GCN: v_mad_f32 {{v[0-9]+}}, 2.0, |[[X:s[0-9]+]]|, v{{[0-9]+}} 62 ; GCN: v_mad_f32 {{v[0-9]+}}, 2.0, |[[X]]|, v{{[0-9]+}} 63 define void @multiple_use_fadd_multi_fmad(float addrspace(1)* %out, float %x, float %y, float %z) #0 { 64 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 65 %x.abs = call float @llvm.fabs.f32(float %x) 66 %mul2 = fmul fast float %x.abs, 2.0 67 %mad0 = fadd fast float %mul2, %y 68 %mad1 = fadd fast float %mul2, %z 69 store float %mad0, float addrspace(1)* %out 70 store float %mad1, float addrspace(1)* %out.gep.1 71 ret void 72 } 73 74 ; GCN-LABEL: {{^}}fmul_x2_xn2: 75 ; GCN: v_mul_f32_e64 [[TMP0:v[0-9]+]], -4.0, [[X:s[0-9]+]] 76 ; GCN: v_mul_f32_e32 [[RESULT:v[0-9]+]], [[X]], [[TMP0]] 77 ; GCN: buffer_store_dword [[RESULT]] 78 define void @fmul_x2_xn2(float addrspace(1)* %out, float %x, float %y) #0 { 79 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 80 %mul2 = fmul fast float %x, 2.0 81 %muln2 = fmul fast float %x, -2.0 82 %mul = fmul fast float %mul2, %muln2 83 store float %mul, float addrspace(1)* %out 84 ret void 85 } 86 87 ; GCN-LABEL: {{^}}fmul_x2_xn3: 88 ; GCN: v_mov_b32_e32 [[K:v[0-9]+]], 0xc0c00000 89 ; GCN: v_mul_f32_e32 [[TMP0:v[0-9]+]], [[X:s[0-9]+]], [[K]] 90 ; GCN: v_mul_f32_e32 [[RESULT:v[0-9]+]], [[X]], [[TMP0]] 91 ; GCN: buffer_store_dword [[RESULT]] 92 define void @fmul_x2_xn3(float addrspace(1)* %out, float %x, float %y) #0 { 93 %out.gep.1 = getelementptr float, float addrspace(1)* %out, i32 1 94 %mul2 = fmul fast float %x, 2.0 95 %muln2 = fmul fast float %x, -3.0 96 %mul = fmul fast float %mul2, %muln2 97 store float %mul, float addrspace(1)* %out 98 ret void 99 } 100 101 attributes #0 = { nounwind "unsafe-fp-math"="true" } 102 attributes #1 = { nounwind readnone } 103