[Mlir-commits] [mlir] [mlir][vector] Add mask elimination transform (PR #99314)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Mon Jul 29 02:28:47 PDT 2024
banach-space wrote:
> * Could we move the trivial pattern-matching cases to the folder/canonicalizer?
+1 IIUC, Diego is asking for more code re-use. In particular, if similar logic is already available somewhere in folder/conanicalization "landscape", it should be re-used here:
```cpp
struct UnknownMaskDim {
size_t position;
Value dimSize;
};
// Return `Failure` if at least one Mask dim is statically known not to be "all true". Otherwise,
// returns a vector of `UnknownMaskDim` yet to be analysed to see whether these are "all-true" lanes.
// If the return value is an empty vector, all Mask dims are statically known to be "all-true".
FailureOr<SmallVector<UnknownMaskDim>> getPossiblyTrueMaskDim() {
SmallVector<UnknownMaskDim> unknownDims;
for (auto [i, dimSize] : llvm::enumerate(createMaskOp.getOperands())) {
if (auto intSize = getConstantIntValue(dimSize)) {
// Mask not all-true for this dim.
if (maskTypeDimScalableFlags[i] || intSize < maskTypeDimSizes[i])
return failure();
} else if (auto vscaleMultiplier = getConstantVscaleMultiplier(dimSize)) {
// Mask not all-true for this dim.
if (vscaleMultiplier < maskTypeDimSizes[i])
return failure();
} else {
// Unknown (without further analysis).
unknownDims.push_back(UnknownMaskDim{i, dimSize});
}
}
return unknownDims;
}
```
>From what I can tell, you can wrap this into an utilility funciton ,e.g.
```cpp
SmallVector<>
```
> * Could we use `constant_mask` instead of `arith.constant`? This is not enforced in any way but we've been using the former to represent vector masks (they are kind of redundant, actually).
+1 to this suggestion. @dcaballe , are you OK to implement this as a follow-up?
https://github.com/llvm/llvm-project/pull/99314
More information about the Mlir-commits
mailing list