[Mlir-commits] [mlir] 608cc6b - [mlir][complex] Lower complex.constant to LLVM

Benjamin Kramer llvmlistbot at llvm.org
Thu Jan 27 04:49:35 PST 2022


Author: Benjamin Kramer
Date: 2022-01-27T13:48:23+01:00
New Revision: 608cc6b16394b6a2fb2a9555232f35ad58beb0a3

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

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

This fixes a regression from 480cd4cb8560532e544fc0c234749912dde759c6

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

Added: 
    

Modified: 
    mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp
    mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp b/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp
index 592d1839f8f83..c061495fda0b4 100644
--- a/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp
+++ b/mlir/lib/Conversion/ComplexToLLVM/ComplexToLLVM.cpp
@@ -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,

diff  --git a/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir b/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir
index 6b3fd20fa15f2..0abc375f4ed6a 100644
--- a/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir
+++ b/mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir
@@ -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)>


        


More information about the Mlir-commits mailing list