@@ -294,14 +294,13 @@ bool VPInstruction::doesGeneratePerAllLanes() const {
294
294
bool VPInstruction::canGenerateScalarForFirstLane () const {
295
295
if (Instruction::isBinaryOp (getOpcode ()))
296
296
return true ;
297
-
297
+ if (isVectorToScalar ())
298
+ return true ;
298
299
switch (Opcode) {
299
300
case VPInstruction::BranchOnCond:
300
301
case VPInstruction::BranchOnCount:
301
302
case VPInstruction::CalculateTripCountMinusVF:
302
303
case VPInstruction::CanonicalIVIncrementForPart:
303
- case VPInstruction::ComputeReductionResult:
304
- case VPInstruction::ExtractFromEnd:
305
304
case VPInstruction::PtrAdd:
306
305
case VPInstruction::ExplicitVectorLength:
307
306
return true ;
@@ -567,17 +566,15 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
567
566
auto *CI = cast<ConstantInt>(getOperand (1 )->getLiveInIRValue ());
568
567
unsigned Offset = CI->getZExtValue ();
569
568
570
- // Extract lane VF - Offset in the from the operand.
571
569
Value *Res;
572
570
if (State.VF .isVector ()) {
571
+ // Extract lane VF - Offset from the operand.
573
572
Res = State.get (
574
573
getOperand (0 ),
575
574
VPIteration (State.UF - 1 , VPLane::getLaneFromEnd (State.VF , Offset)));
576
575
} else {
577
576
assert (State.UF > 1 && " VF and UF cannot both be 1" );
578
- // When loop is unrolled without vectorizing, retrieve the value just
579
- // prior to the final unrolled value. This is analogous to the vectorized
580
- // case above: extracting the second last element when VF > 1.
577
+ // When loop is unrolled without vectorizing, retrieve UF - Offset.
581
578
Res = State.get (getOperand (0 ), State.UF - Offset);
582
579
}
583
580
Res->setName (Name);
@@ -600,6 +597,11 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
600
597
}
601
598
}
602
599
600
+ bool VPInstruction::isVectorToScalar () const {
601
+ return getOpcode () == VPInstruction::ExtractFromEnd ||
602
+ getOpcode () == VPInstruction::ComputeReductionResult;
603
+ }
604
+
603
605
#if !defined(NDEBUG)
604
606
bool VPInstruction::isFPMathOp () const {
605
607
// Inspired by FPMathOperator::classof. Notable differences are that we don't
@@ -622,9 +624,7 @@ void VPInstruction::execute(VPTransformState &State) {
622
624
State.setDebugLocFrom (getDebugLoc ());
623
625
bool GeneratesPerFirstLaneOnly =
624
626
canGenerateScalarForFirstLane () &&
625
- (vputils::onlyFirstLaneUsed (this ) ||
626
- getOpcode () == VPInstruction::ExtractFromEnd ||
627
- getOpcode () == VPInstruction::ComputeReductionResult);
627
+ (vputils::onlyFirstLaneUsed (this ) || isVectorToScalar ());
628
628
bool GeneratesPerAllLanes = doesGeneratePerAllLanes ();
629
629
for (unsigned Part = 0 ; Part < State.UF ; ++Part) {
630
630
if (GeneratesPerAllLanes) {
0 commit comments