Index: llvm/lib/Target/AMDGPU/SIFoldOperands.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -1406,6 +1406,18 @@ static int getOModValue(unsigned Opc, int64_t Val) { switch (Opc) { + case AMDGPU::V_MUL_F64_e64: { + switch (Val) { + case 0x3fe0000000000000: // 0.5 + return SIOutMods::DIV2; + case 0x4000000000000000: // 2.0 + return SIOutMods::MUL2; + case 0x4010000000000000: // 4.0 + return SIOutMods::MUL4; + default: + return SIOutMods::NONE; + } + } case AMDGPU::V_MUL_F32_e64: { switch (static_cast(Val)) { case 0x3f000000: // 0.5 @@ -1442,11 +1454,13 @@ SIFoldOperands::isOMod(const MachineInstr &MI) const { unsigned Op = MI.getOpcode(); switch (Op) { + case AMDGPU::V_MUL_F64_e64: case AMDGPU::V_MUL_F32_e64: case AMDGPU::V_MUL_F16_e64: { // If output denormals are enabled, omod is ignored. if ((Op == AMDGPU::V_MUL_F32_e64 && MFI->getMode().FP32OutputDenormals) || - (Op == AMDGPU::V_MUL_F16_e64 && MFI->getMode().FP64FP16OutputDenormals)) + ((Op == AMDGPU::V_MUL_F64_e64 || Op == AMDGPU::V_MUL_F16_e64) && + MFI->getMode().FP64FP16OutputDenormals)) return std::make_pair(nullptr, SIOutMods::NONE); const MachineOperand *RegOp = nullptr; @@ -1472,11 +1486,13 @@ return std::make_pair(RegOp, OMod); } + case AMDGPU::V_ADD_F64_e64: case AMDGPU::V_ADD_F32_e64: case AMDGPU::V_ADD_F16_e64: { // If output denormals are enabled, omod is ignored. if ((Op == AMDGPU::V_ADD_F32_e64 && MFI->getMode().FP32OutputDenormals) || - (Op == AMDGPU::V_ADD_F16_e64 && MFI->getMode().FP64FP16OutputDenormals)) + ((Op == AMDGPU::V_ADD_F64_e64 || Op == AMDGPU::V_ADD_F16_e64) && + MFI->getMode().FP64FP16OutputDenormals)) return std::make_pair(nullptr, SIOutMods::NONE); // Look through the DAGCombiner canonicalization fmul x, 2 -> fadd x, x Index: llvm/test/CodeGen/AMDGPU/omod.ll =================================================================== --- llvm/test/CodeGen/AMDGPU/omod.ll +++ llvm/test/CodeGen/AMDGPU/omod.ll @@ -53,6 +53,15 @@ ret void } +; GCN-LABEL: {{^}}v_omod_div2_f64: +; GCN: v_add_f64 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, 1.0 div:2{{$}} +define amdgpu_ps void @v_omod_div2_f64(double %a) #5 { + %add = fadd fast double %a, 1.0 + %div2 = fmul fast double %add, 0.5 + store double %div2, double addrspace(1)* undef + ret void +} + ; GCN-LABEL: {{^}}v_omod_mul2_f32: ; GCN: v_add_f32_e64 v{{[0-9]+}}, v0, 1.0 mul:2{{$}} define amdgpu_ps void @v_omod_mul2_f32(float %a) #0 { @@ -62,6 +71,15 @@ ret void } +; GCN-LABEL: {{^}}v_omod_mul2_f64: +; GCN: v_add_f64 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, 1.0 mul:2{{$}} +define amdgpu_ps void @v_omod_mul2_f64(double %a) #5 { + %add = fadd fast double %a, 1.0 + %div2 = fmul fast double %add, 2.0 + store double %div2, double addrspace(1)* undef + ret void +} + ; GCN-LABEL: {{^}}v_omod_mul4_f32: ; GCN: v_add_f32_e64 v{{[0-9]+}}, v0, 1.0 mul:4{{$}} define amdgpu_ps void @v_omod_mul4_f32(float %a) #0 { @@ -71,6 +89,15 @@ ret void } +; GCN-LABEL: {{^}}v_omod_mul4_f64: +; GCN: v_add_f64 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, 1.0 mul:4{{$}} +define amdgpu_ps void @v_omod_mul4_f64(double %a) #5 { + %add = fadd fast double %a, 1.0 + %div2 = fmul fast double %add, 4.0 + store double %div2, double addrspace(1)* undef + ret void +} + ; GCN-LABEL: {{^}}v_omod_mul4_multi_use_f32: ; GCN: v_add_f32_e32 [[ADD:v[0-9]+]], 1.0, v0{{$}} ; GCN: v_mul_f32_e32 v{{[0-9]+}}, 4.0, [[ADD]]{{$}} @@ -280,6 +307,7 @@ attributes #2 = { nounwind "denormal-fp-math-f32"="ieee,ieee" "no-signed-zeros-fp-math"="true" } attributes #3 = { nounwind "denormal-fp-math"="preserve-sign,preserve-sign" "no-signed-zeros-fp-math"="true" } attributes #4 = { nounwind "no-signed-zeros-fp-math"="false" } +attributes #5 = { nounwind "denormal-fp-math"="preserve-sign,preserve-sign" "no-signed-zeros-fp-math"="true" } !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!2, !3}