[Mlir-commits] [mlir] Fix remove dead values poison crash (PR #205966)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jun 25 23:48:16 PDT 2026


https://github.com/LouisLu060211 updated https://github.com/llvm/llvm-project/pull/205966

>From 8159ee2b4e0188e999056a09dd075da0d79ac568 Mon Sep 17 00:00:00 2001
From: LouisLu0602 <yaolu0602 at gmail.com>
Date: Wed, 24 Jun 2026 15:09:36 +0800
Subject: [PATCH] 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

minnor issues
---
 mlir/lib/Transforms/RemoveDeadValues.cpp     | 20 +++++++++++------
 mlir/test/Transforms/remove-dead-values.mlir | 23 ++++++++++++++++++++
 2 files changed, 36 insertions(+), 7 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/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>
+  }
+}



More information about the Mlir-commits mailing list