[PATCH] D79049: [mlir][StandardToSPIRV] Handle conversion of cmpi operation with i1 type operands.
Mahesh Ravishankar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 10:12:08 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c12a95d9c52: [mlir][StandardToSPIRV] Handle conversion of cmpi operation with i1 type… (authored by mravishankar).
Changed prior to commit:
https://reviews.llvm.org/D79049?vs=260786&id=260952#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79049/new/
https://reviews.llvm.org/D79049
Files:
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
Index: mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
===================================================================
--- mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
+++ mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
@@ -285,6 +285,15 @@
return
}
+// CHECK-LABEL: @boolcmpi
+func @boolcmpi(%arg0 : i1, %arg1 : i1) {
+ // CHECK: spv.LogicalEqual
+ %0 = cmpi "eq", %arg0, %arg1 : i1
+ // CHECK: spv.LogicalNotEqual
+ %1 = cmpi "ne", %arg0, %arg1 : i1
+ return
+}
+
} // end module
// -----
Index: mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
===================================================================
--- mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
+++ mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
@@ -184,6 +184,16 @@
ConversionPatternRewriter &rewriter) const override;
};
+/// Converts integer compare operation on i1 type opearnds to SPIR-V ops.
+class BoolCmpIOpPattern final : public SPIRVOpLowering<CmpIOp> {
+public:
+ using SPIRVOpLowering<CmpIOp>::SPIRVOpLowering;
+
+ LogicalResult
+ matchAndRewrite(CmpIOp cmpIOp, ArrayRef<Value> operands,
+ ConversionPatternRewriter &rewriter) const override;
+};
+
/// Converts integer compare operation to SPIR-V ops.
class CmpIOpPattern final : public SPIRVOpLowering<CmpIOp> {
public:
@@ -454,10 +464,42 @@
//===----------------------------------------------------------------------===//
LogicalResult
+BoolCmpIOpPattern::matchAndRewrite(CmpIOp cmpIOp, ArrayRef<Value> operands,
+ ConversionPatternRewriter &rewriter) const {
+ CmpIOpOperandAdaptor cmpIOpOperands(operands);
+
+ Type operandType = cmpIOp.lhs().getType();
+ if (!operandType.isa<IntegerType>() ||
+ operandType.cast<IntegerType>().getWidth() != 1)
+ return failure();
+
+ switch (cmpIOp.getPredicate()) {
+#define DISPATCH(cmpPredicate, spirvOp) \
+ case cmpPredicate: \
+ rewriter.replaceOpWithNewOp<spirvOp>(cmpIOp, cmpIOp.getResult().getType(), \
+ cmpIOpOperands.lhs(), \
+ cmpIOpOperands.rhs()); \
+ return success();
+
+ DISPATCH(CmpIPredicate::eq, spirv::LogicalEqualOp);
+ DISPATCH(CmpIPredicate::ne, spirv::LogicalNotEqualOp);
+
+#undef DISPATCH
+ default:;
+ }
+ return failure();
+}
+
+LogicalResult
CmpIOpPattern::matchAndRewrite(CmpIOp cmpIOp, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const {
CmpIOpOperandAdaptor cmpIOpOperands(operands);
+ Type operandType = cmpIOp.lhs().getType();
+ if (operandType.isa<IntegerType>() &&
+ operandType.cast<IntegerType>().getWidth() == 1)
+ return failure();
+
switch (cmpIOp.getPredicate()) {
#define DISPATCH(cmpPredicate, spirvOp) \
case cmpPredicate: \
@@ -599,9 +641,10 @@
UnaryAndBinaryOpPattern<UnsignedShiftRightOp, spirv::ShiftRightLogicalOp>,
BitwiseOpPattern<AndOp, spirv::LogicalAndOp, spirv::BitwiseAndOp>,
BitwiseOpPattern<OrOp, spirv::LogicalOrOp, spirv::BitwiseOrOp>,
- ConstantCompositeOpPattern, ConstantScalarOpPattern, CmpFOpPattern,
- CmpIOpPattern, LoadOpPattern, ReturnOpPattern, SelectOpPattern,
- StoreOpPattern, TypeCastingOpPattern<SIToFPOp, spirv::ConvertSToFOp>,
+ BoolCmpIOpPattern, ConstantCompositeOpPattern, ConstantScalarOpPattern,
+ CmpFOpPattern, CmpIOpPattern, LoadOpPattern, ReturnOpPattern,
+ SelectOpPattern, StoreOpPattern,
+ TypeCastingOpPattern<SIToFPOp, spirv::ConvertSToFOp>,
TypeCastingOpPattern<FPExtOp, spirv::FConvertOp>,
TypeCastingOpPattern<FPTruncOp, spirv::FConvertOp>, XOrOpPattern>(
context, typeConverter);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79049.260952.patch
Type: text/x-patch
Size: 4020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200429/844680cf/attachment-0001.bin>
More information about the llvm-commits
mailing list