[Mlir-commits] [mlir] [mlir][Interfaces][NFC] `ValueBoundsConstraintSet`: Add columns for constant values/dims (PR #86097)

Nicolas Vasilache llvmlistbot at llvm.org
Mon Mar 25 02:59:32 PDT 2024


================
@@ -107,25 +107,47 @@ AffineExpr ValueBoundsConstraintSet::getExpr(Value value,
   assertValidValueDim(value, dim);
 #endif // NDEBUG
 
+  // Check if the value/dim is statically known. In that case, an affine
+  // constant expression should be returned. This allows us to support
+  // multiplications with constants. (Multiplications of two columns in the
+  // constraint set is not supported.)
+  std::optional<int64_t> constSize = std::nullopt;
   auto shapedType = dyn_cast<ShapedType>(value.getType());
   if (shapedType) {
-    // Static dimension: return constant directly.
     if (shapedType.hasRank() && !shapedType.isDynamicDim(*dim))
-      return builder.getAffineConstantExpr(shapedType.getDimSize(*dim));
-  } else {
-    // Constant index value: return directly.
-    if (auto constInt = ::getConstantIntValue(value))
-      return builder.getAffineConstantExpr(*constInt);
+      constSize = shapedType.getDimSize(*dim);
----------------
nicolasvasilache wrote:

Hmm, I feel this is tricky: this really depends about the context in which we query the analysis.
It is easy to create a varying shape (i.e. size depends on loop iv) and this will not be a symbol anymore.

Basically, if the analysis was properly rooted at an op / block, we could say that everything defined above is a symbol.

IOW, any such analysis is relative to its context: if your transform/analysis cares about information on say k innermost loops, you can "make" information about the outermost loops constant.

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


More information about the Mlir-commits mailing list