@@ -3449,14 +3449,65 @@ func.func @fold_insert_constant_indices(%arg : vector<4x1xi32>) -> vector<4x1xi3
34493449
34503450// -----
34513451
3452- // CHECK-LABEL: @insert_insert_to_insert (
3452+ // CHECK-LABEL: @fold_insert_use_chain_static_pos (
34533453// CHECK-SAME: %[[ARG:.*]]: vector<4xf32>,
34543454// CHECK-SAME: %[[VAL:.*]]: f32) -> vector<4xf32> {
34553455// CHECK: %[[RES:.*]] = vector.insert %[[VAL]], %[[ARG]] [0] : f32 into vector<4xf32>
34563456// CHECK: return %[[RES]] : vector<4xf32>
3457- func.func @insert_insert_to_insert (%v : vector <4 xf32 >, %value : f32 ) -> vector <4 xf32 > {
3457+ func.func @fold_insert_use_chain_static_pos (%v : vector <4 xf32 >, %value : f32 ) -> vector <4 xf32 > {
34583458 %v_0 = vector.insert %value , %v [0 ] : f32 into vector <4 xf32 >
34593459 %v_1 = vector.insert %value , %v_0 [0 ] : f32 into vector <4 xf32 >
34603460 %v_2 = vector.insert %value , %v_1 [0 ] : f32 into vector <4 xf32 >
34613461 return %v_2 : vector <4 xf32 >
34623462}
3463+
3464+ // -----
3465+
3466+ // CHECK-LABEL: @fold_insert_use_chain_dynamic_pos(
3467+ // CHECK-SAME: %[[ARG:.*]]: vector<4x4xf32>,
3468+ // CHECK-SAME: %[[VAL:.*]]: f32,
3469+ // CHECK-SAME: %[[POS:.*]]: index) -> vector<4x4xf32> {
3470+ // CHECK: %[[RES:.*]] = vector.insert %[[VAL]], %[[ARG]] {{\[}}%[[POS]], 0] : f32 into vector<4x4xf32>
3471+ // CHECK: return %[[RES]] : vector<4x4xf32>
3472+ func.func @fold_insert_use_chain_dynamic_pos (%arg : vector <4 x4 xf32 >, %value : f32 , %pos: index ) -> vector <4 x4 xf32 > {
3473+ %v_0 = vector.insert %value , %arg [%pos , 0 ] : f32 into vector <4 x4 xf32 >
3474+ %v_1 = vector.insert %value , %v_0 [%pos , 0 ] : f32 into vector <4 x4 xf32 >
3475+ %v_2 = vector.insert %value , %v_1 [%pos , 0 ] : f32 into vector <4 x4 xf32 >
3476+ return %v_2 : vector <4 x4 xf32 >
3477+ }
3478+
3479+ // -----
3480+
3481+ // CHECK-LABEL: @fold_insert_use_chain_add_float(
3482+ // CHECK-SAME: %[[VEC_0:.*]]: vector<4xf32>,
3483+ // CHECK-SAME: %[[VAL:.*]]: f32) -> vector<4xf32> {
3484+ // CHECK: %[[VEC_1:.*]] = vector.insert %[[VAL]], %[[VEC_0]] [0] : f32 into vector<4xf32>
3485+ // CHECK: %[[VEC_2:.*]] = arith.addf %[[VEC_1]], %[[VEC_1]] : vector<4xf32>
3486+ // CHECK: %[[VEC_3:.*]] = vector.insert %[[VAL]], %[[VEC_0]] [0] : f32 into vector<4xf32>
3487+ // CHECK: %[[VEC_4:.*]] = arith.addf %[[VEC_2]], %[[VEC_3]] : vector<4xf32>
3488+ // CHECK: return %[[VEC_4]] : vector<4xf32>
3489+ func.func @fold_insert_use_chain_add_float (%v : vector <4 xf32 >, %value : f32 ) -> vector <4 xf32 > {
3490+ %v_0 = vector.insert %value , %v [0 ] : f32 into vector <4 xf32 >
3491+ %v_1 = arith.addf %v_0 , %v_0 : vector <4 xf32 >
3492+ %v_2 = vector.insert %value , %v_0 [0 ] : f32 into vector <4 xf32 >
3493+ %v_3 = arith.addf %v_1 , %v_2 : vector <4 xf32 >
3494+ return %v_3 : vector <4 xf32 >
3495+ }
3496+
3497+ // -----
3498+
3499+ // CHECK-LABEL: @fold_insert_use_chain_add_float_pos_mismatch(
3500+ // CHECK-SAME: %[[VEC_0:.*]]: vector<4xf32>,
3501+ // CHECK-SAME: %[[VAL:.*]]: f32) -> vector<4xf32> {
3502+ // CHECK: %[[VEC_1:.*]] = vector.insert %[[VAL]], %[[VEC_0]] [0] : f32 into vector<4xf32>
3503+ // CHECK: %[[VEC_2:.*]] = arith.addf %[[VEC_1]], %[[VEC_1]] : vector<4xf32>
3504+ // CHECK: %[[VEC_3:.*]] = vector.insert %[[VAL]], %[[VEC_1]] [1] : f32 into vector<4xf32>
3505+ // CHECK: %[[VEC_4:.*]] = arith.addf %[[VEC_2]], %[[VEC_3]] : vector<4xf32>
3506+ // CHECK: return %[[VEC_4]] : vector<4xf32>
3507+ func.func @fold_insert_use_chain_add_float_pos_mismatch (%v : vector <4 xf32 >, %value : f32 ) -> vector <4 xf32 > {
3508+ %v_0 = vector.insert %value , %v [0 ] : f32 into vector <4 xf32 >
3509+ %v_1 = arith.addf %v_0 , %v_0 : vector <4 xf32 >
3510+ %v_2 = vector.insert %value , %v_0 [1 ] : f32 into vector <4 xf32 >
3511+ %v_3 = arith.addf %v_1 , %v_2 : vector <4 xf32 >
3512+ return %v_3 : vector <4 xf32 >
3513+ }
0 commit comments