[Mlir-commits] [mlir] [mlir][SPIR-V] Guard update-vce pass against ops exceeding target max version (PR #212939)

Arseniy Obolenskiy llvmlistbot at llvm.org
Thu Jul 30 01:41:55 PDT 2026


https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/212939

>From d6f1a76fa1fd3af1f138b3d7742c4d7a12339a65 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Thu, 30 Jul 2026 08:52:16 +0200
Subject: [PATCH] [mlir][SPIR-V] Guard update-vce pass against ops exceeding
 target max version

---
 .../SPIRV/Transforms/UpdateVCEPass.cpp        | 14 ++++++++++---
 .../SPIRV/Transforms/vce-deduction.mlir       | 21 ++++++++++++++++++-
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
index febfc0f7f57f5..c44d902ba24f4 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp
@@ -136,6 +136,17 @@ void UpdateVCEPass::runOnOperation() {
       }
     }
 
+    // Op max version requirements
+    if (auto maxVersionIfx = dyn_cast<spirv::QueryMaxVersionInterface>(op)) {
+      std::optional<spirv::Version> maxVersion = maxVersionIfx.getMaxVersion();
+      if (maxVersion && *maxVersion < allowedVersion) {
+        return op->emitError("'") << op->getName() << "' requires max version "
+                                  << spirv::stringifyVersion(*maxVersion)
+                                  << " but target environment allows up to "
+                                  << spirv::stringifyVersion(allowedVersion);
+      }
+    }
+
     // Op extension requirements
     if (auto extensions = dyn_cast<spirv::QueryExtensionInterface>(op))
       if (failed(checkAndUpdateExtensionRequirements(
@@ -244,9 +255,6 @@ void UpdateVCEPass::runOnOperation() {
     }
   }
 
-  // TODO: verify that the deduced version is consistent with
-  // SPIR-V ops' maximal version requirements.
-
   auto triple = spirv::VerCapExtAttr::get(
       deducedVersion, deducedCapabilities.getArrayRef(),
       deducedExtensions.getArrayRef(), &getContext());
diff --git a/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir b/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
index 5ac467d143807..7aba8fb65a4bd 100644
--- a/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
+++ b/mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -spirv-update-vce %s | FileCheck %s
+// RUN: mlir-opt -spirv-update-vce -split-input-file -verify-diagnostics %s | FileCheck %s
 
 //===----------------------------------------------------------------------===//
 // Version
@@ -42,6 +42,25 @@ spirv.module Logical GLSL450 attributes {
   }
 }
 
+// -----
+
+// Test rejecting an op whose max version is below what the target
+// environment allows.
+// spirv.AtomicCompareExchangeWeak is only available up to v1.3.
+
+spirv.module Logical GLSL450 attributes {
+  spirv.target_env = #spirv.target_env<
+    #spirv.vce<v1.6, [Kernel], []>, #spirv.resource_limits<>>
+} {
+  spirv.func @atomic_compare_exchange_weak(%ptr : !spirv.ptr<i32, Workgroup>, %value : i32, %comparator : i32) -> i32 "None" {
+    // expected-error @+1 {{'spirv.AtomicCompareExchangeWeak' requires max version v1.3 but target environment allows up to v1.6}}
+    %0 = spirv.AtomicCompareExchangeWeak <Workgroup> <Acquire> <None> %ptr, %value, %comparator : !spirv.ptr<i32, Workgroup>
+    spirv.ReturnValue %0 : i32
+  }
+}
+
+// -----
+
 //===----------------------------------------------------------------------===//
 // Capability
 //===----------------------------------------------------------------------===//



More information about the Mlir-commits mailing list