Skip to content

Commit d9fb52e

Browse files
MatzeBmacurtis-amd
authored andcommitted
X86: Do not return invalid cost for fp16 conversion (llvm#114128)
Returning invalid instruction costs when converting from/to fp16 in `X86TTIImpl::getCastInstrCost` when there is no hardware support available was triggering asserts. This changes the code to return a large (arbitrary) number to model the fact that libcalls are used to implement the conversion. This also simplifies the code by only reporting costs for the scalar fp16 conversion; vectorized costs being left to the fallback assuming scalarization. This is a follow-up to assertion issues reported for the changes in llvm#113195 upstream commit: 255e441
1 parent 7fdce91 commit d9fb52e

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,11 +3310,6 @@ InstructionCost X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
33103310
TTI::CastContextHint::None, CostKind);
33113311
}
33123312

3313-
if (ISD == ISD::FP_ROUND && LTDest.second.getScalarType() == MVT::f16) {
3314-
// Conversion requires a libcall.
3315-
return InstructionCost::getInvalid();
3316-
}
3317-
33183313
// TODO: Allow non-throughput costs that aren't binary.
33193314
auto AdjustCost = [&CostKind](InstructionCost Cost,
33203315
InstructionCost N = 1) -> InstructionCost {

llvm/test/Transforms/SLPVectorizer/X86/conversion-fp16.ll

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,9 @@ define void @fpround_v16xf32_v16xf16(ptr %s0, ptr %d0) {
453453
;
454454
; CHECK-F16C-LABEL: define void @fpround_v16xf32_v16xf16(
455455
; CHECK-F16C-SAME: ptr [[S0:%.*]], ptr [[D0:%.*]]) #[[ATTR0]] {
456-
; CHECK-F16C-NEXT: [[S8:%.*]] = getelementptr inbounds float, ptr [[S0]], i64 8
457-
; CHECK-F16C-NEXT: [[D8:%.*]] = getelementptr inbounds half, ptr [[D0]], i64 8
458-
; CHECK-F16C-NEXT: [[TMP1:%.*]] = load <8 x float>, ptr [[S0]], align 4
459-
; CHECK-F16C-NEXT: [[TMP2:%.*]] = fptrunc <8 x float> [[TMP1]] to <8 x half>
460-
; CHECK-F16C-NEXT: [[TMP3:%.*]] = load <8 x float>, ptr [[S8]], align 4
461-
; CHECK-F16C-NEXT: [[TMP4:%.*]] = fptrunc <8 x float> [[TMP3]] to <8 x half>
462-
; CHECK-F16C-NEXT: store <8 x half> [[TMP2]], ptr [[D0]], align 2
463-
; CHECK-F16C-NEXT: store <8 x half> [[TMP4]], ptr [[D8]], align 2
456+
; CHECK-F16C-NEXT: [[TMP1:%.*]] = load <16 x float>, ptr [[S0]], align 4
457+
; CHECK-F16C-NEXT: [[TMP2:%.*]] = fptrunc <16 x float> [[TMP1]] to <16 x half>
458+
; CHECK-F16C-NEXT: store <16 x half> [[TMP2]], ptr [[D0]], align 2
464459
; CHECK-F16C-NEXT: ret void
465460
;
466461
; CHECK-AVX512-LABEL: define void @fpround_v16xf32_v16xf16(

0 commit comments

Comments
 (0)