Skip to content

Commit f3f8e3d

Browse files
committed
[SLP] Remove ScheduleData::UnscheduledDepsInBundle field [NFC-ish]
We can simply compute the value of this field on demand. Doing so clarifies the behavior when one of the instructions within a bundle doesn't have valid dependencies. I vaguely thing this could change behavior slightly, but none of the test cases are affected, and my attempts to write one by hand have failed. This also minorly reduces memory usage, but that's a secondary value at best.
1 parent 37bad56 commit f3f8e3d

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,6 @@ class BoUpSLP {
24562456
NextLoadStore = nullptr;
24572457
IsScheduled = false;
24582458
SchedulingRegionID = BlockSchedulingRegionID;
2459-
UnscheduledDepsInBundle = UnscheduledDeps;
24602459
clearDependencies();
24612460
OpValue = OpVal;
24622461
TE = nullptr;
@@ -2467,8 +2466,8 @@ class BoUpSLP {
24672466
void verify() {
24682467
if (hasValidDependencies()) {
24692468
assert(UnscheduledDeps <= Dependencies && "invariant");
2470-
assert(UnscheduledDeps <= FirstInBundle->UnscheduledDepsInBundle &&
2471-
"bundle must have at least as many dependencies as member");
2469+
} else {
2470+
assert(UnscheduledDeps == Dependencies && "invariant");
24722471
}
24732472

24742473
if (IsScheduled) {
@@ -2479,6 +2478,8 @@ class BoUpSLP {
24792478
}
24802479

24812480
/// Returns true if the dependency information has been calculated.
2481+
/// Note that depenendency validity can vary between instructions within
2482+
/// a single bundle.
24822483
bool hasValidDependencies() const { return Dependencies != InvalidDeps; }
24832484

24842485
/// Returns true for single instructions and for bundle representatives
@@ -2496,20 +2497,23 @@ class BoUpSLP {
24962497
bool isReady() const {
24972498
assert(isSchedulingEntity() &&
24982499
"can't consider non-scheduling entity for ready list");
2499-
return UnscheduledDepsInBundle == 0 && !IsScheduled;
2500+
return unscheduledDepsInBundle() == 0 && !IsScheduled;
25002501
}
25012502

2502-
/// Modifies the number of unscheduled dependencies, also updating it for
2503-
/// the whole bundle.
2503+
/// Modifies the number of unscheduled dependencies for this instruction,
2504+
/// and returns the number of remaining dependencies for the containing
2505+
/// bundle.
25042506
int incrementUnscheduledDeps(int Incr) {
2507+
assert(hasValidDependencies() &&
2508+
"increment of unscheduled deps would be meaningless");
25052509
UnscheduledDeps += Incr;
2506-
return FirstInBundle->UnscheduledDepsInBundle += Incr;
2510+
return FirstInBundle->unscheduledDepsInBundle();
25072511
}
25082512

25092513
/// Sets the number of unscheduled dependencies to the number of
25102514
/// dependencies.
25112515
void resetUnscheduledDeps() {
2512-
incrementUnscheduledDeps(Dependencies - UnscheduledDeps);
2516+
UnscheduledDeps = Dependencies;
25132517
}
25142518

25152519
/// Clears all dependency information.
@@ -2519,6 +2523,18 @@ class BoUpSLP {
25192523
MemoryDependencies.clear();
25202524
}
25212525

2526+
int unscheduledDepsInBundle() const {
2527+
assert(isSchedulingEntity() && "only meaningful on the bundle");
2528+
int Sum = 0;
2529+
for (const ScheduleData *BundleMember = this; BundleMember;
2530+
BundleMember = BundleMember->NextInBundle) {
2531+
if (BundleMember->UnscheduledDeps == InvalidDeps)
2532+
return InvalidDeps;
2533+
Sum += BundleMember->UnscheduledDeps;
2534+
}
2535+
return Sum;
2536+
}
2537+
25222538
void dump(raw_ostream &os) const {
25232539
if (!isSchedulingEntity()) {
25242540
os << "/ " << *Inst;
@@ -2572,10 +2588,6 @@ class BoUpSLP {
25722588
/// Note that this is negative as long as Dependencies is not calculated.
25732589
int UnscheduledDeps = InvalidDeps;
25742590

2575-
/// The sum of UnscheduledDeps in a bundle. Equals to UnscheduledDeps for
2576-
/// single instructions.
2577-
int UnscheduledDepsInBundle = InvalidDeps;
2578-
25792591
/// True if this instruction is scheduled (or considered as scheduled in the
25802592
/// dry-run).
25812593
bool IsScheduled = false;
@@ -7503,8 +7515,6 @@ BoUpSLP::BlockScheduling::buildBundle(ArrayRef<Value *> VL) {
75037515
} else {
75047516
Bundle = BundleMember;
75057517
}
7506-
BundleMember->UnscheduledDepsInBundle = 0;
7507-
Bundle->UnscheduledDepsInBundle += BundleMember->UnscheduledDeps;
75087518

75097519
// Group the instructions to a bundle.
75107520
BundleMember->FirstInBundle = Bundle;
@@ -7631,8 +7641,7 @@ void BoUpSLP::BlockScheduling::cancelScheduling(ArrayRef<Value *> VL,
76317641
BundleMember->FirstInBundle = BundleMember;
76327642
ScheduleData *Next = BundleMember->NextInBundle;
76337643
BundleMember->NextInBundle = nullptr;
7634-
BundleMember->UnscheduledDepsInBundle = BundleMember->UnscheduledDeps;
7635-
if (BundleMember->UnscheduledDepsInBundle == 0) {
7644+
if (BundleMember->unscheduledDepsInBundle() == 0) {
76367645
ReadyInsts.insert(BundleMember);
76377646
}
76387647
BundleMember = Next;

0 commit comments

Comments
 (0)