diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp --- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp @@ -447,6 +447,15 @@ Inst.addOperand(MCOperand::createImm(TypeCode)); outputMCInst(Inst); } + if (!M.getNamedMetadata("spirv.ExecutionMode") && + !M.getNamedMetadata("opencl.enable.FP_CONTRACT")) { + MCInst Inst; + Inst.setOpcode(SPIRV::OpExecutionMode); + Inst.addOperand(MCOperand::createReg(FReg)); + unsigned EM = static_cast(SPIRV::ExecutionMode::ContractionOff); + Inst.addOperand(MCOperand::createImm(EM)); + outputMCInst(Inst); + } } } diff --git a/llvm/test/CodeGen/SPIRV/opencl/metadata/fp_contractions_metadata.ll b/llvm/test/CodeGen/SPIRV/opencl/metadata/fp_contractions_metadata.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/opencl/metadata/fp_contractions_metadata.ll @@ -0,0 +1,10 @@ +; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s + +; CHECK: OpEntryPoint Kernel %[[#ENTRY:]] "foo" +; CHECK-NOT: OpExecutionMode %[[#ENTRY]] ContractionOff +define spir_kernel void @foo() { +entry: + ret void +} + +!opencl.enable.FP_CONTRACT = !{} diff --git a/llvm/test/CodeGen/SPIRV/opencl/kernel_arg_type_function_metadata.ll b/llvm/test/CodeGen/SPIRV/opencl/metadata/kernel_arg_type_function_metadata.ll rename from llvm/test/CodeGen/SPIRV/opencl/kernel_arg_type_function_metadata.ll rename to llvm/test/CodeGen/SPIRV/opencl/metadata/kernel_arg_type_function_metadata.ll diff --git a/llvm/test/CodeGen/SPIRV/opencl/kernel_arg_type_module_metadata.ll b/llvm/test/CodeGen/SPIRV/opencl/metadata/kernel_arg_type_module_metadata.ll rename from llvm/test/CodeGen/SPIRV/opencl/kernel_arg_type_module_metadata.ll rename to llvm/test/CodeGen/SPIRV/opencl/metadata/kernel_arg_type_module_metadata.ll diff --git a/llvm/test/CodeGen/SPIRV/opencl/metadata/no_fp_contractions_metadata.ll b/llvm/test/CodeGen/SPIRV/opencl/metadata/no_fp_contractions_metadata.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/opencl/metadata/no_fp_contractions_metadata.ll @@ -0,0 +1,8 @@ +; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s + +; CHECK: OpEntryPoint Kernel %[[#ENTRY:]] "foo" +; CHECK: OpExecutionMode %[[#ENTRY]] ContractionOff +define spir_kernel void @foo() { +entry: + ret void +} diff --git a/llvm/test/CodeGen/SPIRV/metadata-opencl.ll b/llvm/test/CodeGen/SPIRV/opencl/metadata/opencl_version_metadata.ll rename from llvm/test/CodeGen/SPIRV/metadata-opencl.ll rename to llvm/test/CodeGen/SPIRV/opencl/metadata/opencl_version_metadata.ll