1; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s 2; XUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI %s 3 4declare i32 @llvm.r600.read.tidig.x() nounwind readnone 5declare float @llvm.fabs.f32(float) nounwind readnone 6 7; GCN-LABEL: {{^}}madmk_f32: 8; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}} 9; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4 10; GCN: v_madmk_f32_e32 {{v[0-9]+}}, [[VA]], [[VB]], 0x41200000 11define void @madmk_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { 12 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 13 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 14 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1 15 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 16 17 %a = load float, float addrspace(1)* %gep.0, align 4 18 %b = load float, float addrspace(1)* %gep.1, align 4 19 20 %mul = fmul float %a, 10.0 21 %madmk = fadd float %mul, %b 22 store float %madmk, float addrspace(1)* %out.gep, align 4 23 ret void 24} 25 26; GCN-LABEL: {{^}}madmk_2_use_f32: 27; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}} 28; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4 29; GCN-DAG: buffer_load_dword [[VC:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:8 30; GCN-DAG: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000 31; GCN-DAG: v_mac_f32_e32 [[VB]], [[VK]], [[VA]] 32; GCN-DAG: v_mac_f32_e32 [[VC]], [[VK]], [[VA]] 33; GCN: s_endpgm 34define void @madmk_2_use_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { 35 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 36 37 %in.gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 38 %in.gep.1 = getelementptr float, float addrspace(1)* %in.gep.0, i32 1 39 %in.gep.2 = getelementptr float, float addrspace(1)* %in.gep.0, i32 2 40 41 %out.gep.0 = getelementptr float, float addrspace(1)* %out, i32 %tid 42 %out.gep.1 = getelementptr float, float addrspace(1)* %in.gep.0, i32 1 43 44 %a = load float, float addrspace(1)* %in.gep.0, align 4 45 %b = load float, float addrspace(1)* %in.gep.1, align 4 46 %c = load float, float addrspace(1)* %in.gep.2, align 4 47 48 %mul0 = fmul float %a, 10.0 49 %mul1 = fmul float %a, 10.0 50 %madmk0 = fadd float %mul0, %b 51 %madmk1 = fadd float %mul1, %c 52 53 store float %madmk0, float addrspace(1)* %out.gep.0, align 4 54 store float %madmk1, float addrspace(1)* %out.gep.1, align 4 55 ret void 56} 57 58; We don't get any benefit if the constant is an inline immediate. 59; GCN-LABEL: {{^}}madmk_inline_imm_f32: 60; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}} 61; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4 62; GCN: v_mac_f32_e32 [[VB]], 4.0, [[VA]] 63define void @madmk_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { 64 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 65 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 66 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1 67 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 68 69 %a = load float, float addrspace(1)* %gep.0, align 4 70 %b = load float, float addrspace(1)* %gep.1, align 4 71 72 %mul = fmul float %a, 4.0 73 %madmk = fadd float %mul, %b 74 store float %madmk, float addrspace(1)* %out.gep, align 4 75 ret void 76} 77 78; GCN-LABEL: {{^}}s_s_madmk_f32: 79; GCN-NOT: v_madmk_f32 80; GCN: v_mac_f32_e32 81; GCN: s_endpgm 82define void @s_s_madmk_f32(float addrspace(1)* noalias %out, float %a, float %b) nounwind { 83 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 84 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 85 86 %mul = fmul float %a, 10.0 87 %madmk = fadd float %mul, %b 88 store float %madmk, float addrspace(1)* %out.gep, align 4 89 ret void 90} 91 92; GCN-LABEL: {{^}}v_s_madmk_f32: 93; GCN-NOT: v_madmk_f32 94; GCN: v_mad_f32 95; GCN: s_endpgm 96define void @v_s_madmk_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in, float %b) nounwind { 97 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 98 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 99 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 100 %a = load float, float addrspace(1)* %gep.0, align 4 101 102 %mul = fmul float %a, 10.0 103 %madmk = fadd float %mul, %b 104 store float %madmk, float addrspace(1)* %out.gep, align 4 105 ret void 106} 107 108; GCN-LABEL: {{^}}scalar_vector_madmk_f32: 109; GCN-NOT: v_madmk_f32 110; GCN: v_mac_f32_e32 111; GCN: s_endpgm 112define void @scalar_vector_madmk_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in, float %a) nounwind { 113 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 114 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 115 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 116 %b = load float, float addrspace(1)* %gep.0, align 4 117 118 %mul = fmul float %a, 10.0 119 %madmk = fadd float %mul, %b 120 store float %madmk, float addrspace(1)* %out.gep, align 4 121 ret void 122} 123 124; GCN-LABEL: {{^}}no_madmk_src0_modifier_f32: 125; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}} 126; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4 127; GCN: v_mad_f32 {{v[0-9]+}}, |{{v[0-9]+}}|, {{v[0-9]+}}, {{[sv][0-9]+}} 128define void @no_madmk_src0_modifier_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { 129 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 130 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 131 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1 132 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 133 134 %a = load float, float addrspace(1)* %gep.0, align 4 135 %b = load float, float addrspace(1)* %gep.1, align 4 136 137 %a.fabs = call float @llvm.fabs.f32(float %a) nounwind readnone 138 139 %mul = fmul float %a.fabs, 10.0 140 %madmk = fadd float %mul, %b 141 store float %madmk, float addrspace(1)* %out.gep, align 4 142 ret void 143} 144 145; GCN-LABEL: {{^}}no_madmk_src2_modifier_f32: 146; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}} 147; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4 148; GCN: v_mad_f32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, |{{[sv][0-9]+}}| 149define void @no_madmk_src2_modifier_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { 150 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 151 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 152 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1 153 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 154 155 %a = load float, float addrspace(1)* %gep.0, align 4 156 %b = load float, float addrspace(1)* %gep.1, align 4 157 158 %b.fabs = call float @llvm.fabs.f32(float %b) nounwind readnone 159 160 %mul = fmul float %a, 10.0 161 %madmk = fadd float %mul, %b.fabs 162 store float %madmk, float addrspace(1)* %out.gep, align 4 163 ret void 164} 165 166; GCN-LABEL: {{^}}madmk_add_inline_imm_f32: 167; GCN: buffer_load_dword [[A:v[0-9]+]] 168; GCN: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000 169; GCN: v_mad_f32 {{v[0-9]+}}, [[VK]], [[A]], 2.0 170define void @madmk_add_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind { 171 %tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone 172 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid 173 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid 174 175 %a = load float, float addrspace(1)* %gep.0, align 4 176 177 %mul = fmul float %a, 10.0 178 %madmk = fadd float %mul, 2.0 179 store float %madmk, float addrspace(1)* %out.gep, align 4 180 ret void 181} 182 183; SI-LABEL: {{^}}kill_madmk_verifier_error: 184; SI: s_xor_b64 185; SI: v_madmk_f32_e32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, 0x472aee8c 186; SI: s_or_b64 187define void @kill_madmk_verifier_error() nounwind { 188bb: 189 br label %bb2 190 191bb1: ; preds = %bb2 192 ret void 193 194bb2: ; preds = %bb6, %bb 195 %tmp = phi float [ undef, %bb ], [ %tmp8, %bb6 ] 196 %tmp3 = fsub float undef, %tmp 197 %tmp5 = fcmp oeq float %tmp3, 1.000000e+04 198 br i1 %tmp5, label %bb1, label %bb6 199 200bb6: ; preds = %bb2 201 %tmp4 = fmul float %tmp, undef 202 %tmp7 = fmul float %tmp4, 0x40E55DD180000000 203 %tmp8 = fadd float %tmp7, undef 204 br label %bb2 205} 206