FirstOrderRecurrencePHI Unroll Parts


This is a query regarding vectorization of VPFirstOrderRecurrencePHIRecipe in the presence of unroll.

Observed from the implementation that its created for first part of unroll with the initial value coming from vector pre header.

And later it gets its second incoming value when the cross iteration PHI gets fixed.

The cross iteration PHI gets fixed during the last stage of vectorization, when the instruction are already widened.

But during the vectorization if we need the value of FirstOrderRecurrencePHI for different unroll parts, it’s not available.

When I try to access gets below error:
llvm::Value llvm::VPValue::getLiveInIRValue(): Assertion `!hasDefiningRecipe() && “VPValue is not a live-in; it is defined by a VPDef inside a VPlan”’ failed.*

The point where I’m expecting this information the value which later added as incoming to PHI is expanded and its available.

Probably I’m missing something here, but is there an existing way to get it ?


@fhahn @ayalz

The recurrence phi only carries through the value of the last unroll part from the previous iteration, as you said. This is intentional.

The values for all parts are generated by combining the values from the previous iteration with the values from the current iteration. This is done by VPInstruction::FirstOrderRecurrenceSplice, generated here llvm-project/LoopVectorize.cpp at main · llvm/llvm-project · GitHub. This generates the vector values for all unrolled parts.

Thanks for the inputs Florian.


Would be good to provide this explanation in the documentation - perhaps update the example provided with ILV::fixFixedOrderRecurrence() to refer to said splice and multiple unroll parts.