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
10 changes: 10 additions & 0 deletions lib/SILOptimizer/Mandatory/Differentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,16 @@ void DifferentiableActivityInfo::analyze(DominanceInfo *di,
if (isVaried(cai->getSrc(), i))
recursivelySetVariedIfDifferentiable(cai->getDest(), i);
}
else if (auto *sei = dyn_cast<StructExtractInst>(&inst)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll also want to check whether CotangentVector is @_fieldwiseProductSpace, because if it's not, we consider @noDerivative as having had no effect on conformance synthesis, so it could still have a VJP we would call when it's active.

It would be nice to move the code that checks for @_fieldwiseProductSpace into a helper.

if (isVaried(sei->getOperand(), i)) {
auto hasNoDeriv = sei->getField()->getAttrs()
.hasAttribute<NoDerivativeAttr>();
if (!hasNoDeriv) {
for (auto result: inst.getResults())
setVariedIfDifferentiable(result, i);
}
}
}
// Handle everything else.
else {
for (auto &op : inst.getAllOperands())
Expand Down