diff --git a/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp b/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp --- a/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp +++ b/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp @@ -78,6 +78,18 @@ } }; +struct ConstantOpLowering : public ConvertOpToLLVMPattern { + 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 { using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern; @@ -294,6 +306,7 @@ patterns.add< AbsOpConversion, AddOpConversion, + ConstantOpLowering, CreateOpConversion, DivOpConversion, ImOpConversion, diff --git a/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir b/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir --- a/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir +++ b/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir @@ -10,6 +10,13 @@ return %cplx2 : complex } +// CHECK-LABEL: func @complex_constant +// CHECK-NEXT: llvm.mlir.constant([1.000000e+00, 2.000000e+00]) : !llvm.struct<(f64, f64)> +func @complex_constant() -> complex { + %cplx2 = complex.constant [1.000000e+00, 2.000000e+00] : complex + return %cplx2 : complex +} + // CHECK-LABEL: func @complex_extract // CHECK-SAME: (%[[CPLX:.*]]: complex) // CHECK-NEXT: %[[CAST0:.*]] = builtin.unrealized_conversion_cast %[[CPLX]] : complex to !llvm.struct<(f32, f32)>