[Mlir-commits] [mlir] [mlir] canonicalizer: shape_cast(poison) -> poison (PR #133988)
Kunwar Grover
llvmlistbot at llvm.org
Mon Apr 7 09:09:58 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());
+ }
----------------
Groverkss wrote:
You don't need to check getDefiningOp, the adaptor will automatically give you an attribute if it can. Instead, you can do:
if (auto dense = llvm::dyn_cast<SplatElementsAttr>(adaptor.getSource()) {
...
}
Same for ub::PoisonOp, but use ub::PosionAttr
https://github.com/llvm/llvm-project/pull/133988
More information about the Mlir-commits
mailing list