[Mlir-commits] [mlir] Fix remove dead values poison crash (PR #205966)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jun 25 23:47:18 PDT 2026
https://github.com/LouisLu060211 updated https://github.com/llvm/llvm-project/pull/205966
>From 58d1f2667a6802d0a232dfe8d575e210e1e0f8b9 Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Wed, 24 Jun 2026 15:09:36 +0800
Subject: [PATCH 1/2] Fix crash in vectorizeOpPrecondition when vector sizes
array is too short
[MLIR][Vector] Add regression test for bug #204100 (mixed static/dynamic vector sizes)
Remove accidentally created file vectorize-dynamic-mixed-sizes.mlir
Remove mlir_venv/ from .gitignore (directory already deleted)
Fix comment about regression test location in Vectorization.cpp
Correct the path in the comment from .../Linalg/transform/... to .../Linalg/...
(the test actually lives directly under Linalg). Also update the
related vector-to-llvm test for consistency.
remove venv
Remove lldb/python_api from .gitignore
Fix emitSilenceableFailure to use target->getLoc()
Fixing comments
Fix a.mlir crash
[mlir][RemoveDeadValues] Fix crash replacing dead operand with poison
updated
updated minor changes
---
mlir/lib/Transforms/RemoveDeadValues.cpp | 20 ++++++++++------
.../Vector/transform-op-vector-to-llvm.mlir | 2 +-
mlir/test/Transforms/remove-dead-values.mlir | 23 +++++++++++++++++++
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index f0a210a2ededb..ae46630c949de 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -520,14 +520,20 @@ static void processBranchOp(BranchOpInterface branchOp, RunLivenessAnalysis &la,
}
}
+/// Create ub.poison ops for the given values. If a value has no uses, return
+/// an "empty" value.
+static Value createPoisonedValue(OpBuilder &b, Value value) {
+ if (!value || value.use_empty())
+ return Value();
+ return ub::PoisonOp::create(b, value.getLoc(), value.getType()).getResult();
+}
+
/// Create ub.poison ops for the given values. If a value has no uses, return
/// an "empty" value.
static SmallVector<Value> createPoisonedValues(OpBuilder &b,
ValueRange values) {
- return llvm::map_to_vector(values, [&](Value value) {
- if (value.use_empty())
- return Value();
- return ub::PoisonOp::create(b, value.getLoc(), value.getType()).getResult();
+ return llvm::map_to_vector(values, [&](Value value) -> Value {
+ return createPoisonedValue(b, value);
});
}
@@ -689,9 +695,9 @@ static void cleanUpDeadVals(MLIRContext *ctx, RDVFinalCleanupList &list) {
if (o.replaceWithPoison) {
rewriter.setInsertionPoint(o.op);
for (auto deadIdx : o.nonLive.set_bits()) {
- o.op->setOperand(
- deadIdx, createPoisonedValues(rewriter, o.op->getOperand(deadIdx))
- .front());
+ Value poisoned = createPoisonedValue(rewriter, o.op->getOperand(deadIdx));
+ if (poisoned)
+ o.op->setOperand(deadIdx, poisoned);
}
} else {
o.op->eraseOperands(o.nonLive);
diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
index 271cdf0e059f4..1a3b38158a262 100644
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
@@ -18,4 +18,4 @@ module attributes {transform.with_named_sequence} {
} {legal_dialects = ["func", "llvm"]} : !transform.any_op
transform.yield
}
-}
+}
\ No newline at end of file
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 64088ce15cd48..bbed2dc2e2feb 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -868,3 +868,26 @@ module @func_with_non_call_users {
}
spirv.EntryPoint "GLCompute" @callee
}
+
+// -----
+
+// CHECK: pdl_interp.func private @matcher()
+// CHECK-LABEL: func.func private @callee()
+// CHECK: return
+module {
+ pdl_interp.func private @matcher(%arg0: !llvm.ptr) {
+ pdl_interp.finalize
+ }
+ module @rewriters {
+ }
+ func.func private @callee(%arg0: memref<f32>) -> memref<f32> {
+ %false = arith.constant false
+ %0 = scf.if %false -> (memref<f32>) {
+ scf.yield %arg0 : memref<f32>
+ } else {
+ %1 = bufferization.clone %arg0 : memref<f32> to memref<f32>
+ scf.yield %1 : memref<f32>
+ }
+ return %0 : memref<f32>
+ }
+}
>From 2dfa90aaab3542422b1e42e40557575470870a53 Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Fri, 26 Jun 2026 14:46:54 +0800
Subject: [PATCH 2/2] minnor issues
---
mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
index 1a3b38158a262..271cdf0e059f4 100644
--- a/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
+++ b/mlir/test/Dialect/Vector/transform-op-vector-to-llvm.mlir
@@ -18,4 +18,4 @@ module attributes {transform.with_named_sequence} {
} {legal_dialects = ["func", "llvm"]} : !transform.any_op
transform.yield
}
-}
\ No newline at end of file
+}
More information about the Mlir-commits
mailing list