[llvm] [VPlan] Mark default value or ExtractLastActive as only first lane used. (PR #226153)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 08:48:48 PDT 2026


================
@@ -1745,6 +1745,8 @@ bool VPInstruction::usesFirstLaneOnly(const VPValue *Op) const {
     return Op == getOperand(1);
   case Instruction::InsertElement:
     return Op == getOperand(1) || Op == getOperand(2);
+  case VPInstruction::ExtractLastActive:
+    return Op == getOperand(0);
----------------
david-arm wrote:

Hmm ok. I think I see now from the comments describing the operation:

```
    /// Extracts the last active lane from a set of vectors. The first operand
    /// is the default value if no lanes in the masks are active. Conceptually,
    /// this concatenates all data vectors (odd operands), concatenates all
    /// masks (even operands -- ignoring the default value), and returns the
    /// last active value from the combined data vector using the combined mask.
    ExtractLastActive,
```

although it sounds like `ExtractLastActive` is too simplified a name, since it's really ExtractLastActiveValueFromConcatenatedMask or something like that. The only use case seems to be in `handleFindLastReductions`:

```
    auto *ExtractLastActive =
        Builder.createNaryOp(VPInstruction::ExtractLastActive,
                             {PhiR->getStartValue(), DataSelect, MaskSelect},
                             RdxResult->getDebugLoc());
```

where presumably the first operand is actually a vector? It's quite confusing! In `unrollBlock` it looks like we add the part as the last operand to the instruction. I'm still not sure how we only use the first lane of operand 0 here?

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


More information about the llvm-commits mailing list