diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1660b3966dae..06d4a244c1a5 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1760,6 +1760,8 @@ def mcrc : Flag<["-"], "mcrc">, Group, HelpText<"Allow use of CRC instructions (ARM only)">; def mnocrc : Flag<["-"], "mnocrc">, Group, HelpText<"Disallow use of CRC instructions (ARM only)">; +def mno_neg_immediates: Flag<["-"], "mno-neg-immediates">, Group, + HelpText<"Disallow converting instructions with negative immediates to their negation or inversion.">; def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group, HelpText<"Generate code which only uses the general purpose registers (AArch64 only)">; diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index 7dc2f57d8299..554d051fb155 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -193,4 +193,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, const ArgList &Args, if (Args.hasArg(options::OPT_ffixed_x18)) Features.push_back("+reserve-x18"); + + if (Args.hasArg(options::OPT_mno_neg_immediates)) + Features.push_back("+no-neg-immediates"); } diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index 15f224bb22af..4eac97620114 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -449,6 +449,9 @@ void arm::getARMTargetFeatures(const ToolChain &TC, // The kext linker doesn't know how to deal with movw/movt. if (KernelOrKext || Args.hasArg(options::OPT_mno_movt)) Features.push_back("+no-movt"); + + if (Args.hasArg(options::OPT_mno_neg_immediates)) + Features.push_back("+no-neg-immediates"); } const std::string arm::getARMArch(StringRef Arch, const llvm::Triple &Triple) { diff --git a/clang/test/Driver/arm-no-neg-immediates.c b/clang/test/Driver/arm-no-neg-immediates.c new file mode 100644 index 000000000000..f1e4d5f7906b --- /dev/null +++ b/clang/test/Driver/arm-no-neg-immediates.c @@ -0,0 +1,8 @@ +// RUN: %clang -target arm-none-gnueabi -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT +// RUN: %clang -target arm-none-gnueabi -mno-neg-immediates -### %s 2>&1 | FileCheck %s + +// RUN: %clang -target aarch64-none-gnueabi -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT +// RUN: %clang -target aarch64-none-gnueabi -mno-neg-immediates -### %s 2>&1 | FileCheck %s + +// CHECK: "-target-feature" "+no-neg-immediates" +// CHECK-DEFAULT-NOT: "+no-neg-immediates"