[mlir][complex] Lower complex.constant to LLVM

This fixes a regression from 480cd4cb85

Differential Revision: https://reviews.llvm.org/D118347
This commit is contained in:
Benjamin Kramer 2022-01-27 13:08:08 +01:00
parent a78ce48c37
commit 608cc6b163
2 changed files with 20 additions and 0 deletions

View File

@ -78,6 +78,18 @@ struct AbsOpConversion : public ConvertOpToLLVMPattern<complex::AbsOp> {
}
};
struct ConstantOpLowering : public ConvertOpToLLVMPattern<complex::ConstantOp> {
using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
LogicalResult
matchAndRewrite(complex::ConstantOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
return LLVM::detail::oneToOneRewrite(
op, LLVM::ConstantOp::getOperationName(), adaptor.getOperands(),
*getTypeConverter(), rewriter);
}
};
struct CreateOpConversion : public ConvertOpToLLVMPattern<complex::CreateOp> {
using ConvertOpToLLVMPattern<complex::CreateOp>::ConvertOpToLLVMPattern;
@ -294,6 +306,7 @@ void mlir::populateComplexToLLVMConversionPatterns(
patterns.add<
AbsOpConversion,
AddOpConversion,
ConstantOpLowering,
CreateOpConversion,
DivOpConversion,
ImOpConversion,

View File

@ -10,6 +10,13 @@ func @complex_create(%real: f32, %imag: f32) -> complex<f32> {
return %cplx2 : complex<f32>
}
// CHECK-LABEL: func @complex_constant
// CHECK-NEXT: llvm.mlir.constant([1.000000e+00, 2.000000e+00]) : !llvm.struct<(f64, f64)>
func @complex_constant() -> complex<f64> {
%cplx2 = complex.constant [1.000000e+00, 2.000000e+00] : complex<f64>
return %cplx2 : complex<f64>
}
// CHECK-LABEL: func @complex_extract
// CHECK-SAME: (%[[CPLX:.*]]: complex<f32>)
// CHECK-NEXT: %[[CAST0:.*]] = builtin.unrealized_conversion_cast %[[CPLX]] : complex<f32> to !llvm.struct<(f32, f32)>