Iterate through snapshotted instructions in copy insertion.

Otherwise if a while feed into another while as init, the init (while)
will be added back to the iteration list, which makes dataflow
analysis confused.

PiperOrigin-RevId: 300137503
Change-Id: I3d6d993d09a9f9cda1fa738c26a0bbb164b707e5
This commit is contained in:
Yunxing Dai 2020-03-10 11:27:19 -07:00 committed by TensorFlower Gardener
parent 0bbfe8d95d
commit c7ca2a45e6

View File

@ -975,8 +975,9 @@ Status CopyInsertion::AddCopiesToResolveInterference(HloModule* module) {
TF_ASSIGN_OR_RETURN(std::unique_ptr<HloAliasAnalysis> alias_analysis,
HloAliasAnalysis::Run(module, can_share_buffer_));
for (HloComputation* computation : module->computations()) {
for (HloInstruction* instruction : computation->instructions()) {
for (HloComputation* computation : module->MakeComputationPostOrder()) {
for (HloInstruction* instruction :
computation->MakeInstructionPostOrder()) {
if (instruction->opcode() == HloOpcode::kWhile) {
TF_RETURN_IF_ERROR(AddCopiesForWhile(*alias_analysis, instruction));
} else if (instruction->opcode() == HloOpcode::kConditional) {