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]+]], off, s[{{[0-9]+:[0-9]+}}], 0{{$}} 6; GCN: buffer_load_dword [[B:v[0-9]+]], off, s[{{[0-9]+:[0-9]+}}], 0 offset:4 7; GCN: buffer_load_dword [[C:v[0-9]+]], off, 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) #0 { 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 volatile float, float addrspace(1)* %in 16 %b = load volatile float, float addrspace(1)* %b_ptr 17 %c = load volatile 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]}}, s{{[0-9]+}}, 0.5, 0.5 28define void @mad_inline_sgpr_inline(float addrspace(1)* %out, float %in) #0 { 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) #0 { 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) #0 { 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) #0 { 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 volatile float, float addrspace(1)* %in 75 %b = load volatile float, float addrspace(1)* %b_ptr 76 %c = load volatile float, float addrspace(1)* %c_ptr 77 %d = load volatile float, float addrspace(1)* %d_ptr 78 %e = load volatile 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: {{^}}unsafe_mad_sub0_src0: 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 @unsafe_mad_sub0_src0(float addrspace(1)* %out, float addrspace(1)* %in) #1 { 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_a = fsub float 0.0, %a 128 %tmp0 = fmul float %neg_a, %b 129 %tmp1 = fadd float %tmp0, %c 130 131 store float %tmp1, float addrspace(1)* %out 132 ret void 133} 134 135; GCN-LABEL: {{^}}safe_mad_sub0_src0: 136; GCN: v_sub_f32_e32 [[SUB0:v[0-9]+]], 0, 137; GCN: v_mac_f32_e32 v{{[0-9]+}}, v{{[0-9]+}}, [[SUB0]] 138define void @safe_mad_sub0_src0(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_a = fsub float 0.0, %a 148 %tmp0 = fmul float %neg_a, %b 149 %tmp1 = fadd float %tmp0, %c 150 151 store float %tmp1, float addrspace(1)* %out 152 ret void 153} 154 155; GCN-LABEL: {{^}}mad_neg_src1: 156; GCN-NOT: v_mac_f32 157; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}} 158define void @mad_neg_src1(float addrspace(1)* %out, float addrspace(1)* %in) #0 { 159entry: 160 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 161 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 162 163 %a = load float, float addrspace(1)* %in 164 %b = load float, float addrspace(1)* %b_ptr 165 %c = load float, float addrspace(1)* %c_ptr 166 167 %neg_b = fsub float -0.0, %b 168 %tmp0 = fmul float %a, %neg_b 169 %tmp1 = fadd float %tmp0, %c 170 171 store float %tmp1, float addrspace(1)* %out 172 ret void 173} 174 175; GCN-LABEL: {{^}}unsafe_mad_sub0_src1: 176; GCN-NOT: v_mac_f32 177; GCN: v_mad_f32 v{{[0-9]+}}, -v{{[0-9]+}}, v{{[0-9]+}}, v{{[-0-9]}} 178define void @unsafe_mad_sub0_src1(float addrspace(1)* %out, float addrspace(1)* %in) #1 { 179entry: 180 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 181 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 182 183 %a = load float, float addrspace(1)* %in 184 %b = load float, float addrspace(1)* %b_ptr 185 %c = load float, float addrspace(1)* %c_ptr 186 187 %neg_b = fsub float 0.0, %b 188 %tmp0 = fmul float %a, %neg_b 189 %tmp1 = fadd float %tmp0, %c 190 191 store float %tmp1, float addrspace(1)* %out 192 ret void 193} 194 195; GCN-LABEL: {{^}}mad_neg_src2: 196; GCN-NOT: v_mac 197; GCN: v_mad_f32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}, -v{{[-0-9]}} 198define void @mad_neg_src2(float addrspace(1)* %out, float addrspace(1)* %in) #0 { 199entry: 200 %b_ptr = getelementptr float, float addrspace(1)* %in, i32 1 201 %c_ptr = getelementptr float, float addrspace(1)* %in, i32 2 202 203 %a = load float, float addrspace(1)* %in 204 %b = load float, float addrspace(1)* %b_ptr 205 %c = load float, float addrspace(1)* %c_ptr 206 207 %neg_c = fsub float -0.0, %c 208 %tmp0 = fmul float %a, %b 209 %tmp1 = fadd float %tmp0, %neg_c 210 211 store float %tmp1, float addrspace(1)* %out 212 ret void 213} 214 215attributes #0 = { nounwind "unsafe-fp-math"="false" } 216attributes #1 = { nounwind "unsafe-fp-math"="true" } 217