diff --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp --- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp +++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp @@ -178,6 +178,11 @@ } void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) { + if (!STI->getFeatureBits()[RISCV::FeatureRelax]) { + static_cast(*OutStreamer->getTargetStreamer()) + .emitDirectiveOptionNoRelax(); + } + if (TM.getTargetTriple().isOSBinFormatELF()) emitAttributes(); } diff --git a/llvm/test/CodeGen/RISCV/option-norelax2.ll b/llvm/test/CodeGen/RISCV/option-norelax2.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/option-norelax2.ll @@ -0,0 +1,12 @@ +; RUN: llc -mtriple=riscv32 -mattr=-relax < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=-relax < %s | FileCheck %s + +; RUN: llc -mtriple=riscv64 -mattr=+relax < %s | FileCheck %s --check-prefix=RELAX + +; CHECK: .option norelax + +; RELAX-NOT: .option norelax + +define void @foo() { + ret void +}