mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 07:31:28 +00:00
[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:
parent
8dcb67225b
commit
a8599ac242
@ -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();
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user