Skip to content

Commit b8cfe0c

Browse files
authored
Rooting: handle extract value in post (#2587)
1 parent 77f894c commit b8cfe0c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

enzyme/Enzyme/CApi.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,34 @@ bool needsReRooting(llvm::Argument *arg, bool is_v, bool &anyJLStore) {
17461746
continue;
17471747
}
17481748
}
1749+
if (auto ST = dyn_cast<StructType>(sv->getType())) {
1750+
bool legal = true;
1751+
for (size_t i = 0; i < ST->getNumElements(); i++) {
1752+
1753+
CountTrackedPointers tracked(ST->getElementType(i));
1754+
if (tracked.count == 0) {
1755+
continue;
1756+
}
1757+
Value *ev = nullptr;
1758+
for (auto u : sv->users()) {
1759+
if (auto ev0 = dyn_cast<ExtractValueInst>(u)) {
1760+
if (ev0->getNumIndices() == 1 && ev0->getIndices()[0] == i) {
1761+
ev = ev0;
1762+
break;
1763+
}
1764+
}
1765+
}
1766+
if (ev) {
1767+
storedValues.push_back(ev);
1768+
} else {
1769+
legal = false;
1770+
break;
1771+
}
1772+
}
1773+
if (legal) {
1774+
continue;
1775+
}
1776+
}
17491777
if (!isa<PointerType>(sv->getType()) ||
17501778
!isSpecialPtr(cast<PointerType>(sv->getType()))) {
17511779
llvm::errs() << " sf: " << *arg->getParent() << "\n";

0 commit comments

Comments
 (0)