Allow DCE to clean up some mutable ops (#14601)
authorMichael Suo <suo@fb.com>
Mon, 3 Dec 2018 21:27:59 +0000 (13:27 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 3 Dec 2018 21:31:08 +0000 (13:31 -0800)
commitb768db081005b22b14e74907feb181360314d63f
tree2fb5b703ce120cc801ae5dcd366161d9b9981a48
parent9783ce3825d33b1e42982474485bd9e84c0a48ff
Allow DCE to clean up some mutable ops (#14601)

Summary:
This PR makes DCE a little smarter in the presence of mutable ops. Previously mutable ops could never be cleaned up, now they can be cleaned up if we can prove there are no live uses of any alias sets that the op writes to.

This behavior is optional; if you pass DCE a block instead of a graph, it will do the same thing as before. Also changed `InlineAutographSubgraph` to use the common subgraph utils.

Tested on traced ResNet, and it gets rid of the dead code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14601

Differential Revision: D13309118

Pulled By: suo

fbshipit-source-id: dac2791e7d2ecf219ae717a2759b83c1e927f254
20 files changed:
test/expect/TestScript.test_mutable_dce.expect [new file with mode: 0644]
test/expect/TestScript.test_mutable_dce_block.expect [new file with mode: 0644]
test/expect/TestScript.test_mutable_dce_graph_input.expect [new file with mode: 0644]
test/expect/TestScript.test_mutable_dce_list.expect [new file with mode: 0644]
test/expect/TestScript.test_mutable_dce_loop.expect [new file with mode: 0644]
test/test_jit.py
torch/csrc/jit/export.cpp
torch/csrc/jit/init.cpp
torch/csrc/jit/ir.cpp
torch/csrc/jit/ir.h
torch/csrc/jit/passes/alias_analysis.cpp
torch/csrc/jit/passes/alias_analysis.h
torch/csrc/jit/passes/common_subexpression_elimination.cpp
torch/csrc/jit/passes/constant_propagation.cpp
torch/csrc/jit/passes/dead_code_elimination.cpp
torch/csrc/jit/passes/dead_code_elimination.h
torch/csrc/jit/passes/inline_autodiff_subgraphs.cpp
torch/csrc/jit/passes/lower_tuples.cpp
torch/csrc/jit/passes/shape_analysis.cpp
torch/csrc/jit/passes/utils/subgraph_utils.cpp