[Mlir-commits] [mlir] [mlir][SPIR-V] Convert math.trunc to GL Trunc and CL trunc (PR #200739)

Arseniy Obolenskiy llvmlistbot at llvm.org
Mon Jun 1 01:39:45 PDT 2026


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

>From a26a99505e9eae1a6f59022b5815bf899ebf5968 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 1 Jun 2026 09:08:18 +0200
Subject: [PATCH] [mlir][SPIR-V] Convert math.trunc to GL Trunc and CL trunc

---
 mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp            | 2 ++
 mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir     | 4 ++++
 mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir | 4 ++++
 3 files changed, 10 insertions(+)

diff --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
index 78cf3f3398bcc..de1201916874d 100644
--- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
+++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
@@ -591,6 +591,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
            CheckedElementwiseOpPattern<math::SqrtOp, spirv::GLSqrtOp>,
            CheckedElementwiseOpPattern<math::TanhOp, spirv::GLTanhOp>,
            CheckedElementwiseOpPattern<math::TanOp, spirv::GLTanOp>,
+           CheckedElementwiseOpPattern<math::TruncOp, spirv::GLTruncOp>,
            CheckedElementwiseOpPattern<math::AsinOp, spirv::GLAsinOp>,
            CheckedElementwiseOpPattern<math::AcosOp, spirv::GLAcosOp>,
            CheckedElementwiseOpPattern<math::SinhOp, spirv::GLSinhOp>,
@@ -626,6 +627,7 @@ void populateMathToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
       CheckedElementwiseOpPattern<math::SqrtOp, spirv::CLSqrtOp>,
       CheckedElementwiseOpPattern<math::TanhOp, spirv::CLTanhOp>,
       CheckedElementwiseOpPattern<math::TanOp, spirv::CLTanOp>,
+      CheckedElementwiseOpPattern<math::TruncOp, spirv::CLTruncOp>,
       CheckedElementwiseOpPattern<math::AsinOp, spirv::CLAsinOp>,
       CheckedElementwiseOpPattern<math::AcosOp, spirv::CLAcosOp>,
       CheckedElementwiseOpPattern<math::SinhOp, spirv::CLSinhOp>,
diff --git a/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
index 1bd004f0a50db..eb87b4619cbad 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
@@ -62,6 +62,8 @@ func.func @float32_unary_scalar(%arg0: f32) {
   %22 = math.acosh %arg0 : f32
   // CHECK: spirv.GL.Atanh %{{.*}}: f32
   %23 = math.atanh %arg0 : f32
+  // CHECK: spirv.GL.Trunc %{{.*}}: f32
+  %24 = math.trunc %arg0 : f32
   return
 }
 
@@ -117,6 +119,8 @@ func.func @float32_unary_vector(%arg0: vector<3xf32>) {
   %19 = math.acosh %arg0 : vector<3xf32>
   // CHECK: spirv.GL.Atanh %{{.*}}: vector<3xf32>
   %20 = math.atanh %arg0 : vector<3xf32>
+  // CHECK: spirv.GL.Trunc %{{.*}}: vector<3xf32>
+  %21 = math.trunc %arg0 : vector<3xf32>
   return
 }
 
diff --git a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
index 1b7d63fb38d36..fd040f1646661 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
@@ -62,6 +62,8 @@ func.func @float32_unary_scalar(%arg0: f32) {
   %24 = math.acosh %arg0 : f32
   // CHECK: spirv.CL.atanh %{{.*}}: f32
   %25 = math.atanh %arg0 : f32
+  // CHECK: spirv.CL.trunc %{{.*}}: f32
+  %26 = math.trunc %arg0 : f32
   return
 }
 
@@ -115,6 +117,8 @@ func.func @float32_unary_vector(%arg0: vector<3xf32>) {
   %19 = math.acosh %arg0 : vector<3xf32>
   // CHECK: spirv.CL.atanh %{{.*}}: vector<3xf32>
   %20 = math.atanh %arg0 : vector<3xf32>
+  // CHECK: spirv.CL.trunc %{{.*}}: vector<3xf32>
+  %21 = math.trunc %arg0 : vector<3xf32>
   return
 }
 



More information about the Mlir-commits mailing list