1; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=GCN %s 2; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=VI -check-prefix=GCN %s 3 4; GCN-LABEL: {{^}}mac_vvv: 5; GCN: buffer_load_dword [[A:v[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0{{$}} 6; GCN: buffer_load_dword [[B:v[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0 offset:4 7; GCN: buffer_load_dword [[C:v[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0 offset:8 8; GCN: v_mac_f32_e32 [[C]], [[B]], [[A]] 9; GCN: buffer_store_dword [[C]] 10define void @mac_vvv(float addrspace(1)* %out, float addrspace(1)* %in) { 11entry: 12 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 13 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 14 15 %a = load float, float addrspace(1)* %in 16 %b = load float, float addrspace(1)* %b_ptr 17 %c = load float, float addrspace(1)* %c_ptr 18 19 %tmp0 = fmul float %a, %b 20 %tmp1 = fadd float %tmp0, %c 21 store float %tmp1, float addrspace(1)* %out 22 ret void 23} 24 25; GCN-LABEL: {{^}}mad_inline_sgpr_inline: 26; GCN-NOT: v_mac_f32 27; GCN: v_mad_f32 v{{[0-9]}}, 0.5, s{{[0-9]+}}, 0.5 28define void @mad_inline_sgpr_inline(float addrspace(1)* %out, float %in) { 29entry: 30 %tmp0 = fmul float 0.5, %in 31 %tmp1 = fadd float %tmp0, 0.5 32 store float %tmp1, float addrspace(1)* %out 33 ret void 34} 35 36; GCN-LABEL: {{^}}mad_vvs: 37; GCN-NOT: v_mac_f32 38; GCN: v_mad_f32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, s{{[0-9]+}} 39define void @mad_vvs(float addrspace(1)* %out, float addrspace(1)* %in, float %c) { 40entry: 41 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 42 43 %a = load float, float addrspace(1)* %in 44 %b = load float, float addrspace(1)* %b_ptr 45 46 %tmp0 = fmul float %a, %b 47 %tmp1 = fadd float %tmp0, %c 48 store float %tmp1, float addrspace(1)* %out 49 ret void 50} 51 52; GCN-LABEL: {{^}}mac_ssv: 53; GCN: v_mac_f32_e64 v{{[0-9]+}}, s{{[0-9]+}}, s{{[0-9]+}} 54define void @mac_ssv(float addrspace(1)* %out, float addrspace(1)* %in, float %a) { 55entry: 56 %c = load float, float addrspace(1)* %in 57 58 %tmp0 = fmul float %a, %a 59 %tmp1 = fadd float %tmp0, %c 60 store float %tmp1, float addrspace(1)* %out 61 ret void 62} 63 64; GCN-LABEL: {{^}}mac_mad_same_add: 65; GCN: v_mad_f32 v{{[0-9]}}, v{{[0-9]+}}, v{{[0-9]+}}, [[ADD:v[0-9]+]] 66; GCN: v_mac_f32_e32 [[ADD]], v{{[0-9]+}}, v{{[0-9]+}} 67define void @mac_mad_same_add(float addrspace(1)* %out, float addrspace(1)* %in) { 68entry: 69 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 70 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 71 %d_ptr = getelementptr float, float addrspace(1)* %in, i32 3 72 %e_ptr = getelementptr float, float addrspace(1)* %in, i32 4 73 74 %a = load float, float addrspace(1)* %in 75 %b = load float, float addrspace(1)* %b_ptr 76 %c = load float, float addrspace(1)* %c_ptr 77 %d = load float, float addrspace(1)* %d_ptr 78 %e = load float, float addrspace(1)* %e_ptr 79 80 %tmp0 = fmul float %a, %b 81 %tmp1 = fadd float %tmp0, %c 82 83 %tmp2 = fmul float %d, %e 84 %tmp3 = fadd float %tmp2, %c 85 86 %out1 = getelementptr float, float addrspace(1)* %out, i32 1 87 store float %tmp1, float addrspace(1)* %out 88 store float %tmp3, float addrspace(1)* %out1 89 ret void 90} 91 92; There is no advantage to using v_mac when one of the operands is negated 93; and v_mad accepts more operand types. 94 95; GCN-LABEL: {{^}}mad_neg_src0: 96; GCN-NOT: v_mac_f32 97; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}} 98define void @mad_neg_src0(float addrspace(1)* %out, float addrspace(1)* %in) #0 { 99entry: 100 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 101 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 102 103 %a = load float, float addrspace(1)* %in 104 %b = load float, float addrspace(1)* %b_ptr 105 %c = load float, float addrspace(1)* %c_ptr 106 107 %neg_a = fsub float 0.0, %a 108 %tmp0 = fmul float %neg_a, %b 109 %tmp1 = fadd float %tmp0, %c 110 111 store float %tmp1, float addrspace(1)* %out 112 ret void 113} 114 115; GCN-LABEL: {{^}}mad_neg_src1: 116; GCN-NOT: v_mac_f32 117; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}} 118define void @mad_neg_src1(float addrspace(1)* %out, float addrspace(1)* %in) #0 { 119entry: 120 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 121 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 122 123 %a = load float, float addrspace(1)* %in 124 %b = load float, float addrspace(1)* %b_ptr 125 %c = load float, float addrspace(1)* %c_ptr 126 127 %neg_b = fsub float 0.0, %b 128 %tmp0 = fmul float %a, %neg_b 129 %tmp1 = fadd float %tmp0, %c 130 131 store float %tmp1, float addrspace(1)* %out 132 ret void 133} 134 135; GCN-LABEL: {{^}}mad_neg_src2: 136; GCN-NOT: v_mac 137; GCN: v_mad_f32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, -v{{[-0-9]}} 138define void @mad_neg_src2(float addrspace(1)* %out, float addrspace(1)* %in) #0 { 139entry: 140 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 141 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 142 143 %a = load float, float addrspace(1)* %in 144 %b = load float, float addrspace(1)* %b_ptr 145 %c = load float, float addrspace(1)* %c_ptr 146 147 %neg_c = fsub float 0.0, %c 148 %tmp0 = fmul float %a, %b 149 %tmp1 = fadd float %tmp0, %neg_c 150 151 store float %tmp1, float addrspace(1)* %out 152 ret void 153} 154 155attributes #0 = { "true" "unsafe-fp-math"="true" } 156