Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions enzyme/Enzyme/GradientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8659,6 +8659,27 @@ void GradientUtils::eraseFictiousPHIs() {
for (auto pair : phis) {
auto pp = pair.first;
if (pp->getNumUses() != 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we definitely want a test case for this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wsmoses I added a IR test here #2700 (comment)

// If the original instruction was a malloc with enzyme_fromstack,
// the allocation is needed but was incorrectly replaced by a
// fictiousPHI. Restore it as a stack allocation (alloca).
if (auto *origCall = dyn_cast<CallInst>(pair.second)) {
if (auto MD = hasMetadata(origCall, "enzyme_fromstack")) {
IRBuilder<> B(&newFunc->getEntryBlock().front());
Value *Size = getNewFromOriginal(origCall->getArgOperand(0));
Type *elTy = Type::getInt8Ty(origCall->getContext());
Value *replacement = B.CreateAlloca(elTy, Size);
auto Alignment =
cast<ConstantInt>(
cast<ConstantAsMetadata>(MD->getOperand(0))->getValue())
->getLimitedValue();
if (Alignment) {
cast<AllocaInst>(replacement)->setAlignment(Align(Alignment));
}
pp->replaceAllUsesWith(replacement);
erase(pp);
continue;
}
}
if (CustomErrorHandler) {
std::string str;
raw_string_ostream ss(str);
Expand Down
Loading