blob: 61163a704d643882911890d39b608776dc43c2fa [file] [log] [blame]
// RUN: mlir-opt %s -pass-pipeline='func(canonicalize)' -split-input-file | FileCheck %s
// -----
// CHECK-LABEL: create_vector_mask_to_constant_mask
func @create_vector_mask_to_constant_mask() -> (vector<4x3xi1>) {
%c2 = constant 2 : index
%c3 = constant 3 : index
// CHECK: vector.constant_mask [3, 2] : vector<4x3xi1>
%0 = vector.create_mask %c3, %c2 : vector<4x3xi1>
return %0 : vector<4x3xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x2xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [0, 0], sizes = [2, 2], strides = [1, 1]}
: vector<4x3xi1> to vector<2x2xi1>
// CHECK: vector.constant_mask [2, 2] : vector<2x2xi1>
return %1 : vector<2x2xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x2xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [1, 0], sizes = [2, 2], strides = [1, 1]}
: vector<4x3xi1> to vector<2x2xi1>
// CHECK: vector.constant_mask [1, 2] : vector<2x2xi1>
return %1 : vector<2x2xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x2xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [0, 1], sizes = [2, 2], strides = [1, 1]}
: vector<4x3xi1> to vector<2x2xi1>
// CHECK: vector.constant_mask [2, 1] : vector<2x2xi1>
return %1 : vector<2x2xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x2xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [2, 0], sizes = [2, 2], strides = [1, 1]}
: vector<4x3xi1> to vector<2x2xi1>
// CHECK: vector.constant_mask [0, 0] : vector<2x2xi1>
return %1 : vector<2x2xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x1xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [0, 2], sizes = [2, 1], strides = [1, 1]}
: vector<4x3xi1> to vector<2x1xi1>
// CHECK: vector.constant_mask [0, 0] : vector<2x1xi1>
return %1 : vector<2x1xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x1xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [0, 1], sizes = [2, 1], strides = [1, 1]}
: vector<4x3xi1> to vector<2x1xi1>
// CHECK: vector.constant_mask [2, 1] : vector<2x1xi1>
return %1 : vector<2x1xi1>
}
// -----
func @strided_slice_of_constant_mask() -> (vector<2x1xi1>) {
%0 = vector.constant_mask [2, 2] : vector<4x3xi1>
%1 = vector.strided_slice %0
{offsets = [1, 1], sizes = [2, 1], strides = [1, 1]}
: vector<4x3xi1> to vector<2x1xi1>
// CHECK: vector.constant_mask [1, 1] : vector<2x1xi1>
return %1 : vector<2x1xi1>
}
// -----
// CHECK-LABEL: transpose_1D_identity
// CHECK-SAME: ([[ARG:%.*]]: vector<4xf32>)
func @transpose_1D_identity(%arg : vector<4xf32>) -> vector<4xf32> {
// CHECK-NOT: transpose
%0 = vector.transpose %arg, [0] : vector<4xf32> to vector<4xf32>
// CHECK-NEXT: return [[ARG]]
return %0 : vector<4xf32>
}
// -----
// CHECK-LABEL: transpose_2D_identity
// CHECK-SAME: ([[ARG:%.*]]: vector<4x3xf32>)
func @transpose_2D_identity(%arg : vector<4x3xf32>) -> vector<4x3xf32> {
// CHECK-NOT: transpose
%0 = vector.transpose %arg, [0, 1] : vector<4x3xf32> to vector<4x3xf32>
// CHECK-NEXT: return [[ARG]]
return %0 : vector<4x3xf32>
}
// -----
// CHECK-LABEL: transpose_3D_identity
// CHECK-SAME: ([[ARG:%.*]]: vector<4x3x2xf32>)
func @transpose_3D_identity(%arg : vector<4x3x2xf32>) -> vector<4x3x2xf32> {
// CHECK-NOT: transpose
%0 = vector.transpose %arg, [0, 1, 2] : vector<4x3x2xf32> to vector<4x3x2xf32>
// CHECK-NEXT: return [[ARG]]
return %0 : vector<4x3x2xf32>
}
// -----
// CHECK-LABEL: transpose_2D_sequence
// CHECK-SAME: ([[ARG:%.*]]: vector<4x3xf32>)
func @transpose_2D_sequence(%arg : vector<4x3xf32>) -> vector<4x3xf32> {
// CHECK-NOT: transpose
%0 = vector.transpose %arg, [1, 0] : vector<4x3xf32> to vector<3x4xf32>
%1 = vector.transpose %0, [0, 1] : vector<3x4xf32> to vector<3x4xf32>
%2 = vector.transpose %1, [1, 0] : vector<3x4xf32> to vector<4x3xf32>
%3 = vector.transpose %2, [0, 1] : vector<4x3xf32> to vector<4x3xf32>
// CHECK: [[ADD:%.*]] = addf [[ARG]], [[ARG]]
%4 = addf %2, %3 : vector<4x3xf32>
// CHECK-NEXT: return [[ADD]]
return %4 : vector<4x3xf32>
}
// -----
// CHECK-LABEL: transpose_3D_sequence
// CHECK-SAME: ([[ARG:%.*]]: vector<4x3x2xf32>)
func @transpose_3D_sequence(%arg : vector<4x3x2xf32>) -> vector<4x3x2xf32> {
// CHECK: [[T0:%.*]] = vector.transpose [[ARG]], [2, 1, 0]
%0 = vector.transpose %arg, [1, 2, 0] : vector<4x3x2xf32> to vector<3x2x4xf32>
%1 = vector.transpose %0, [1, 0, 2] : vector<3x2x4xf32> to vector<2x3x4xf32>
// CHECK-NOT: transpose
%2 = vector.transpose %1, [2, 1, 0] : vector<2x3x4xf32> to vector<4x3x2xf32>
%3 = vector.transpose %2, [2, 1, 0] : vector<4x3x2xf32> to vector<2x3x4xf32>
// CHECK: [[MUL:%.*]] = mulf [[T0]], [[T0]]
%4 = mulf %1, %3 : vector<2x3x4xf32>
// CHECK: [[T5:%.*]] = vector.transpose [[MUL]], [2, 1, 0]
%5 = vector.transpose %4, [2, 1, 0] : vector<2x3x4xf32> to vector<4x3x2xf32>
// CHECK-NOT: transpose
%6 = vector.transpose %3, [2, 1, 0] : vector<2x3x4xf32> to vector<4x3x2xf32>
// CHECK: [[ADD:%.*]] = addf [[T5]], [[ARG]]
%7 = addf %5, %6 : vector<4x3x2xf32>
// CHECK-NEXT: return [[ADD]]
return %7 : vector<4x3x2xf32>
}