[Mlir-commits] [mlir] [mlir][vector] Prevent folding of OOB values in insert/extract (PR #135498)
Jakub Kuderski
llvmlistbot at llvm.org
Sat Apr 12 19:00:31 PDT 2025
================
@@ -3233,3 +3233,41 @@ 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 that out of bounds indices are not folded for vector.insert
+
+// CHECK-LABEL: @fold_insert_oob
+// CHECK-SAME: %[[ARG:.*]]: vector<4x1x2xi32>) -> vector<4x1x2xi32> {
+// CHECK: %[[OOB1:.*]] = arith.constant -2 : index
+// CHECK: %[[OOB2:.*]] = arith.constant 2 : index
+// CHECK: %[[VAL:.*]] = arith.constant 1 : i32
+// CHECK: %[[RES:.*]] = vector.insert %[[VAL]], %[[ARG]] [0, %[[OOB1]], %[[OOB2]]] : i32 into vector<4x1x2xi32>
+// CHECK: return %[[RES]] : vector<4x1x2xi32>
+func.func @fold_insert_oob(%arg : vector<4x1x2xi32>) -> vector<4x1x2xi32> {
+ %0 = arith.constant 0 : index
+ %-2 = arith.constant -2 : index
+ %2 = arith.constant 2 : index
+ %1 = arith.constant 1 : i32
+ %res = vector.insert %1, %arg[%0, %-2, %2] : i32 into vector<4x1x2xi32>
+ return %res : vector<4x1x2xi32>
+}
+
+// -----
+
+// Check that out of bounds indices are not folded for vector.extract
----------------
kuhar wrote:
```suggestion
// Check that out of bounds indices are not folded for vector.extract.
```
https://github.com/llvm/llvm-project/pull/135498
More information about the Mlir-commits
mailing list