aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tensorflow/compiler/xla/service/hlo_computation.cc2
-rw-r--r--tensorflow/compiler/xla/service/hlo_computation.h7
2 files changed, 5 insertions, 4 deletions
diff --git a/tensorflow/compiler/xla/service/hlo_computation.cc b/tensorflow/compiler/xla/service/hlo_computation.cc
index c2041c4667..b0f7cd91ad 100644
--- a/tensorflow/compiler/xla/service/hlo_computation.cc
+++ b/tensorflow/compiler/xla/service/hlo_computation.cc
@@ -215,7 +215,7 @@ Status HloComputation::RemoveInstructionAndUnusedOperands(
if (removed.count(item) != 0 || item->user_count() != 0 ||
item == root_instruction() || !IsRemovable(item) ||
- item->HasSideEffect()) {
+ (item->HasSideEffect() && item != instruction)) {
continue;
}
for (int i = 0; i < item->operand_count(); ++i) {
diff --git a/tensorflow/compiler/xla/service/hlo_computation.h b/tensorflow/compiler/xla/service/hlo_computation.h
index d87ab4bda1..dec96d11a9 100644
--- a/tensorflow/compiler/xla/service/hlo_computation.h
+++ b/tensorflow/compiler/xla/service/hlo_computation.h
@@ -128,9 +128,10 @@ class HloComputation {
// users. Instruction is deallocated with this call.
Status RemoveInstruction(HloInstruction* instruction);
- // Remove an instruction from the computation and also transitively any
- // operand that has no users post removing an instruction. The instruction
- // must have no users. Instruction is deallocated with this call.
+ // Remove an instruction (including side effecting ones) from the computation
+ // and also transitively any operand that has no side effect and no users post
+ // removing an instruction. The instruction must have no users. Instruction is
+ // deallocated with this call.
Status RemoveInstructionAndUnusedOperands(HloInstruction* instruction);
// Set the root of the computation to the given instruction. The instruction