Skip to content

Commit b359e2c

Browse files
authored
Fix mincut remat bug (rust-lang#893)
1 parent e3c7867 commit b359e2c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

enzyme/Enzyme/DifferentialUseAnalysis.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,25 +1020,30 @@ static inline void minCut(const DataLayout &DL, LoopInfo &OrigLI,
10201020
for (auto U : V->users()) {
10211021
if (auto I = dyn_cast<Instruction>(U)) {
10221022
for (auto pair : rematerializableAllocations) {
1023-
if (Intermediates.count(pair.first) && pair.second.stores.count(I))
1024-
G[Node(V, true)].insert(Node(pair.first, false));
1023+
if (Intermediates.count(pair.first) && pair.second.stores.count(I)) {
1024+
if (V != pair.first)
1025+
G[Node(V, true)].insert(Node(pair.first, false));
1026+
}
10251027
}
10261028
}
10271029
if (Intermediates.count(U)) {
1028-
G[Node(V, true)].insert(Node(U, false));
1030+
if (V != U)
1031+
G[Node(V, true)].insert(Node(U, false));
10291032
}
10301033
}
10311034
}
10321035
for (auto pair : rematerializableAllocations) {
10331036
if (Intermediates.count(pair.first)) {
10341037
for (LoadInst *L : pair.second.loads) {
10351038
if (Intermediates.count(L)) {
1036-
G[Node(pair.first, true)].insert(Node(L, false));
1039+
if (L != pair.first)
1040+
G[Node(pair.first, true)].insert(Node(L, false));
10371041
}
10381042
}
10391043
for (auto L : pair.second.loadLikeCalls) {
10401044
if (Intermediates.count(L.loadCall)) {
1041-
G[Node(pair.first, true)].insert(Node(L.loadCall, false));
1045+
if (L.loadCall != pair.first)
1046+
G[Node(pair.first, true)].insert(Node(L.loadCall, false));
10421047
}
10431048
}
10441049
}

0 commit comments

Comments
 (0)