Index: lib/Target/AMDGPU/AMDGPUInstructions.td =================================================================== --- lib/Target/AMDGPU/AMDGPUInstructions.td +++ lib/Target/AMDGPU/AMDGPUInstructions.td @@ -842,6 +842,7 @@ [{ (void)N; return TM.Options.NoNaNsFPMath; }] >; +let AddedComplexity = 2 in { class IMad24Pat : AMDGPUPat < (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2), !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)), @@ -853,6 +854,7 @@ !if(HasClamp, (Inst $src0, $src1, $src2, (i1 0)), (Inst $src0, $src1, $src2)) >; +} // AddedComplexity. class RcpPat : AMDGPUPat < (fdiv FP_ONE, vt:$src), Index: test/CodeGen/AMDGPU/add3.ll =================================================================== --- test/CodeGen/AMDGPU/add3.ll +++ test/CodeGen/AMDGPU/add3.ll @@ -23,6 +23,32 @@ ret float %bc } +; V_MAD_U32_U24 is given higher priority. +define amdgpu_ps float @mad_no_add3(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { +; GFX9-LABEL: mad_no_add3: +; GFX9: ; %bb.0: +; GFX9-NEXT: v_mad_u32_u24 v0, v0, v1, v4 +; GFX9-NEXT: v_mad_u32_u24 v0, v2, v3, v0 +; GFX9-NEXT: ; return to shader part epilog + %1 = shl i32 %a, 8 + %a1 = lshr i32 %1, 8 + %2 = shl i32 %b, 8 + %b1 = lshr i32 %2, 8 + %mul1 = mul i32 %a1, %b1 + + %3 = shl i32 %c, 8 + %a2 = lshr i32 %3, 8 + %4 = shl i32 %d, 8 + %b2 = lshr i32 %4, 8 + %mul2 = mul i32 %a2, %b2 + + %5 = add i32 %e, %mul1 + %result = add i32 %mul2, %5 + + %bc = bitcast i32 %result to float + ret float %bc +} + ; ThreeOp instruction variant not used due to Constant Bus Limitations ; TODO: with reassociation it is possible to replace a v_add_u32_e32 with a s_add_i32 define amdgpu_ps float @add3_vgpr_b(i32 inreg %a, i32 %b, i32 inreg %c) {