[Mlir-commits] [mlir] [mlir][SPIR-V] Add GL Radians and Degrees ops (PR #203879)
Arseniy Obolenskiy
llvmlistbot at llvm.org
Mon Jun 15 05:06:06 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/203879
None
>From dd670ce23307387fcdcb4e066f44c67e2c61b83c Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 15 Jun 2026 13:59:23 +0200
Subject: [PATCH] [mlir][SPIR-V] Add GL Radians and Degrees ops
---
.../mlir/Dialect/SPIRV/IR/SPIRVGLOps.td | 48 +++++++++++++++++
mlir/test/Dialect/SPIRV/IR/gl-ops.mlir | 52 +++++++++++++++++++
mlir/test/Target/SPIRV/gl-ops.mlir | 4 ++
3 files changed, 104 insertions(+)
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index 83a3ff5c3adb0..dca21b6eedba0 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -887,6 +887,54 @@ def SPIRV_GLAtan2Op : SPIRV_GLBinaryArithmeticOp<"Atan2", 25, SPIRV_Float16or32>
// -----
+def SPIRV_GLRadiansOp : SPIRV_GLUnaryArithmeticOp<"Radians", 11, SPIRV_Float16or32, [AlwaysSpeculatable]> {
+ let summary = "Convert a quantity in degrees to radians";
+
+ let description = [{
+ Result is the quantity in radians for the quantity x given in degrees, i.e.,
+ (π / 180) * x.
+
+ The operand x must be a scalar or vector whose component type is 16-bit or
+ 32-bit floating-point.
+
+ Result Type and the type of x must be the same type. Results are computed
+ per component.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.GL.Radians %0 : f32
+ %3 = spirv.GL.Radians %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_GLDegreesOp : SPIRV_GLUnaryArithmeticOp<"Degrees", 12, SPIRV_Float16or32, [AlwaysSpeculatable]> {
+ let summary = "Convert a quantity in radians to degrees";
+
+ let description = [{
+ Result is the quantity in degrees for the quantity x given in radians, i.e.,
+ (180 / π) * x.
+
+ The operand x must be a scalar or vector whose component type is 16-bit or
+ 32-bit floating-point.
+
+ Result Type and the type of x must be the same type. Results are computed
+ per component.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.GL.Degrees %0 : f32
+ %3 = spirv.GL.Degrees %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_GLExp2Op : SPIRV_GLUnaryArithmeticOp<"Exp2", 29, SPIRV_Float16or32, [AlwaysSpeculatable]> {
let summary = "Result is 2 raised to the x power";
diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index 88593d54a6783..e8f15e30ba4ee 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -1214,3 +1214,55 @@ func.func @length_vec_out(%arg0 : vector<3xf32>) -> () {
%0 = spirv.GL.Length %arg0 : vector<3xf32> -> vector<3xf32>
return
}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Radians
+//===----------------------------------------------------------------------===//
+
+func.func @radians(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Radians {{%.*}} : f32
+ %2 = spirv.GL.Radians %arg0 : f32
+ return
+}
+
+func.func @radiansvec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Radians {{%.*}} : vector<3xf16>
+ %2 = spirv.GL.Radians %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+func.func @radians(%arg0 : i32) -> () {
+ // expected-error @+1 {{op operand #0 must be 16/32-bit float or fixed-length vector of 16/32-bit float values}}
+ %2 = spirv.GL.Radians %arg0 : i32
+ return
+}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Degrees
+//===----------------------------------------------------------------------===//
+
+func.func @degrees(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Degrees {{%.*}} : f32
+ %2 = spirv.GL.Degrees %arg0 : f32
+ return
+}
+
+func.func @degreesvec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Degrees {{%.*}} : vector<3xf16>
+ %2 = spirv.GL.Degrees %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+func.func @degrees(%arg0 : i32) -> () {
+ // expected-error @+1 {{op operand #0 must be 16/32-bit float or fixed-length vector of 16/32-bit float values}}
+ %2 = spirv.GL.Degrees %arg0 : i32
+ return
+}
diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index f4dc4051818bf..eac859ecf158e 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -55,6 +55,10 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {
%21 = spirv.GL.Tanh %arg0 : f32
// CHECK: {{%.*}} = spirv.GL.Exp2 {{%.*}} : f32
%22 = spirv.GL.Exp2 %arg0 : f32
+ // CHECK: {{%.*}} = spirv.GL.Radians {{%.*}} : f32
+ %23 = spirv.GL.Radians %arg0 : f32
+ // CHECK: {{%.*}} = spirv.GL.Degrees {{%.*}} : f32
+ %24 = spirv.GL.Degrees %arg0 : f32
spirv.Return
}
More information about the Mlir-commits
mailing list