[clang] bd30d4b - [Driver] Add f16 support to -mrecip parsing.
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 28 08:36:39 PDT 2022
Author: Craig Topper
Date: 2022-04-28T08:33:52-07:00
New Revision: bd30d4be2354f149fa6cb6d65fd95e6796951529
URL: https://github.com/llvm/llvm-project/commit/bd30d4be2354f149fa6cb6d65fd95e6796951529
DIFF: https://github.com/llvm/llvm-project/commit/bd30d4be2354f149fa6cb6d65fd95e6796951529.diff
LOG: [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
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/attr-mrecip.c
clang/test/Driver/mrecip.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 52dbe07ab3551..4c22d331be039 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -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;
diff --git a/clang/test/CodeGen/attr-mrecip.c b/clang/test/CodeGen/attr-mrecip.c
index 954c57ae102b1..5f127522db53a 100644
--- a/clang/test/CodeGen/attr-mrecip.c
+++ b/clang/test/CodeGen/attr-mrecip.c
@@ -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"
diff --git a/clang/test/Driver/mrecip.c b/clang/test/Driver/mrecip.c
index 4e99b1532612e..a7e79a49f95ab 100644
--- a/clang/test/Driver/mrecip.c
+++ b/clang/test/Driver/mrecip.c
@@ -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
More information about the cfe-commits
mailing list