@@ -1028,25 +1028,26 @@ func.func @canonicalize_broadcast_shapecast_to_broadcast_scalar(%arg0: f32) -> v
10281028
10291029// -----
10301030
1031- // CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapecast
1031+ // In this test, broadcast (2)->(1,2,1) is not legal, but shape_cast (2)->(1,2,1) is.
1032+ // CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapcast
10321033// 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 x 4 x f32 >) -> vector <1 x 12 x f32 > {
1035- %0 = vector.broadcast %arg0 : vector <3 x 4 x f32 > to vector <1 x 1 x 3 x 4 x f32 >
1036- %1 = vector.shape_cast %0 : vector <1 x 1 x 3 x 4 x f32 > to vector <1 x 12 x f32 >
1037- return %1 : vector <1 x 12 x f32 >
1034+ // CHECK: vector.shape_cast {{.+}} : vector<2xf32 > to vector<1x2x1xf32 >
1035+ func.func @canonicalize_broadcast_shapecast_to_shapcast (%arg0 : vector <2 x f32 >) -> vector <1 x 2 x 1 x f32 > {
1036+ %0 = vector.broadcast %arg0 : vector <2 x f32 > to vector <1 x 2 x f32 >
1037+ %1 = vector.shape_cast %0 : vector <1 x 2 x f32 > to vector <1 x 2 x 1 x f32 >
1038+ return %1 : vector <1 x 2 x 1 x f32 >
10381039}
10391040
10401041// -----
10411042
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
1043+ // In this test, broadcast (1)->(1,1) and shape_cast (1)->(1,1) are both legal. shape_cast is chosen.
1044+ // CHECK-LABEL: func @canonicalize_broadcast_shapecast_both_possible
10441045// CHECK-NOT: vector.broadcast
10451046// 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 >
1047+ func.func @canonicalize_broadcast_shapecast_both_possible (%arg0: vector <1 xf32 >) -> vector <1 x1 xf32 > {
1048+ %0 = vector.broadcast %arg0 : vector <1 xf32 > to vector <1 x1 x1 xf32 >
1049+ %1 = vector.shape_cast %0 : vector <1 x1 x1 xf32 > to vector <1 x1 xf32 >
1050+ return %1 : vector <1 x1 xf32 >
10501051}
10511052
10521053// -----
0 commit comments