180e0bf1aSharsh// RUN: mlir-opt %s --test-vector-scan-lowering | FileCheck %s 280e0bf1aSharsh 380e0bf1aSharsh// CHECK-LABEL: func @scan1d_inc 480e0bf1aSharsh// CHECK-SAME: %[[ARG0:.*]]: vector<2xi32>, 580e0bf1aSharsh// CHECK-SAME: %[[ARG1:.*]]: vector<i32> 680e0bf1aSharsh// CHECK: %[[A:.*]] = arith.constant dense<0> : vector<2xi32> 780e0bf1aSharsh// CHECK: %[[B:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0], sizes = [1], strides = [1]} : vector<2xi32> to vector<1xi32> 880e0bf1aSharsh// CHECK: %[[C:.*]] = vector.insert_strided_slice %[[B]], %[[A]] {offsets = [0], strides = [1]} : vector<1xi32> into vector<2xi32> 980e0bf1aSharsh// CHECK: %[[D:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [1], sizes = [1], strides = [1]} : vector<2xi32> to vector<1xi32> 1080e0bf1aSharsh// CHECK: %[[E:.*]] = arith.addi %[[B]], %[[D]] : vector<1xi32> 1180e0bf1aSharsh// CHECK: %[[F:.*]] = vector.insert_strided_slice %[[E]], %[[C]] {offsets = [1], strides = [1]} : vector<1xi32> into vector<2xi32> 12*9816edc9SCullen Rhodes// CHECK: %[[G:.*]] = vector.extract %[[E]][0] : i32 from vector<1xi32> 1380e0bf1aSharsh// CHECK: %[[H:.*]] = vector.broadcast %[[G]] : i32 to vector<i32> 1480e0bf1aSharsh// CHECK: return %[[F]], %[[H]] : vector<2xi32>, vector<i32> 15c48e3a13SRiver Riddlefunc.func @scan1d_inc(%arg0 : vector<2xi32>, %arg1 : vector<i32>) -> (vector<2xi32>, vector<i32>) { 1680e0bf1aSharsh %0:2 = vector.scan <add>, %arg0, %arg1 {inclusive = true, reduction_dim = 0} : 1780e0bf1aSharsh vector<2xi32>, vector<i32> 1880e0bf1aSharsh return %0#0, %0#1 : vector<2xi32>, vector<i32> 1980e0bf1aSharsh} 2080e0bf1aSharsh 2180e0bf1aSharsh// CHECK-LABEL: func @scan1d_exc 2280e0bf1aSharsh// CHECK-SAME: %[[ARG0:.*]]: vector<2xi32>, 2380e0bf1aSharsh// CHECK-SAME: %[[ARG1:.*]]: vector<i32> 2480e0bf1aSharsh// CHECK: %[[A:.*]] = arith.constant dense<0> : vector<2xi32> 2580e0bf1aSharsh// CHECK: %[[B:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0], sizes = [1], strides = [1]} : vector<2xi32> to vector<1xi32> 2680e0bf1aSharsh// CHECK: %[[C:.*]] = vector.broadcast %[[ARG1]] : vector<i32> to vector<1xi32> 2780e0bf1aSharsh// CHECK: %[[D:.*]] = vector.insert_strided_slice %[[C]], %[[A]] {offsets = [0], strides = [1]} : vector<1xi32> into vector<2xi32> 2880e0bf1aSharsh// CHECK: %[[E:.*]] = arith.addi %[[C]], %[[B]] : vector<1xi32> 2980e0bf1aSharsh// CHECK: %[[F:.*]] = vector.insert_strided_slice %[[E]], %[[D]] {offsets = [1], strides = [1]} : vector<1xi32> into vector<2xi32> 30*9816edc9SCullen Rhodes// CHECK: %[[G:.*]] = vector.extract %[[E]][0] : i32 from vector<1xi32> 3180e0bf1aSharsh// CHECK: %[[H:.*]] = vector.broadcast %[[G]] : i32 to vector<i32> 3280e0bf1aSharsh// CHECK: return %[[F]], %[[H]] : vector<2xi32>, vector<i32> 33c48e3a13SRiver Riddlefunc.func @scan1d_exc(%arg0 : vector<2xi32>, %arg1 : vector<i32>) -> (vector<2xi32>, vector<i32>) { 3480e0bf1aSharsh %0:2 = vector.scan <add>, %arg0, %arg1 {inclusive = false, reduction_dim = 0} : 3580e0bf1aSharsh vector<2xi32>, vector<i32> 3680e0bf1aSharsh return %0#0, %0#1 : vector<2xi32>, vector<i32> 3780e0bf1aSharsh} 3880e0bf1aSharsh 3980e0bf1aSharsh// CHECK-LABEL: func @scan2d_mul_dim0 4080e0bf1aSharsh// CHECK-SAME: %[[ARG0:.*]]: vector<2x3xi32>, 4180e0bf1aSharsh// CHECK-SAME: %[[ARG1:.*]]: vector<3xi32> 4280e0bf1aSharsh// CHECK: %[[A:.*]] = arith.constant dense<0> : vector<2x3xi32> 4380e0bf1aSharsh// CHECK: %[[B:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0, 0], sizes = [1, 3], strides = [1, 1]} : vector<2x3xi32> to vector<1x3xi32> 4480e0bf1aSharsh// CHECK: %[[C:.*]] = vector.insert_strided_slice %[[B]], %[[A]] {offsets = [0, 0], strides = [1, 1]} : vector<1x3xi32> into vector<2x3xi32> 4580e0bf1aSharsh// CHECK: %[[D:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [1, 0], sizes = [1, 3], strides = [1, 1]} : vector<2x3xi32> to vector<1x3xi32> 4680e0bf1aSharsh// CHECK: %[[E:.*]] = arith.muli %[[B]], %[[D]] : vector<1x3xi32> 4780e0bf1aSharsh// CHECK: %[[F:.*]] = vector.insert_strided_slice %[[E]], %[[C]] {offsets = [1, 0], strides = [1, 1]} : vector<1x3xi32> into vector<2x3xi32> 4880e0bf1aSharsh// CHECK: %[[G:.*]] = vector.shape_cast %[[E]] : vector<1x3xi32> to vector<3xi32> 4980e0bf1aSharsh// CHECK: return %[[F]], %[[G]] : vector<2x3xi32>, vector<3xi32> 50c48e3a13SRiver Riddlefunc.func @scan2d_mul_dim0(%arg0 : vector<2x3xi32>, %arg1 : vector<3xi32>) -> (vector<2x3xi32>, vector<3xi32>) { 5180e0bf1aSharsh %0:2 = vector.scan <mul>, %arg0, %arg1 {inclusive = true, reduction_dim = 0} : 5280e0bf1aSharsh vector<2x3xi32>, vector<3xi32> 5380e0bf1aSharsh return %0#0, %0#1 : vector<2x3xi32>, vector<3xi32> 5480e0bf1aSharsh} 5580e0bf1aSharsh 5680e0bf1aSharsh// CHECK-LABEL: func @scan2d_mul_dim1 5780e0bf1aSharsh// CHECK-SAME: %[[ARG0:.*]]: vector<2x3xi32>, 5880e0bf1aSharsh// CHECK-SAME: %[[ARG1:.*]]: vector<2xi32> 5980e0bf1aSharsh// CHECK: %[[A:.*]] = arith.constant dense<0> : vector<2x3xi32> 6080e0bf1aSharsh// CHECK: %[[B:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0, 0], sizes = [2, 1], strides = [1, 1]} : vector<2x3xi32> to vector<2x1xi32> 6180e0bf1aSharsh// CHECK: %[[C:.*]] = vector.insert_strided_slice %[[B]], %[[A]] {offsets = [0, 0], strides = [1, 1]} : vector<2x1xi32> into vector<2x3xi32> 6280e0bf1aSharsh// CHECK: %[[D:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0, 1], sizes = [2, 1], strides = [1, 1]} : vector<2x3xi32> to vector<2x1xi32> 6380e0bf1aSharsh// CHECK: %[[E:.*]] = arith.muli %[[B]], %[[D]] : vector<2x1xi32> 6480e0bf1aSharsh// CHECK: %[[F:.*]] = vector.insert_strided_slice %[[E]], %[[C]] {offsets = [0, 1], strides = [1, 1]} : vector<2x1xi32> into vector<2x3xi32> 6580e0bf1aSharsh// CHECK: %[[G:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0, 2], sizes = [2, 1], strides = [1, 1]} : vector<2x3xi32> to vector<2x1xi32> 6680e0bf1aSharsh// CHECK: %[[H:.*]] = arith.muli %[[E]], %[[G]] : vector<2x1xi32> 6780e0bf1aSharsh// CHECK: %[[I:.*]] = vector.insert_strided_slice %[[H]], %[[F]] {offsets = [0, 2], strides = [1, 1]} : vector<2x1xi32> into vector<2x3xi32> 6880e0bf1aSharsh// CHECK: %[[J:.*]] = vector.shape_cast %[[H]] : vector<2x1xi32> to vector<2xi32> 6980e0bf1aSharsh// CHECK: return %[[I]], %[[J]] : vector<2x3xi32>, vector<2xi32> 70c48e3a13SRiver Riddlefunc.func @scan2d_mul_dim1(%arg0 : vector<2x3xi32>, %arg1 : vector<2xi32>) -> (vector<2x3xi32>, vector<2xi32>) { 7180e0bf1aSharsh %0:2 = vector.scan <mul>, %arg0, %arg1 {inclusive = true, reduction_dim = 1} : 7280e0bf1aSharsh vector<2x3xi32>, vector<2xi32> 7380e0bf1aSharsh return %0#0, %0#1 : vector<2x3xi32>, vector<2xi32> 7480e0bf1aSharsh} 7580e0bf1aSharsh 7680e0bf1aSharsh// CHECK-LABEL: func @scan3d_mul_dim1 7780e0bf1aSharsh// CHECK-SAME: %[[ARG0:.*]]: vector<4x2x3xf32>, 7880e0bf1aSharsh// CHECK-SAME: %[[ARG1:.*]]: vector<4x3xf32> 7980e0bf1aSharsh// CHECK: %[[A:.*]] = arith.constant dense<0.000000e+00> : vector<4x2x3xf32> 8080e0bf1aSharsh// CHECK: %[[B:.*]] = vector.extract_strided_slice %[[ARG0]] {offsets = [0, 0, 0], sizes = [4, 1, 3], strides = [1, 1, 1]} : vector<4x2x3xf32> to vector<4x1x3xf32> 8180e0bf1aSharsh// CHECK: %[[C:.*]] = vector.shape_cast %[[ARG1]] : vector<4x3xf32> to vector<4x1x3xf32> 8280e0bf1aSharsh// CHECK: %[[D:.*]] = vector.insert_strided_slice %[[C]], %[[A]] {offsets = [0, 0, 0], strides = [1, 1, 1]} : vector<4x1x3xf32> into vector<4x2x3xf32> 8380e0bf1aSharsh// CHECK: %[[E:.*]] = arith.mulf %[[C]], %[[B]] : vector<4x1x3xf32> 8480e0bf1aSharsh// CHECK: %[[F:.*]] = vector.insert_strided_slice %[[E]], %[[D]] {offsets = [0, 1, 0], strides = [1, 1, 1]} : vector<4x1x3xf32> into vector<4x2x3xf32> 8580e0bf1aSharsh// CHECK: %[[G:.*]] = vector.shape_cast %[[E]] : vector<4x1x3xf32> to vector<4x3xf32> 8680e0bf1aSharsh// CHECK: return %[[F]], %[[G]] : vector<4x2x3xf32>, vector<4x3xf32> 87c48e3a13SRiver Riddlefunc.func @scan3d_mul_dim1(%arg0 : vector<4x2x3xf32>, %arg1 : vector<4x3xf32>) -> (vector<4x2x3xf32>, vector<4x3xf32>) { 8880e0bf1aSharsh %0:2 = vector.scan <mul>, %arg0, %arg1 {inclusive = false, reduction_dim = 1} : 8980e0bf1aSharsh vector<4x2x3xf32>, vector<4x3xf32> 9080e0bf1aSharsh return %0#0, %0#1 : vector<4x2x3xf32>, vector<4x3xf32> 9180e0bf1aSharsh} 92