[Mlir-commits] [mlir] a8599ac - [mlir][UBToLLVM] Do not arbitrarily restrict input types

Markus Böck llvmlistbot at llvm.org
Mon Aug 28 08:18:57 PDT 2023


Author: Markus Böck
Date: 2023-08-28T17:16:21+02:00
New Revision: a8599ac242e2d08c3eb157ab9331d7a32c3483b0

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

LOG: [mlir][UBToLLVM] Do not arbitrarily restrict input types

The lowering pattern is currently restricted to integer, float and index types.
This is seemingly arbitrary, as `ub.poison` works for any input type. The lowering should therefore also work with any type that can be converted using the type converter.

This patch therefore simply removes that condition and adds a test ensuring that this works.

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

Added: 
    

Modified: 
    mlir/lib/Conversion/UBToLLVM/UBToLLVM.cpp
    mlir/test/Conversion/UBToLLVM/ub-to-llvm.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/UBToLLVM/UBToLLVM.cpp b/mlir/lib/Conversion/UBToLLVM/UBToLLVM.cpp
index ef8b4ce2e7b2eb..0051333a35dcdc 100644
--- a/mlir/lib/Conversion/UBToLLVM/UBToLLVM.cpp
+++ b/mlir/lib/Conversion/UBToLLVM/UBToLLVM.cpp
@@ -42,16 +42,19 @@ struct PoisonOpLowering : public ConvertOpToLLVMPattern<ub::PoisonOp> {
 LogicalResult
 PoisonOpLowering::matchAndRewrite(ub::PoisonOp op, OpAdaptor adaptor,
                                   ConversionPatternRewriter &rewriter) const {
-  Type origType = op.getType();
-  if (!origType.isIntOrIndexOrFloat())
-    return rewriter.notifyMatchFailure(
-        op, [&](Diagnostic &diag) { diag << "unsupported type " << origType; });
+  if (!isa<ub::PoisonAttr>(op.getValue())) {
+    return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
+      diag << "pattern can only convert op with '"
+           << ub::PoisonAttr::getMnemonic() << "' poison value";
+    });
+  }
 
-  Type resType = getTypeConverter()->convertType(origType);
-  if (!resType)
+  Type resType = getTypeConverter()->convertType(op.getType());
+  if (!resType) {
     return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
-      diag << "failed to convert result type " << origType;
+      diag << "failed to convert result type " << op.getType();
     });
+  }
 
   rewriter.replaceOpWithNewOp<LLVM::PoisonOp>(op, resType);
   return success();

diff  --git a/mlir/test/Conversion/UBToLLVM/ub-to-llvm.mlir b/mlir/test/Conversion/UBToLLVM/ub-to-llvm.mlir
index 3f7c8137f3864b..5307e477b8786a 100644
--- a/mlir/test/Conversion/UBToLLVM/ub-to-llvm.mlir
+++ b/mlir/test/Conversion/UBToLLVM/ub-to-llvm.mlir
@@ -12,5 +12,7 @@ func.func @check_poison() {
   %1 = ub.poison : i16
 // CHECK: {{.*}} = llvm.mlir.poison : f64
   %2 = ub.poison : f64
+// CHECK: {{.*}} = llvm.mlir.poison : !llvm.ptr
+  %3 = ub.poison : !llvm.ptr
   return
 }


        


More information about the Mlir-commits mailing list