[Driver] Add f16 support to -mrecip parsing.

This is a followup to D120158 which added an 'h' suffix to the
backend handling.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D124551
This commit is contained in:
Craig Topper 2022-04-28 08:21:02 -07:00
parent 8631a5e712
commit bd30d4be23
3 changed files with 29 additions and 7 deletions
clang
lib/Driver/ToolChains
test

View File

@ -226,12 +226,16 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
llvm::StringMap<bool> OptionStrings;
OptionStrings.insert(std::make_pair("divd", false));
OptionStrings.insert(std::make_pair("divf", false));
OptionStrings.insert(std::make_pair("divh", false));
OptionStrings.insert(std::make_pair("vec-divd", false));
OptionStrings.insert(std::make_pair("vec-divf", false));
OptionStrings.insert(std::make_pair("vec-divh", false));
OptionStrings.insert(std::make_pair("sqrtd", false));
OptionStrings.insert(std::make_pair("sqrtf", false));
OptionStrings.insert(std::make_pair("sqrth", false));
OptionStrings.insert(std::make_pair("vec-sqrtd", false));
OptionStrings.insert(std::make_pair("vec-sqrtf", false));
OptionStrings.insert(std::make_pair("vec-sqrth", false));
for (unsigned i = 0; i != NumOptions; ++i) {
StringRef Val = A->getValue(i);
@ -255,10 +259,11 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
D.Diag(diag::err_drv_unknown_argument) << Val;
return;
}
// The option was specified without a float or double suffix.
// Make sure that the double entry was not already specified.
// The option was specified without a half or float or double suffix.
// Make sure that the double or half entry was not already specified.
// The float entry will be checked below.
if (OptionStrings[ValBase.str() + 'd']) {
if (OptionStrings[ValBase.str() + 'd'] ||
OptionStrings[ValBase.str() + 'h']) {
D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
return;
}
@ -273,9 +278,12 @@ static void ParseMRecip(const Driver &D, const ArgList &Args,
// Mark the matched option as found. Do not allow duplicate specifiers.
OptionIter->second = true;
// If the precision was not specified, also mark the double entry as found.
if (ValBase.back() != 'f' && ValBase.back() != 'd')
// If the precision was not specified, also mark the double and half entry
// as found.
if (ValBase.back() != 'f' && ValBase.back() != 'd' && ValBase.back() != 'h') {
OptionStrings[ValBase.str() + 'd'] = true;
OptionStrings[ValBase.str() + 'h'] = true;
}
// Build the output string.
StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut;

View File

@ -1,7 +1,7 @@
// RUN: %clang_cc1 -mrecip=!sqrtf,vec-divf:3 -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -mrecip=!sqrtf,vec-divf:3,divh -emit-llvm %s -o - | FileCheck %s
int baz(int a) { return 4; }
// CHECK: baz{{.*}} #0
// CHECK: #0 = {{.*}}"reciprocal-estimates"="!sqrtf,vec-divf:3"
// CHECK: #0 = {{.*}}"reciprocal-estimates"="!sqrtf,vec-divf:3,divh"

View File

@ -37,6 +37,9 @@
// RUN: %clang -### -S %s -mrecip=divf,sqrtd,vec-divd,vec-sqrtf 2>&1 | FileCheck --check-prefix=RECIP8 %s
// RECIP8: "-mrecip=divf,sqrtd,vec-divd,vec-sqrtf"
// RUN: %clang -### -S %s -mrecip=vec-sqrth 2>&1 | FileCheck --check-prefix=RECIP18 %s
// RECIP18: "-mrecip=vec-sqrth"
//// Check optional refinement step specifiers.
// RUN: %clang -### -S %s -mrecip=all:1 2>&1 | FileCheck --check-prefix=RECIP9 %s
@ -51,6 +54,9 @@
// RUN: %clang -### -S %s -mrecip=divd:1,!sqrtf:2,vec-divf:9,vec-sqrtd:0 2>&1 | FileCheck --check-prefix=RECIP12 %s
// RECIP12: "-mrecip=divd:1,!sqrtf:2,vec-divf:9,vec-sqrtd:0"
// RUN: %clang -### -S %s -mrecip=sqrth:2 2>&1 | FileCheck --check-prefix=RECIP19 %s
// RECIP19: "-mrecip=sqrth:2"
//// Check invalid parameters.
// RUN: %clang -### -S %s -mrecip=bogus 2>&1 | FileCheck --check-prefix=RECIP13 %s
@ -68,3 +74,11 @@
// RUN: %clang -### -S %s -mrecip=!vec-divd: 2>&1 | FileCheck --check-prefix=RECIP17 %s
// RECIP17: error: invalid value
// RUN: %clang -### -S %s -mrecip=divh:1,divh 2>&1 | FileCheck --check-prefix=RECIP20 %s
// RECIP20: error: invalid value
// RUN: %clang -### -S %s -mrecip=divh,div 2>&1 | FileCheck --check-prefix=RECIP21 %s
// RECIP21: error: invalid value
// RUN: %clang -### -S %s -mrecip=sqrt,sqrth 2>&1 | FileCheck --check-prefix=RECIP22 %s
// RECIP22: error: invalid value