[Mlir-commits] [mlir] [mlir][vector] Add foldInsertUseChain folder function to insert op (PR #147045)
Mehdi Amini
llvmlistbot at llvm.org
Mon Jul 7 02:27:17 PDT 2025
================
@@ -3446,3 +3446,68 @@ func.func @fold_insert_constant_indices(%arg : vector<4x1xi32>) -> vector<4x1xi3
%res = vector.insert %1, %arg[%0, %0] : i32 into vector<4x1xi32>
return %res : vector<4x1xi32>
}
+
+// -----
+
+// CHECK-LABEL: @fold_insert_use_chain_static_pos(
+// CHECK-SAME: %[[ARG:.*]]: vector<4xf32>,
+// CHECK-SAME: %[[VAL:.*]]: f32) -> vector<4xf32> {
+// CHECK: %[[RES:.*]] = vector.insert %[[VAL]], %[[ARG]] [0] : f32 into vector<4xf32>
+// CHECK: return %[[RES]] : vector<4xf32>
+func.func @fold_insert_use_chain_static_pos(%v : vector<4xf32>, %value : f32) -> vector<4xf32> {
+ %v_0 = vector.insert %value, %v[0] : f32 into vector<4xf32>
+ %v_1 = vector.insert %value, %v_0[0] : f32 into vector<4xf32>
+ %v_2 = vector.insert %value, %v_1[0] : f32 into vector<4xf32>
+ return %v_2 : vector<4xf32>
+}
+
+// -----
+
+// CHECK-LABEL: @fold_insert_use_chain_dynamic_pos(
+// CHECK-SAME: %[[ARG:.*]]: vector<4x4xf32>,
+// CHECK-SAME: %[[VAL:.*]]: f32,
+// CHECK-SAME: %[[POS:.*]]: index) -> vector<4x4xf32> {
+// CHECK: %[[RES:.*]] = vector.insert %[[VAL]], %[[ARG]] {{\[}}%[[POS]], 0] : f32 into vector<4x4xf32>
+// CHECK: return %[[RES]] : vector<4x4xf32>
+func.func @fold_insert_use_chain_dynamic_pos(%arg : vector<4x4xf32>, %value : f32, %pos: index) -> vector<4x4xf32> {
+ %v_0 = vector.insert %value, %arg[%pos, 0] : f32 into vector<4x4xf32>
+ %v_1 = vector.insert %value, %v_0[%pos, 0] : f32 into vector<4x4xf32>
+ %v_2 = vector.insert %value, %v_1[%pos, 0] : f32 into vector<4x4xf32>
+ return %v_2 : vector<4x4xf32>
+}
+
+// -----
+
+// CHECK-LABEL: @fold_insert_use_chain_add_float(
+// CHECK-SAME: %[[VEC_0:.*]]: vector<4xf32>,
+// CHECK-SAME: %[[VAL:.*]]: f32) -> vector<4xf32> {
+// CHECK: %[[VEC_1:.*]] = vector.insert %[[VAL]], %[[VEC_0]] [0] : f32 into vector<4xf32>
+// CHECK: %[[VEC_2:.*]] = arith.addf %[[VEC_1]], %[[VEC_1]] : vector<4xf32>
+// CHECK: %[[VEC_3:.*]] = vector.insert %[[VAL]], %[[VEC_0]] [0] : f32 into vector<4xf32>
+// CHECK: %[[VEC_4:.*]] = arith.addf %[[VEC_2]], %[[VEC_3]] : vector<4xf32>
+// CHECK: return %[[VEC_4]] : vector<4xf32>
+func.func @fold_insert_use_chain_add_float(%v : vector<4xf32>, %value : f32) -> vector<4xf32> {
----------------
joker-eph wrote:
The naming comment applies to the next test below though :)
https://github.com/llvm/llvm-project/pull/147045
More information about the Mlir-commits
mailing list