[llvm] [VPlan] Handle FirstActiveLane when unrolling. (PR #145394)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 29 08:01:30 PDT 2025
================
@@ -856,9 +856,32 @@ Value *VPInstruction::generate(VPTransformState &State) {
return Builder.CreateOrReduce(Res);
}
case VPInstruction::FirstActiveLane: {
- Value *Mask = State.get(getOperand(0));
- return Builder.CreateCountTrailingZeroElems(Builder.getInt64Ty(), Mask,
- true, Name);
+ if (getNumOperands() == 1) {
+ Value *Mask = State.get(getOperand(0));
+ return Builder.CreateCountTrailingZeroElems(Builder.getInt64Ty(), Mask,
+ true, Name);
+ }
+ // If there are multiple operands, create a chain of selects to pick the
+ // first operand with an active lane and add the number of lanes of the
+ // preceding operands.
+ Value *RuntimeVF =
+ getRuntimeVF(State.Builder, State.Builder.getInt64Ty(), State.VF);
+ unsigned LastOpIdx = getNumOperands() - 1;
+ Value *Res = nullptr;
+ for (int Idx = LastOpIdx; Idx >= 0; --Idx) {
----------------
ayalz wrote:
Can something like this
```suggestion
for (VPValue *Operand : reverse(operands()) {
```
work instead?
https://github.com/llvm/llvm-project/pull/145394
More information about the llvm-commits
mailing list