Skip to content

Commit 2da56cf

Browse files
authored
AMDGPU: Make v2f32 -> v2f16 legal when target supports v_cvt_pk_f16_f32 (llvm#139956) (llvm#2478)
If targets support v_cvt_pk_f16_f32 instruction, v2f32 -> v2f16 should be legal. However, SelectionDAG does not allow us to specify the source type in the legalization rules. To workaround this, we make FP_ROUND Custom for v2f16 then set up v2f32 -> v2f16 to be legal during custom lowering. Cherry-pick llvm#139956 to mainline (after bulk promotion) Fixes: SWDEV-532608 -- expected v_cvt_pk_f16_f32 was not generated.
1 parent 4f49035 commit 2da56cf

File tree

3 files changed

+219
-215
lines changed

3 files changed

+219
-215
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
916916
setOperationAction(ISD::BUILD_VECTOR, MVT::v2bf16, Legal);
917917
}
918918

919+
if (Subtarget->hasCvtPkF16F32Inst())
920+
setOperationAction(ISD::FP_ROUND, MVT::v2f16, Custom);
921+
919922
setTargetDAGCombine({ISD::ADD,
920923
ISD::UADDO_CARRY,
921924
ISD::SUB,
@@ -6807,11 +6810,18 @@ SDValue SITargetLowering::getFPExtOrFPRound(SelectionDAG &DAG, SDValue Op,
68076810
}
68086811

68096812
SDValue SITargetLowering::lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const {
6813+
SDValue Src = Op.getOperand(0);
6814+
EVT SrcVT = Src.getValueType();
6815+
EVT DstVT = Op.getValueType();
6816+
6817+
if (DstVT == MVT::v2f16) {
6818+
assert(Subtarget->hasCvtPkF16F32Inst() && "support v_cvt_pk_f16_f32");
6819+
return SrcVT == MVT::v2f32 ? Op : SDValue();
6820+
}
6821+
68106822
assert(Op.getValueType() == MVT::f16 &&
68116823
"Do not know how to custom lower FP_ROUND for non-f16 type");
68126824

6813-
SDValue Src = Op.getOperand(0);
6814-
EVT SrcVT = Src.getValueType();
68156825
if (SrcVT != MVT::f64)
68166826
return Op;
68176827

llvm/test/CodeGen/AMDGPU/fptrunc.v2f16.fpmath.ll

Lines changed: 0 additions & 213 deletions
This file was deleted.

0 commit comments

Comments
 (0)