Skip to content

Commit d63194a

Browse files
committed
Consider vscale_range
1 parent 47c9260 commit d63194a

File tree

4 files changed

+228
-11
lines changed

4 files changed

+228
-11
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8566,8 +8566,13 @@ static void addExitUsersForFirstOrderRecurrences(
85668566
VPBuilder ScalarPHBuilder(ScalarPHVPBB);
85678567
VPBuilder MiddleBuilder(MiddleVPBB, MiddleVPBB->getFirstNonPhi());
85688568

8569-
auto IsScalableOne = [](ElementCount VF) -> bool {
8570-
return VF.isScalable() && VF.getKnownMinValue() == 1;
8569+
auto MayOneElement = [&Plan](ElementCount VF) -> bool {
8570+
if (!VF.isScalable() || VF.getKnownMinValue() != 1)
8571+
return false;
8572+
8573+
const Function *Fn = Plan.getScalarHeader()->getIRBasicBlock()->getParent();
8574+
const auto &Attr = Fn->getFnAttribute(Attribute::VScaleRange);
8575+
return !Attr.isValid() || Attr.getVScaleRangeMin() == 1;
85718576
};
85728577

85738578
for (auto &HeaderPhi : VectorRegion->getEntryBasicBlock()->phis()) {
@@ -8654,8 +8659,8 @@ static void addExitUsersForFirstOrderRecurrences(
86548659
// For VF vscale x 1, if vscale = 1, we are unable to extract the
86558660
// penultimate value of the recurrence. Instead, we can extract the last
86568661
// element directly from VPInstruction::FirstOrderRecurrenceSplice.
8657-
// TODO: Consider vscale_range info and UF.
8658-
if (LoopVectorizationPlanner::getDecisionAndClampRange(IsScalableOne,
8662+
// TODO: Consider UF > 1.
8663+
if (LoopVectorizationPlanner::getDecisionAndClampRange(MayOneElement,
86598664
Range))
86608665
return;
86618666
VPValue *PenultimateElement = MiddleBuilder.createNaryOp(

llvm/lib/Transforms/Vectorize/VPlanHelpers.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ class VPLane {
149149
static VPLane getFirstLane() { return VPLane(0, VPLane::Kind::First); }
150150

151151
static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset) {
152-
assert(Offset > 0 && Offset <= VF.getKnownMinValue() &&
153-
"trying to extract with invalid offset");
152+
assert(Offset > 0 && "trying to extract with invalid offset");
154153
unsigned LaneOffset = VF.getKnownMinValue() - Offset;
155154
Kind LaneKind;
156155
if (VF.isScalable())

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,6 @@ Value *VPInstruction::generate(VPTransformState &State) {
715715
unsigned Offset = getOpcode() == VPInstruction::ExtractLastElement ? 1 : 2;
716716
Value *Res;
717717
if (State.VF.isVector()) {
718-
assert(Offset <= State.VF.getKnownMinValue() &&
719-
"invalid offset to extract from");
720718
// Extract lane VF - Offset from the operand.
721719
Res = State.get(getOperand(0), VPLane::getLaneFromEnd(State.VF, Offset));
722720
} else {

0 commit comments

Comments
 (0)