[AutoDiff] Revamp and fix variedness propagation in activity analysis. (#28155)
Varied values are those that depend on (specific) independent variables,
i.e. function arguments.
For addresses: all projections of a varied address should be varied.
This has special support:
`DifferentiableActivityInfo::propagateVariedInwardsThroughProjections`.
Previously:
- Variedness was propagated by iterating through all instructions in dominance
order. This is not efficient because irrelevant instructions may be visited.
- For varied addresses, `propagateVariedInwardsThroughProjections` propagated
variedness one step to projections, but not recursively to users of the
projections. This caused some values to incorrectly be marked as non-varied.
Now:
- Variedness is propagated by following use-def chains, starting from
independent variables (function arguments). This is handled by the
following helpers:
- `setVariedAndPropagateToUsers(SILValue, unsigned)`: marks a value as varied
and propagates variedness to users.
- `propagateVaried(Operand *operand, unsigned)`: propagates variedness for
the given operand to its user's results.
- `DifferentiableActivityInfo::propagateVariedInwardsThroughProjections`
now calls `setVariedAndPropagateToUsers` to propagate variedness recursively
through projections, which is desired.
Resolves various control flow differentiation correctness issues:
TF-681, TF-781, TF-933.
All of these issues involve incorrect variedness propagation for
initially non-varied addresses.
TF-947 tracks further improvements to varied propagation.
TF-949 tracks similar revamping for usefulness propagation.