[Mlir-commits] [mlir] [mlir][memref] Add foldUseDominateCast function to castOp (PR #168337)
Mehdi Amini
llvmlistbot at llvm.org
Mon Nov 17 06:56:02 PST 2025
================
@@ -793,8 +795,32 @@ bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
return false;
}
+static OpFoldResult foldUseDominateCast(CastOp castOp) {
+ auto funcOp = castOp->getParentOfType<FunctionOpInterface>();
+ if (!funcOp)
+ return {};
+ auto castOps = castOp->getBlock()->getOps<CastOp>();
+ CastOp dominateCastOp = castOp;
+ SmallVector<CastOp> ops(castOps);
+ mlir::DominanceInfo dominanceInfo(castOp);
+ for (auto it : castOps) {
+ if (it.getSource() == dominateCastOp.getSource() &&
+ it.getDest().getType() == dominateCastOp.getDest().getType() &&
+ dominanceInfo.dominates(it.getOperation(),
+ dominateCastOp.getOperation())) {
+ dominateCastOp = it;
+ }
+ }
----------------
joker-eph wrote:
Why do you need the dominanceInfo when you're just processing operations in a single block? Seems heavy for something that is naturally ordered.
https://github.com/llvm/llvm-project/pull/168337
More information about the Mlir-commits
mailing list