Skip to content

Commit ce7cac7

Browse files
committed
[clang] Make -fveclib={ArmPL,SLEEF} imply -fno-math-errno
These two veclibs are only available for AArch64 targets, and as mentioned in https://discourse.llvm.org/t/rfc-should-fveclib-imply-fno-math-errno-for-all-targets/81384, we (Arm) think that `-fveclib` should imply `-fno-math-errno`. By setting `-fveclib` the user shows they intend to use the vector math functions, which implies they don't care about errno. However, currently, the vector mappings won't be used in many cases without setting `-fno-math-errno` separately. Making this change would also help resolve some inconsistencies in how vector mappings are applied (see llvm#108980 (comment)).
1 parent ac5a201 commit ce7cac7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,8 @@ def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, Group<f_clang_
34103410
Alias<fno_global_isel>;
34113411
def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>,
34123412
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
3413-
HelpText<"Use the given vector functions library">,
3413+
HelpText<"Use the given vector functions library."
3414+
"Note: -fveclib={ArmPL,SLEEF} implies -fno-math-errno">,
34143415
Values<"Accelerate,libmvec,MASSV,SVML,SLEEF,Darwin_libsystem_m,ArmPL,AMDLIBM,none">,
34153416
NormalizedValuesScope<"llvm::driver::VectorLibrary">,
34163417
NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "SLEEF",

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,10 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
28542854
bool OFastEnabled, const ArgList &Args,
28552855
ArgStringList &CmdArgs,
28562856
const JobAction &JA) {
2857+
// List of veclibs which when used with -fveclib imply -fno-math-errno.
2858+
constexpr std::array VecLibImpliesNoMathErrno{llvm::StringLiteral("ArmPL"),
2859+
llvm::StringLiteral("SLEEF")};
2860+
28572861
// Handle various floating point optimization flags, mapping them to the
28582862
// appropriate LLVM code generation flags. This is complicated by several
28592863
// "umbrella" flags, so we do this by stepping through the flags incrementally
@@ -3125,6 +3129,10 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
31253129
TrappingMathPresent = true;
31263130
FPExceptionBehavior = "strict";
31273131
break;
3132+
case options::OPT_fveclib:
3133+
if (llvm::is_contained(VecLibImpliesNoMathErrno, A->getValue()))
3134+
MathErrno = false;
3135+
break;
31283136
case options::OPT_fno_trapping_math:
31293137
if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
31303138
FPExceptionBehavior != "ignore")

clang/test/Driver/fveclib.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,23 @@
3636
/* Verify that the correct vector library is passed to LTO flags. */
3737

3838
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=LIBMVEC -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-LIBMVEC %s
39+
// CHECK-LTO-LIBMVEC: "-fmath-errno"
3940
// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
4041

4142
// RUN: %clang -### --target=powerpc64-unknown-linux-gnu -fveclib=MASSV -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-MASSV %s
43+
// CHECK-LTO-MASSV: "-fmath-errno"
4244
// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
4345

4446
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-SVML %s
47+
// CHECK-LTO-SVML: "-fmath-errno"
4548
// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
4649

4750
// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-SLEEF %s
51+
// CHECK-LTO-SLEEF-NOT: "-fmath-errno"
4852
// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
53+
// CHECK-LTO-SLEEF-NOT: "-fmath-errno"
4954

5055
// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-ARMPL %s
56+
// CHECK-LTO-ARMPL-NOT: "-fmath-errno"
5157
// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"
58+
// CHECK-LTO-ARMPL-NOT: "-fmath-errno"

0 commit comments

Comments
 (0)