Skip to content

[NFC] Add useFPRegsForHalfType(). #74147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,18 @@ class TargetLoweringBase {
return TypePromoteInteger;
}

// Return true if the half type should be passed around as i16, but promoted
// to float around arithmetic. The default behavior is to pass around as
// float and convert around loads/stores/bitcasts and other places where
// the size matters.
// Return true if the half type should be promoted using soft promotion rules
// where each operation is promoted to f32 individually, then converted to
// fp16. The default behavior is to promote chains of operations, keeping
// intermediate results in f32 precision and range.
virtual bool softPromoteHalfType() const { return false; }

// Return true if, for soft-promoted half, the half type should be passed
// passed to and returned from functions as f32. The default behavior is to
// pass as i16. If soft-promoted half is not used, this function is ignored
// and values are always passed and returned as f32.
virtual bool useFPRegsForHalfType() const { return false; }

// There are two general methods for expanding a BUILD_VECTOR node:
// 1. Use SCALAR_TO_VECTOR on the defined scalar values and then shuffle
// them together.
Expand Down
13 changes: 9 additions & 4 deletions llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,15 +1430,20 @@ void TargetLoweringBase::computeRegisterProperties(
// conversions).
if (!isTypeLegal(MVT::f16)) {
// Allow targets to control how we legalize half.
if (softPromoteHalfType()) {
bool SoftPromoteHalfType = softPromoteHalfType();
bool UseFPRegsForHalfType = !SoftPromoteHalfType || useFPRegsForHalfType();

if (!UseFPRegsForHalfType) {
NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16];
RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16];
TransformToType[MVT::f16] = MVT::f32;
ValueTypeActions.setTypeAction(MVT::f16, TypeSoftPromoteHalf);
} else {
NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
TransformToType[MVT::f16] = MVT::f32;
}
TransformToType[MVT::f16] = MVT::f32;
if (SoftPromoteHalfType) {
ValueTypeActions.setTypeAction(MVT::f16, TypeSoftPromoteHalf);
} else {
ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
}
}
Expand Down