[Mlir-commits] [mlir] c8295de - [MLIR][SPIRVToLLVM] Conversion for bitrverse and bitcount ops
Lei Zhang
llvmlistbot at llvm.org
Fri Jun 26 07:33:48 PDT 2020
Author: George Mitenkov
Date: 2020-06-26T10:30:52-04:00
New Revision: c8295de4a66adcc610c315df69286f02c306a1c9
URL: https://github.com/llvm/llvm-project/commit/c8295de4a66adcc610c315df69286f02c306a1c9
DIFF: https://github.com/llvm/llvm-project/commit/c8295de4a66adcc610c315df69286f02c306a1c9.diff
LOG: [MLIR][SPIRVToLLVM] Conversion for bitrverse and bitcount ops
Implemented conversion for `spv.BitReverse` and `spv.BitCount`. Since ODS
generates builders in a different way for LLVM dialect intrinsics, I
added attributes to build method in `DirectConversionPattern` class. The
tests for these ops are in `bitwise-ops-to-llvm.mlir`.
Differential Revision: https://reviews.llvm.org/D82286
Added:
Modified:
mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
index 297e73a3baaf..6178b53c883b 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
@@ -72,7 +72,8 @@ class DirectConversionPattern : public SPIRVToLLVMConversion<SPIRVOp> {
auto dstType = this->typeConverter.convertType(operation.getType());
if (!dstType)
return failure();
- rewriter.template replaceOpWithNewOp<LLVMOp>(operation, dstType, operands);
+ rewriter.template replaceOpWithNewOp<LLVMOp>(operation, dstType, operands,
+ operation.getAttrs());
return success();
}
};
@@ -340,6 +341,8 @@ void mlir::populateSPIRVToLLVMConversionPatterns(
DirectConversionPattern<spirv::UModOp, LLVM::URemOp>,
// Bitwise ops
+ DirectConversionPattern<spirv::BitCountOp, LLVM::CtPopOp>,
+ DirectConversionPattern<spirv::BitReverseOp, LLVM::BitReverseOp>,
DirectConversionPattern<spirv::BitwiseAndOp, LLVM::AndOp>,
DirectConversionPattern<spirv::BitwiseOrOp, LLVM::OrOp>,
DirectConversionPattern<spirv::BitwiseXorOp, LLVM::XOrOp>,
diff --git a/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir b/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir
index 13410400253e..fb276d4ee53e 100644
--- a/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir
+++ b/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir
@@ -1,5 +1,37 @@
// RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
+//===----------------------------------------------------------------------===//
+// spv.BitCount
+//===----------------------------------------------------------------------===//
+
+func @bitcount_scalar(%arg0: i16) {
+ // CHECK: %{{.*}} = "llvm.intr.ctpop"(%{{.*}}) : (!llvm.i16) -> !llvm.i16
+ %0 = spv.BitCount %arg0: i16
+ return
+}
+
+func @bitcount_vector(%arg0: vector<3xi32>) {
+ // CHECK: %{{.*}} = "llvm.intr.ctpop"(%{{.*}}) : (!llvm<"<3 x i32>">) -> !llvm<"<3 x i32>">
+ %0 = spv.BitCount %arg0: vector<3xi32>
+ return
+}
+
+//===----------------------------------------------------------------------===//
+// spv.BitReverse
+//===----------------------------------------------------------------------===//
+
+func @bitreverse_scalar(%arg0: i64) {
+ // CHECK: %{{.*}} = "llvm.intr.bitreverse"(%{{.*}}) : (!llvm.i64) -> !llvm.i64
+ %0 = spv.BitReverse %arg0: i64
+ return
+}
+
+func @bitreverse_vector(%arg0: vector<4xi32>) {
+ // CHECK: %{{.*}} = "llvm.intr.bitreverse"(%{{.*}}) : (!llvm<"<4 x i32>">) -> !llvm<"<4 x i32>">
+ %0 = spv.BitReverse %arg0: vector<4xi32>
+ return
+}
+
//===----------------------------------------------------------------------===//
// spv.BitwiseAnd
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list