Files
clang-p2996/mlir/test/Dialect/Complex/canonicalize.mlir
River Riddle 480cd4cb85 [mlir] Move the complex support of std.constant to a new complex.constant operation
This is part of splitting up the standard dialect.

Differential Revision: https://reviews.llvm.org/D118182
2022-01-26 11:52:00 -08:00

65 lines
2.4 KiB
MLIR

// RUN: mlir-opt %s -canonicalize | FileCheck %s
// CHECK-LABEL: func @create_of_real_and_imag
// CHECK-SAME: (%[[CPLX:.*]]: complex<f32>)
func @create_of_real_and_imag(%cplx: complex<f32>) -> complex<f32> {
// CHECK-NEXT: return %[[CPLX]] : complex<f32>
%real = complex.re %cplx : complex<f32>
%imag = complex.im %cplx : complex<f32>
%complex = complex.create %real, %imag : complex<f32>
return %complex : complex<f32>
}
// CHECK-LABEL: func @create_of_real_and_imag_different_operand
// CHECK-SAME: (%[[CPLX:.*]]: complex<f32>, %[[CPLX2:.*]]: complex<f32>)
func @create_of_real_and_imag_different_operand(
%cplx: complex<f32>, %cplx2 : complex<f32>) -> complex<f32> {
// CHECK-NEXT: %[[REAL:.*]] = complex.re %[[CPLX]] : complex<f32>
// CHECK-NEXT: %[[IMAG:.*]] = complex.im %[[CPLX2]] : complex<f32>
// CHECK-NEXT: %[[COMPLEX:.*]] = complex.create %[[REAL]], %[[IMAG]] : complex<f32>
%real = complex.re %cplx : complex<f32>
%imag = complex.im %cplx2 : complex<f32>
%complex = complex.create %real, %imag : complex<f32>
return %complex: complex<f32>
}
// CHECK-LABEL: func @real_of_const(
func @real_of_const() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 1.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%complex = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%1 = complex.re %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @real_of_create_op(
func @real_of_create_op() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 1.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%real = arith.constant 1.0 : f32
%imag = arith.constant 0.0 : f32
%complex = complex.create %real, %imag : complex<f32>
%1 = complex.re %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @imag_of_const(
func @imag_of_const() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%complex = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
%1 = complex.im %complex : complex<f32>
return %1 : f32
}
// CHECK-LABEL: func @imag_of_create_op(
func @imag_of_create_op() -> f32 {
// CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
// CHECK-NEXT: return %[[CST]] : f32
%real = arith.constant 1.0 : f32
%imag = arith.constant 0.0 : f32
%complex = complex.create %real, %imag : complex<f32>
%1 = complex.im %complex : complex<f32>
return %1 : f32
}