[llvm] [SPIR-V] Prefer SPV_INTEL_optnone over SPV_EXT_optnone when both extensions are available (PR #122082)
Vyacheslav Levytskyy via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 01:55:00 PST 2025
https://github.com/VyacheslavLevytskyy created https://github.com/llvm/llvm-project/pull/122082
This PR fixes https://github.com/llvm/llvm-project/issues/122075. We prefer SPV_INTEL_optnone over SPV_EXT_optnone when both extensions are available, otherwise, when a target specifies a required extension explicitly rather than allowing any of those (e.g., by providing --spirv-ext=all command line argument), the Backend's behavior remains unchanged. An existing test case is updated to check the case of 2 alternative extensions available at the same time.
>From c40dbe6e467ad4d40294550dd7bb25c2295d75b6 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Wed, 8 Jan 2025 01:52:07 -0800
Subject: [PATCH] Prefer SPV_INTEL_optnone over SPV_EXT_optnone when both
extensions are available
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 8 ++++----
llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_optnone.ll | 9 +++++++++
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 63adf545775c8f..020c11a3af4e16 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -1807,12 +1807,12 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
SPIRV::ExecutionMode::VecTypeHint, ST);
if (F.hasOptNone()) {
- if (ST.canUseExtension(SPIRV::Extension::SPV_EXT_optnone)) {
- MAI.Reqs.addExtension(SPIRV::Extension::SPV_EXT_optnone);
- MAI.Reqs.addCapability(SPIRV::Capability::OptNoneEXT);
- } else if (ST.canUseExtension(SPIRV::Extension::SPV_INTEL_optnone)) {
+ if (ST.canUseExtension(SPIRV::Extension::SPV_INTEL_optnone)) {
MAI.Reqs.addExtension(SPIRV::Extension::SPV_INTEL_optnone);
MAI.Reqs.addCapability(SPIRV::Capability::OptNoneINTEL);
+ } else if (ST.canUseExtension(SPIRV::Extension::SPV_EXT_optnone)) {
+ MAI.Reqs.addExtension(SPIRV::Extension::SPV_EXT_optnone);
+ MAI.Reqs.addCapability(SPIRV::Capability::OptNoneEXT);
}
}
}
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_optnone.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_optnone.ll
index e21d99badea061..268b6969f32fd2 100644
--- a/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_optnone.ll
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_EXT_optnone.ll
@@ -4,6 +4,9 @@
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_EXT_optnone %s -o - -filetype=obj | spirv-val %}
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_EXT_optnone,+SPV_INTEL_optnone %s -o - | FileCheck %s --check-prefixes=CHECK-TWO-EXTENSIONS
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=all %s -o - | FileCheck %s --check-prefixes=CHECK-ALL-EXTENSIONS
+
; CHECK-EXTENSION: OpCapability OptNoneEXT
; CHECK-EXTENSION: OpExtension "SPV_EXT_optnone"
; CHECK-NO-EXTENSION-NOT: OpCapability OptNoneINTEL
@@ -11,6 +14,12 @@
; CHECK-NO-EXTENSION-NOT: OpExtension "SPV_INTEL_optnone"
; CHECK-NO-EXTENSION-NOT: OpExtension "SPV_EXT_optnone"
+; CHECK-TWO-EXTENSIONS: OpCapability OptNoneEXT
+; CHECK-TWO-EXTENSIONS: OpExtension "SPV_INTEL_optnone"
+
+; CHECK-ALL-EXTENSIONS: OpCapability OptNoneEXT
+; CHECK-ALL-EXTENSIONS: OpExtension "SPV_INTEL_optnone"
+
define spir_func void @foo() #0 {
; CHECK-EXTENSION: %[[#]] = OpFunction %[[#]] DontInline|OptNoneEXT %[[#]]
entry:
More information about the llvm-commits
mailing list