Skip to content
Merged
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
9 changes: 7 additions & 2 deletions lib/SILOptimizer/Mandatory/Differentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4396,8 +4396,13 @@ void DifferentiationTask::createVJP() {
// This assumes that the primal direct results correspond exactly to the
// adjoint's direct parameters, an assumption that we check in assertions
// above.
builder.createRetainValue(loc, primalDirectResults[dirResIdx],
builder.getDefaultAtomicity());
//
// If this is not the primal value struct (index 0), it must be an
// original result. Retain it because we'll return original results
// alongside the pullback.
if (dirResIdx != 0)
builder.createRetainValue(loc, primalDirectResults[dirResIdx],
builder.getDefaultAtomicity());
partialAdjointArgs.push_back(primalDirectResults[dirResIdx++]);
} else {
// This assumes that the primal indirect results correspond exactly to the
Expand Down