[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
This commit is contained in:
Markus Böck 2023-08-28 15:04:52 +02:00
parent 8dcb67225b
commit a8599ac242
2 changed files with 13 additions and 8 deletions

View File

@ -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; });
Type resType = getTypeConverter()->convertType(origType);
if (!resType)
if (!isa<ub::PoisonAttr>(op.getValue())) {
return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
diag << "failed to convert result type " << origType;
diag << "pattern can only convert op with '"
<< ub::PoisonAttr::getMnemonic() << "' poison value";
});
}
Type resType = getTypeConverter()->convertType(op.getType());
if (!resType) {
return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
diag << "failed to convert result type " << op.getType();
});
}
rewriter.replaceOpWithNewOp<LLVM::PoisonOp>(op, resType);
return success();

View File

@ -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
}