File tree Expand file tree Collapse file tree 3 files changed +26
-5
lines changed
include/llvm/Transforms/Vectorize/SandboxVectorizer
lib/Transforms/Vectorize/SandboxVectorizer
unittests/Transforms/Vectorize/SandboxVectorizer Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,12 @@ template <typename T> class Interval {
127127 }
128128 // / Inequality.
129129 bool operator !=(const Interval &Other) const { return !(*this == Other); }
130+ // / \Returns true if this interval comes before \p Other in program order.
131+ // / This expects disjoint intervals.
132+ bool comesBefore (const Interval &Other) const {
133+ assert (disjoint (Other) && " Expect disjoint intervals!" );
134+ return bottom ()->comesBefore (Other.top ());
135+ }
130136 // / \Returns true if this and \p Other have nothing in common.
131137 bool disjoint (const Interval &Other) const {
132138 if (Other.empty ())
Original file line number Diff line number Diff line change @@ -231,11 +231,7 @@ void DependencyGraph::createNewNodes(const Interval<Instruction> &NewInterval) {
231231 }
232232 // Link new MemDGNode chain with the old one, if any.
233233 if (!DAGInterval.empty ()) {
234- // TODO: Implement Interval::comesBefore() to replace this check.
235- bool NewIsAbove = NewInterval.bottom ()->comesBefore (DAGInterval.top ());
236- assert (
237- (NewIsAbove || DAGInterval.bottom ()->comesBefore (NewInterval.top ())) &&
238- " Expected NewInterval below DAGInterval." );
234+ bool NewIsAbove = NewInterval.comesBefore (DAGInterval);
239235 const auto &TopInterval = NewIsAbove ? NewInterval : DAGInterval;
240236 const auto &BotInterval = NewIsAbove ? DAGInterval : NewInterval;
241237 MemDGNode *LinkTopN =
Original file line number Diff line number Diff line change @@ -123,6 +123,25 @@ define void @foo(i8 %v0) {
123123 EXPECT_FALSE (Intvl1.disjoint (Intvl3));
124124 EXPECT_TRUE (Intvl1.disjoint (Empty));
125125 }
126+ {
127+ // Check comesBefore().
128+ sandboxir::Interval<sandboxir::Instruction> Intvl1 (I0, I0);
129+ sandboxir::Interval<sandboxir::Instruction> Intvl2 (I2, I2);
130+ EXPECT_TRUE (Intvl1.comesBefore (Intvl2));
131+ EXPECT_FALSE (Intvl2.comesBefore (Intvl1));
132+
133+ sandboxir::Interval<sandboxir::Instruction> Intvl12 (I1, I2);
134+ EXPECT_TRUE (Intvl1.comesBefore (Intvl12));
135+ EXPECT_FALSE (Intvl12.comesBefore (Intvl1));
136+ {
137+ #ifndef NDEBUG
138+ // Check comesBefore() with non-disjoint intervals.
139+ sandboxir::Interval<sandboxir::Instruction> Intvl1 (I0, I2);
140+ sandboxir::Interval<sandboxir::Instruction> Intvl2 (I2, I2);
141+ EXPECT_DEATH (Intvl1.comesBefore (Intvl2), " .*disjoint.*" );
142+ #endif // NDEBUG
143+ }
144+ }
126145}
127146
128147// Helper function for returning a vector of instruction pointers from a range
You can’t perform that action at this time.
0 commit comments