[Mlir-commits] [mlir] [MLIR] Add replace-operands option to mlir-reduce (PR #153100)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Aug 31 11:21:49 PDT 2025


aidint wrote:

> If I have an operations with N i32 inputs, would all of them be replaced by the same value? E.g., we'd go from "sub a, b : i32" to "sub arg0, arg0 : i32" always.

Yes, that's what I'd expect. In each operation, the algorithm first iterates over the operands. For each operand, it then iterates through the candidates stored in a `DenseMap<Type, SmallVector>`. Within the `SmallVector`, the algorithm selects the first value that dominates the operator. Since this value is the same for every operand within a single operator, and neither the `DenseMap` nor its `SmallVector` values are modified, I believe the operands will all be replaced by this same value.

> The other one I was wondering about, but didn't get time to look deeper into, is if this could be handled in a pattern (so need not be option, but one which folks can add or not)

I'm not really sure about this. I don't know how this could be implemented as a pattern. It basically matches every operation and also holds a state based on previous observations which I'm not sure how to handle in a pattern.

> and/or if it could behave the same as tree traversal (so would be able to only replace some of the arguments).

I didn't get this part. Do you mean replacing operands only when some patterns are matched?

https://github.com/llvm/llvm-project/pull/153100


More information about the Mlir-commits mailing list