[Mlir-commits] [mlir] [mlir] canonicalizer: shape_cast(poison) -> poison (PR #133988)
James Newling
llvmlistbot at llvm.org
Mon Apr 7 09:03:32 PDT 2025
================
@@ -5670,6 +5670,23 @@ class ShapeCastConstantFolder final : public OpRewritePattern<ShapeCastOp> {
}
};
+// Pattern to rewrite a ShapeCast(PoisonOp) -> PoisonOp.
+class ShapeCastPoisonFolder final : public OpRewritePattern<ShapeCastOp> {
+public:
+ using OpRewritePattern::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(ShapeCastOp shapeCastOp,
+ PatternRewriter &rewriter) const override {
+
+ if (!shapeCastOp.getSource().getDefiningOp<ub::PoisonOp>())
+ return failure();
+
+ rewriter.replaceOpWithNewOp<ub::PoisonOp>(shapeCastOp,
+ shapeCastOp.getType());
+ return success();
+ }
+};
+
----------------
newling wrote:
Makes sense. I've moved the equivalent constant canonicalizer to a folder for consistency
https://github.com/llvm/llvm-project/pull/133988
More information about the Mlir-commits
mailing list