[llvm] [clang] [mlir] [llvm][TypeSize] Consider TypeSize of '0' to be fixed/scalable-agnostic. (PR #72994)

Sander de Smalen via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 21 07:21:27 PST 2023


sdesmalen-arm wrote:

> Creating a scalable vector of size 0 should not even be allowed.

Correct, but that is no reason to disallow a value of '0' for TypeSize. This is just a class to represent a value (fixed or scalable), and it's up to the places where TypeSize is used on whether that use is valid. You could argue the same for an `int`, which is used to represent the size of a type.

FWIW, one of the uses for a zero-sized TypeSize value (and also the motivating reason for this patch) is e.g. to get the combined size of spills for N vectors, you could do:
```
TypeSize Size();
for (auto Obj : Objects)
  Size += Obj.getSize();
```
without having to determine before the loop whether Size needs to be Fixed or Scalable.

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


More information about the cfe-commits mailing list