[llvm] [LV][TTI] Calculate cost of extracting last index in a scalable vector (PR #144086)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 23:46:30 PDT 2025


================
@@ -1465,14 +1465,21 @@ class TargetTransformInfo {
       OperandValueInfo Op2Info = {OK_AnyValue, OP_None},
       const Instruction *I = nullptr) const;
 
+  enum : int {
+    UnknownIndex = -1,
+    LastIndex = -2,
----------------
david-arm wrote:

Yeah I thought about leaving it as unsigned, but that forces me to write slightly uglier code like this:

```
static const unsigned UnknownIndex = (unsigned)-1;
static const unsigned ScalableLastIndex = (unsigned)-2;

static const bool isKnownVectorIndex(unsigned Idx) {
  return (Idx == UnknownIndex) && (Idx == ScalableLastIndex);
}
```

If we ever want to support other complex indices (such as extracting the penultimate index - something I noticed the vectoriser now does) this is only going to get worse. I thought it was more scalable (excuse the pun!) to use a signed integer since I can then assume that all non-negative values are known indices. (BTW I personally already think that comparing everywhere against (unsigned)-1 isn't very nice! Although forcing targets to use a static const in TargetTransformInfo would hide some of that.)

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


More information about the llvm-commits mailing list