@@ -1006,38 +1006,47 @@ func.func @canonicalize_broadcast_shapecast_to_broadcast(%arg0: vector<3xf32>) -
10061006
10071007// -----
10081008
1009- // CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapecast
1010- // CHECK-NOT : vector.broadcast
1011- // CHECK: vector.shape_cast {{.+}} : vector<3x4xf32> to vector<1x12xf32>
1012- func.func @canonicalize_broadcast_shapecast_to_shapecast (%arg0: vector <3 x 4 x f32 >) -> vector <1 x 12 x f32 > {
1013- %0 = vector.broadcast %arg0 : vector <3 x 4 x f32 > to vector <1 x 1 x 3 x 4 x f32 >
1014- %1 = vector.shape_cast %0 : vector <1 x 1 x 3 x 4 x f32 > to vector <1 x 12 x f32 >
1015- return %1 : vector <1 x 12 x f32 >
1009+ // CHECK-LABEL: func @canonicalize_broadcast_ones_shapecast_to_broadcast_ones
1010+ // CHECK: vector.broadcast {{.*}} vector<1x1xi8> to vector<1x1x6x1x4xi8>
1011+ // CHECK-NOT : vector.shape_cast
1012+ func.func @canonicalize_broadcast_ones_shapecast_to_broadcast_ones (%arg0: vector <1 x 1 x i8 >) -> vector <1 x 1 x 6 x 1 x 4 x i8 > {
1013+ %0 = vector.broadcast %arg0 : vector <1 x 1 x i8 > to vector <6 x 4 x i8 >
1014+ %1 = vector.shape_cast %0 : vector <6 x 4 x i8 > to vector <1 x 1 x 6 x 1 x 4 x i8 >
1015+ return %1 : vector <1 x 1 x 6 x 1 x 4 x i8 >
10161016}
10171017
10181018// -----
10191019
1020-
1021- // CHECK-LABEL: func @canonicalize_broadcast_shapecast_scalar
1022- // CHECK: vector.broadcast
1023- // CHECK-SAME: f32 to vector<3x4x1xf32>
1020+ // CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_broadcast_scalar
1021+ // CHECK: vector.broadcast {{.*}} f32 to vector<3x4x1xf32>
10241022// CHECK-NOT: vector.shape_cast
1025- func.func @canonicalize_broadcast_shapecast_scalar (%arg0: f32 ) -> vector <3 x4 x1 xf32 > {
1023+ func.func @canonicalize_broadcast_shapecast_to_broadcast_scalar (%arg0: f32 ) -> vector <3 x4 x1 xf32 > {
10261024 %0 = vector.broadcast %arg0 : f32 to vector <12 xf32 >
10271025 %1 = vector.shape_cast %0 : vector <12 xf32 > to vector <3 x4 x1 xf32 >
10281026 return %1 : vector <3 x4 x1 xf32 >
10291027}
10301028
10311029// -----
10321030
1033- // CHECK-LABEL: func @canonicalize_broadcast_shapecast_ones
1034- // CHECK: vector.broadcast
1035- // CHECK-SAME: vector<1x1xi8> to vector<1x1x6x1x4xi8>
1036- // CHECK-NOT: vector.shape_cast
1037- func.func @canonicalize_broadcast_shapecast_ones (%arg0: vector <1 x1 xi8 >) -> vector <1 x1 x6 x1 x4 xi8 > {
1038- %0 = vector.broadcast %arg0 : vector <1 x1 xi8 > to vector <6 x4 xi8 >
1039- %1 = vector.shape_cast %0 : vector <6 x4 xi8 > to vector <1 x1 x6 x1 x4 xi8 >
1040- return %1 : vector <1 x1 x6 x1 x4 xi8 >
1031+ // CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapecast
1032+ // CHECK-NOT: vector.broadcast
1033+ // CHECK: vector.shape_cast {{.+}} : vector<3x4xf32> to vector<1x12xf32>
1034+ func.func @canonicalize_broadcast_shapecast_to_shapecast (%arg0: vector <3 x4 xf32 >) -> vector <1 x12 xf32 > {
1035+ %0 = vector.broadcast %arg0 : vector <3 x4 xf32 > to vector <1 x1 x3 x4 xf32 >
1036+ %1 = vector.shape_cast %0 : vector <1 x1 x3 x4 xf32 > to vector <1 x12 xf32 >
1037+ return %1 : vector <1 x12 xf32 >
1038+ }
1039+
1040+ // -----
1041+
1042+ // In this test, it could be folded to broadcast or shape_cast, shape_cast is chosen.
1043+ // CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapcast_priority
1044+ // CHECK-NOT: vector.broadcast
1045+ // CHECK: vector.shape_cast {{.+}} : vector<1xf32> to vector<1x1xf32>
1046+ func.func @canonicalize_broadcast_shapecast_to_shapcast_priority (%arg0 : vector <1 xf32 >) -> vector <1 x1 xf32 > {
1047+ %0 = vector.broadcast %arg0 : vector <1 xf32 > to vector <1 x1 x1 xf32 >
1048+ %1 = vector.shape_cast %0 : vector <1 x1 x1 xf32 > to vector <1 x1 xf32 >
1049+ return %1 : vector <1 x1 xf32 >
10411050}
10421051
10431052// -----
0 commit comments