[Mlir-commits] [mlir] be0ad5b - [mlir][StandardToSPIRV] Add support for lowering integer casting.

Hanhan Wang llvmlistbot at llvm.org
Thu Apr 30 19:29:59 PDT 2020


Author: Hanhan Wang
Date: 2020-04-30T19:29:31-07:00
New Revision: be0ad5b034b22aed144cb9d0522c1412af6f3801

URL: https://github.com/llvm/llvm-project/commit/be0ad5b034b22aed144cb9d0522c1412af6f3801
DIFF: https://github.com/llvm/llvm-project/commit/be0ad5b034b22aed144cb9d0522c1412af6f3801.diff

LOG: [mlir][StandardToSPIRV] Add support for lowering integer casting.

Summary:
Maps ZeroExtendIOp and TruncateIOp to spirv::UConvertOp and spirv::SConvertOp.

Depends On D78974

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

Added: 
    

Modified: 
    mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
    mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp b/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
index 16fea677b51e..eb0421d2fae6 100644
--- a/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
+++ b/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
@@ -770,6 +770,8 @@ void populateStandardToSPIRVPatterns(MLIRContext *context,
       CmpFOpPattern, CmpIOpPattern, IntLoadOpPattern, LoadOpPattern,
       ReturnOpPattern, SelectOpPattern, StoreOpPattern,
       TypeCastingOpPattern<SIToFPOp, spirv::ConvertSToFOp>,
+      TypeCastingOpPattern<ZeroExtendIOp, spirv::UConvertOp>,
+      TypeCastingOpPattern<TruncateIOp, spirv::SConvertOp>,
       TypeCastingOpPattern<FPExtOp, spirv::FConvertOp>,
       TypeCastingOpPattern<FPTruncOp, spirv::FConvertOp>, XOrOpPattern>(
       context, typeConverter);

diff  --git a/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir b/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
index 7351e62b19a2..d2ede0c8024e 100644
--- a/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
+++ b/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
@@ -501,6 +501,34 @@ func @sitofp2(%arg0 : i64) -> f64 {
   return %0 : f64
 }
 
+// CHECK-LABEL: @zexti1
+func @zexti1(%arg0: i16) -> i64 {
+  // CHECK: spv.UConvert %{{.*}} : i16 to i64
+  %0 = std.zexti %arg0 : i16 to i64
+  return %0 : i64
+}
+
+// CHECK-LABEL: @zexti2
+func @zexti2(%arg0 : i32) -> i64 {
+  // CHECK: spv.UConvert %{{.*}} : i32 to i64
+  %0 = std.zexti %arg0 : i32 to i64
+  return %0 : i64
+}
+
+// CHECK-LABEL: @trunci1
+func @trunci1(%arg0 : i64) -> i16 {
+  // CHECK: spv.SConvert %{{.*}} : i64 to i16
+  %0 = std.trunci %arg0 : i64 to i16
+  return %0 : i16
+}
+
+// CHECK-LABEL: @trunci2
+func @trunci2(%arg0: i32) -> i16 {
+  // CHECK: spv.SConvert %{{.*}} : i32 to i16
+  %0 = std.trunci %arg0 : i32 to i16
+  return %0 : i16
+}
+
 } // end module
 
 // -----


        


More information about the Mlir-commits mailing list