[Mlir-commits] [mlir] [mlir] canonicalizer: shape_cast(poison) -> poison (PR #133988)
James Newling
llvmlistbot at llvm.org
Mon Apr 7 10:15:14 PDT 2025
================
@@ -5643,32 +5643,24 @@ OpFoldResult ShapeCastOp::fold(FoldAdaptor adaptor) {
return bcastOp.getSource();
}
+ // Replace shape_cast(arith.constant) with arith.constant. Currently only
+ // handles splat constants.
+ if (auto constantOp = getSource().getDefiningOp<arith::ConstantOp>()) {
+ if (auto dense = llvm::dyn_cast<SplatElementsAttr>(constantOp.getValue())) {
+ return DenseElementsAttr::get(cast<VectorType>(getType()),
+ dense.getSplatValue<Attribute>());
+ }
+ }
+
+ // Replace shape_cast(poison) with poison.
+ if (getSource().getDefiningOp<ub::PoisonOp>()) {
+ return ub::PoisonAttr::get(getContext());
+ }
----------------
newling wrote:
That is simpler. Note I needed to `if (auto dense = llvm::dyn_cast_if_present(adaptor.getSource())` -- the '_if_present' for the case where the shape cast is the source is not already a constant/attribute.
https://github.com/llvm/llvm-project/pull/133988
More information about the Mlir-commits
mailing list