AD Cleanup: break-elimination during the CFG normalization step can cause the loop condition to be evaluated an extra time. #4188
Labels
goal:quality & productivity
Quality issues and issues that impact our productivity coding day to day inside slang
kind:cleanup
tech debt and rough edges
Milestone
This is typically not a problem, except for when the loop condition evaluates functions with side-effects.
Example:
gets replaced with:
Here
f(i)
can be evaluated an extra time, since instead of immediately breaking out of the loop, we evaluate the condition an extra time. The evaluated result is unimportant sincebflag=false
, but iff(i)
has side-effects, the primal part of the computation would be incorrect since it runs one extra time than the user intended.The fix is simply to enclose the condition block in another condition, but this is tricky to do since most of the AD passes assume that the loop's condition check is in the block immediately following the loop condition.
The text was updated successfully, but these errors were encountered: