[clang] c9db799 - [RISCV] Don't add -unaligned-scalar-mem to target features by default.
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 30 09:53:02 PDT 2023
Author: Craig Topper
Date: 2023-08-30T09:52:16-07:00
New Revision: c9db799dda6928d52baad51802c4315a0312e69d
URL: https://github.com/llvm/llvm-project/commit/c9db799dda6928d52baad51802c4315a0312e69d
DIFF: https://github.com/llvm/llvm-project/commit/c9db799dda6928d52baad51802c4315a0312e69d.diff
LOG: [RISCV] Don't add -unaligned-scalar-mem to target features by default.
Only pass it +unaligned-scalar-mem/-unaligned-scalar-mem if the
user has passed one of the alignment options.
This allows us to add unaligned-scalar-mem as a feature on CPUs
that support it.
Reviewed By: wangpc
Differential Revision: https://reviews.llvm.org/D159145
Added:
Modified:
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-default-features.c
clang/test/Driver/riscv-features.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 91a5589c363c49..bb097356d0c126 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -169,15 +169,17 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
// -mno-unaligned-access is default, unless -munaligned-access is specified.
bool HasV = llvm::is_contained(Features, "+zve32x");
- if (Args.hasFlag(options::OPT_munaligned_access,
- options::OPT_mno_unaligned_access, false)) {
- Features.push_back("+unaligned-scalar-mem");
- if (HasV)
- Features.push_back("+unaligned-vector-mem");
- } else {
- Features.push_back("-unaligned-scalar-mem");
- if (HasV)
- Features.push_back("-unaligned-vector-mem");
+ if (const Arg *A = Args.getLastArg(options::OPT_munaligned_access,
+ options::OPT_mno_unaligned_access)) {
+ if (A->getOption().matches(options::OPT_munaligned_access)) {
+ Features.push_back("+unaligned-scalar-mem");
+ if (HasV)
+ Features.push_back("+unaligned-vector-mem");
+ } else {
+ Features.push_back("-unaligned-scalar-mem");
+ if (HasV)
+ Features.push_back("-unaligned-vector-mem");
+ }
}
// Now add any that the user explicitly requested on the command line,
diff --git a/clang/test/Driver/riscv-default-features.c b/clang/test/Driver/riscv-default-features.c
index 9e7d119d0e2690..6e48f7cc37dcb0 100644
--- a/clang/test/Driver/riscv-default-features.c
+++ b/clang/test/Driver/riscv-default-features.c
@@ -3,10 +3,8 @@
// RV32: "target-features"="+32bit,+a,+c,+m,+relax,
// RV32-SAME: -save-restore
-// RV32-SAME: -unaligned-scalar-mem
// RV64: "target-features"="+64bit,+a,+c,+m,+relax,
// RV64-SAME: -save-restore
-// RV64-SAME: -unaligned-scalar-mem
// Dummy function
int foo(void){
diff --git a/clang/test/Driver/riscv-features.c b/clang/test/Driver/riscv-features.c
index bb9b4f37e222a1..0039c230ec476f 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -39,8 +39,6 @@
// NO-UNALIGNED-SCALAR-MEM: "-target-feature" "-unaligned-scalar-mem"
// UNALIGNED-VECTOR-MEM: "-target-feature" "+unaligned-vector-mem"
// NO-UNALIGNED-VECTOR-MEM: "-target-feature" "-unaligned-vector-mem"
-// DEFAULT: "-target-feature" "-unaligned-scalar-mem"
-// DEFAULT-NOT: "-target-feature" "+unaligned-scalar-mem"
// RUN: %clang --target=riscv32-linux -### %s -fsyntax-only 2>&1 \
// RUN: | FileCheck %s -check-prefix=DEFAULT-LINUX
More information about the cfe-commits
mailing list