[SPIR-V] Emit OpExecutionMode ContractionOff for no FP_CONTRACT metadata
authorMichal Paszkowski <michal.paszkowski@outlook.com>
Wed, 18 Jan 2023 21:23:11 +0000 (22:23 +0100)
committerMichal Paszkowski <michal.paszkowski@outlook.com>
Thu, 19 Jan 2023 14:26:34 +0000 (15:26 +0100)
This change makes the AsmPrinter emit OpExecutionMode ContractionOff
when both opencl.enable.FP_CONTRACT and spirv.ExecutionMode
metadata are not present.

Differential Revision: https://reviews.llvm.org/D141734

llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
llvm/test/CodeGen/SPIRV/opencl/metadata/fp_contractions_metadata.ll [new file with mode: 0644]
llvm/test/CodeGen/SPIRV/opencl/metadata/kernel_arg_type_function_metadata.ll [moved from llvm/test/CodeGen/SPIRV/opencl/kernel_arg_type_function_metadata.ll with 100% similarity]
llvm/test/CodeGen/SPIRV/opencl/metadata/kernel_arg_type_module_metadata.ll [moved from llvm/test/CodeGen/SPIRV/opencl/kernel_arg_type_module_metadata.ll with 100% similarity]
llvm/test/CodeGen/SPIRV/opencl/metadata/no_fp_contractions_metadata.ll [new file with mode: 0644]
llvm/test/CodeGen/SPIRV/opencl/metadata/opencl_version_metadata.ll [moved from llvm/test/CodeGen/SPIRV/metadata-opencl.ll with 100% similarity]

index f32d70e..2e822a3 100644 (file)
@@ -447,6 +447,15 @@ void SPIRVAsmPrinter::outputExecutionMode(const Module &M) {
       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<unsigned>(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 (file)
index 0000000..2b09f52
--- /dev/null
@@ -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/metadata/no_fp_contractions_metadata.ll b/llvm/test/CodeGen/SPIRV/opencl/metadata/no_fp_contractions_metadata.ll
new file mode 100644 (file)
index 0000000..1084012
--- /dev/null
@@ -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
+}