[Mlir-commits] [mlir] [mlir][arith] Add result pretty printing for constant vscale values (PR #83565)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Tue Mar 19 10:48:01 PDT 2024
================
@@ -400,6 +400,35 @@ OpFoldResult arith::MulIOp::fold(FoldAdaptor adaptor) {
[](const APInt &a, const APInt &b) { return a * b; });
}
+void arith::MulIOp::getAsmResultNames(
+ function_ref<void(Value, StringRef)> setNameFn) {
+ if (!isa<IndexType>(getType()))
+ return;
+
+ // Match vector.vscale by name to avoid depending on the vector dialect (which
+ // is a circular dependency).
+ auto isVscale = [](Operation *op) {
+ return op && op->getName().getStringRef() == "vector.vscale";
+ };
+
+ // Name `base * vscale` or `vscale * base` as `c<base_value>_vscale`.
+ IntegerAttr baseValue;
+ if (matchPattern(getLhs(), m_Constant(&baseValue)) &&
+ isVscale(getRhs().getDefiningOp())) {
+ // base * vscale
+ } else if (isVscale(getLhs().getDefiningOp()) &&
+ matchPattern(getRhs(), m_Constant(&baseValue))) {
+ // vscale * base
+ } else {
+ return;
+ }
----------------
banach-space wrote:
Could we avoid `if/else-if` nests? How about:
```suggestion
bool isVscaleXBase = matchPattern(getLhs(), m_Constant(&baseValue)) &&
isVscale(getRhs().getDefiningOp());
bool isBaseXVscale = isVscale(getLhs().getDefiningOp()) &&
matchPattern(getRhs(), m_Constant(&baseValue));
if (!(isVscaleXBase || isBaseXVscale)
return;
```
https://github.com/llvm/llvm-project/pull/83565
More information about the Mlir-commits
mailing list