[Mlir-commits] [mlir] [mlir][Interfaces] Track and infer no-overflow flags in integer ranges (PR #191777)

Hocky Yudhiono llvmlistbot at llvm.org
Wed Apr 15 23:31:16 PDT 2026


================
@@ -104,10 +104,10 @@ LogicalResult StridedMetadataRangeAnalysis::visitOperation(
   };
 
   // Convert the arguments lattices to a vector.
-  SmallVector<StridedMetadataRange> argRanges = llvm::map_to_vector(
-      operands, [](const StridedMetadataRangeLattice *lattice) {
-        return lattice->getValue();
-      });
+  SmallVector<StridedMetadataRange, 2> argRanges;
+  argRanges.reserve(operands.size());
+  for (const StridedMetadataRangeLattice *lattice : operands)
+    argRanges.push_back(lattice->getValue());
----------------
hockyy wrote:


> This class likely need to be revisited and bound the SmallVector there. Can you try to do this and send a NFC PR ahead of this one?

I tried to use this instead
```mlir
  auto argRanges = llvm::map_to_vector<2>(
      operands, [](const StridedMetadataRangeLattice *lattice) {
        return lattice->getValue();
      });
```
and it compiles successfully, bounding the SmallVector in there I don't think would make much changes. 

---

I probed using this:
```
template <unsigned N>
struct Probe {
  std::optional<llvm::SmallVector<mlir::ConstantIntRanges, N>> offsets;
  llvm::SmallVector<mlir::ConstantIntRanges, N> sizes;
  llvm::SmallVector<mlir::ConstantIntRanges, N> strides;
};
```

```
N=0 -> size 56
N=1 -> size 272 (already > 256)
N=2 -> size 488
```

SmallVector.h uses this computation:
```
PreferredInlineBytes = 64 - sizeof(SmallVector<T, 0>)
N = max(1, PreferredInlineBytes / sizeof(T))
```
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/SmallVector.h#L1201 

What do you think?

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


More information about the Mlir-commits mailing list