[Mlir-commits] [mlir] [mlir][IntRangeInference] Infer values for {memref, tensor}.dim (PR #122945)

Ivan Butygin llvmlistbot at llvm.org
Tue Jan 14 11:07:01 PST 2025


================
@@ -725,3 +726,46 @@ std::optional<bool> mlir::intrange::evaluatePred(CmpPredicate pred,
     return false;
   return std::nullopt;
 }
+
+//===----------------------------------------------------------------------===//
+// Shaped type dimension accessors / ShapedDimOpInterface
+//===----------------------------------------------------------------------===//
+
+ConstantIntRanges
+mlir::intrange::inferShapedDimOpInterface(ShapedDimOpInterface op,
+                                          const IntegerValueRange &maybeDim) {
+  unsigned width =
+      ConstantIntRanges::getStorageBitwidth(op->getResult(0).getType());
+  APInt zero = APInt::getZero(width);
+  APInt typeMax = APInt::getSignedMaxValue(width);
+
+  auto shapedTy = cast<ShapedType>(op.getShapedValue().getType());
+  if (!shapedTy.hasRank())
+    return ConstantIntRanges::fromSigned(zero, typeMax);
+
+  int64_t rank = shapedTy.getRank();
+  int64_t minDim = 0;
+  int64_t maxDim = rank - 1;
----------------
Hardcode84 wrote:

We need a check and test for 0-rank shaped, dim of 0-rank shaped is runtime UB but it is still a valid IR.

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


More information about the Mlir-commits mailing list