[Mlir-commits] [mlir] [MLIR][SCCP] Fix in-place folds leaking into IR during simulation (PR #213933)
Tobias Gysi
llvmlistbot at llvm.org
Tue Aug 4 07:31:40 PDT 2026
================
@@ -335,3 +335,52 @@ func.func @fold_to_non_operand_value(%x: i64, %cond: i1) -> i64 {
%cast2 = builtin.unrealized_conversion_cast %cast1 : index to i64
return %cast2 : i64
}
+
+// -----
+
+// Regression test: SCCP must revert in-place folds. The `vector.extract`
+// folder rewrites a constant dynamic position into a static one in place, but
+// the constants SCCP feeds into `fold` are speculative: on the first visit of
+// ^bb1 %iv is Constant 0, before the back edge widens it to overdefined.
+// Without the revert, the dynamic extract would permanently read element 0.
+
+// CHECK-LABEL: func @no_inplace_extract_fold_of_speculative_constant
+func.func @no_inplace_extract_fold_of_speculative_constant(%a: f32, %b: f32) -> f32 {
+ %c0_i32 = arith.constant 0 : i32
+ %c1_i32 = arith.constant 1 : i32
+ %c2_i32 = arith.constant 2 : i32
+ %v = vector.from_elements %a, %b : vector<2xf32>
+ cf.br ^bb1(%c0_i32 : i32)
+^bb1(%iv: i32):
+ %idx = arith.index_cast %iv : i32 to index
+ // CHECK: vector.extract %{{.*}}[%{{.*}}] : f32 from vector<2xf32>
----------------
gysit wrote:
nit: can you add check lines for the index so that it is a bit clearer that this is not a constant.
https://github.com/llvm/llvm-project/pull/213933
More information about the Mlir-commits
mailing list