[Mlir-commits] [mlir] a0d8a08 - [mlir] Add std.bitcast -> llvm.bitcast conversion

Alex Zinenko llvmlistbot at llvm.org
Wed Aug 11 07:30:32 PDT 2021


Author: Alex Zinenko
Date: 2021-08-11T16:30:21+02:00
New Revision: a0d8a08e3e8b77fd1699fa7083e6d0b8548d67e1

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

LOG: [mlir] Add std.bitcast -> llvm.bitcast conversion

The conversion is a straightforward one-to-one mapping with optional unrolling
for nD vectors, similarly to other cast operations.

Depends On D107889

Reviewed By: cota, akuegel

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

Added: 
    

Modified: 
    mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
    mlir/test/Conversion/StandardToLLVM/convert-nd-vector-to-llvmir.mlir
    mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
index b4725d2d9f5ea..ada4e1228764a 100644
--- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -376,6 +376,8 @@ using AbsFOpLowering = VectorConvertToLLVMPattern<AbsFOp, LLVM::FAbsOp>;
 using AddFOpLowering = VectorConvertToLLVMPattern<AddFOp, LLVM::FAddOp>;
 using AddIOpLowering = VectorConvertToLLVMPattern<AddIOp, LLVM::AddOp>;
 using AndOpLowering = VectorConvertToLLVMPattern<AndOp, LLVM::AndOp>;
+using BitcastOpLowering =
+    VectorConvertToLLVMPattern<BitcastOp, LLVM::BitcastOp>;
 using CeilFOpLowering = VectorConvertToLLVMPattern<CeilFOp, LLVM::FCeilOp>;
 using CopySignOpLowering =
     VectorConvertToLLVMPattern<CopySignOp, LLVM::CopySignOp>;
@@ -1128,6 +1130,7 @@ void mlir::populateStdToLLVMConversionPatterns(LLVMTypeConverter &converter,
       AndOpLowering,
       AssertOpLowering,
       AtomicRMWOpLowering,
+      BitcastOpLowering,
       BranchOpLowering,
       CallIndirectOpLowering,
       CallOpLowering,

diff  --git a/mlir/test/Conversion/StandardToLLVM/convert-nd-vector-to-llvmir.mlir b/mlir/test/Conversion/StandardToLLVM/convert-nd-vector-to-llvmir.mlir
index 5ec2692efb3ac..caf77c4d1ee19 100644
--- a/mlir/test/Conversion/StandardToLLVM/convert-nd-vector-to-llvmir.mlir
+++ b/mlir/test/Conversion/StandardToLLVM/convert-nd-vector-to-llvmir.mlir
@@ -180,3 +180,18 @@ func @shru_vector(%arg0 : vector<1x2x3xi64>) -> vector<1x2x3xi64> {
   %0 = shift_right_unsigned %arg0, %c1 : vector<1x2x3xi64>
   return %0 : vector<1x2x3xi64>
 }
+
+// -----
+
+// CHECK-LABEL: @bitcast_2d
+func @bitcast_2d(%arg0: vector<2x4xf32>) {
+  // CHECK: llvm.mlir.undef
+  // CHECK: llvm.extractvalue %{{.*}}[0]
+  // CHECK: llvm.bitcast %{{.*}} : vector<4xf32> to vector<4xi32>
+  // CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[0]
+  // CHECK: llvm.extractvalue %{{.*}}[1]
+  // CHECK: llvm.bitcast %{{.*}} : vector<4xf32> to vector<4xi32>
+  // CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[1]
+  std.bitcast %arg0 : vector<2x4xf32> to vector<2x4xi32>
+  return
+}

diff  --git a/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir b/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir
index d68ce8cb353c7..b44ca0d5e9f01 100644
--- a/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir
+++ b/mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir
@@ -928,6 +928,15 @@ func @index_vector(%arg0: vector<4xindex>) {
 
 // -----
 
+// CHECK-LABEL: @bitcast_1d
+func @bitcast_1d(%arg0: vector<2xf32>) {
+  // CHECK: llvm.bitcast %{{.*}} : vector<2xf32> to vector<2xi32>
+  std.bitcast %arg0 : vector<2xf32> to vector<2xi32>
+  return
+}
+
+// -----
+
 // CHECK-LABEL: func @cmpf_2dvector(
 func @cmpf_2dvector(%arg0 : vector<4x3xf32>, %arg1 : vector<4x3xf32>) {
   // CHECK: %[[EXTRACT1:.*]] = llvm.extractvalue %arg0[0] : !llvm.array<4 x vector<3xf32>>


        


More information about the Mlir-commits mailing list