[JIT] remove dominated guards of functional values (#37105)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37105
If a value isn't mutated anywhere and is guarded by a node, then we can remove all other guards that are dominated by the first guard.
This reduces the number of (test name, Ifs/Loops, non-tensor nodes excluding getAttr and Bailouts) from the previous PR for the following tests:
```
Before: ('upsample', 0, 13)
After: ('upsample', 0, 5)
Before: ('upsample', 0, 2)
After: ('upsample', 0, 1)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 12)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 12)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 12)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 12)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 7)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 7)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 7)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 17)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 17)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 17)
After: ('interpolate', 0, 4)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 1, 21)
After: ('interpolate', 1, 18)
Before: ('interpolate', 0, 3)
After: ('interpolate', 0, 2)
Before: ('interpolate', 1, 21)
After: ('interpolate', 1, 20)
Before: ('interpolate', 0, 3)
After: ('interpolate', 0, 2)
Before: ('interpolate', 1, 13)
After: ('interpolate', 1, 11)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 1, 15)
After: ('interpolate', 1, 13)
Before: ('interpolate', 0, 3)
After: ('interpolate', 0, 2)
Before: ('interpolate', 1, 25)
After: ('interpolate', 1, 21)
Before: ('interpolate', 0, 1)
After: ('interpolate', 0, 0)
Before: ('interpolate', 1, 27)
After: ('interpolate', 1, 23)
Before: ('interpolate', 0, 3)
After: ('interpolate', 0, 2)
Before: ('test_nn_BatchNorm1d_affine', 2, 3)
After: ('test_nn_BatchNorm1d_affine', 1, 2)
Before: ('test_nn_BatchNorm1d_3d_input', 2, 3)
After: ('test_nn_BatchNorm1d_3d_input', 1, 2)
Before: ('test_nn_BatchNorm1d_affine_simple_average', 2, 5)
After: ('test_nn_BatchNorm1d_affine_simple_average', 1, 4)
Before: ('test_nn_BatchNorm1d_not_affine', 2, 3)
After: ('test_nn_BatchNorm1d_not_affine', 1, 2)
Before: ('test_nn_BatchNorm1d_3d_input_not_affine', 2, 3)
After: ('test_nn_BatchNorm1d_3d_input_not_affine', 1, 2)
Before: ('test_nn_BatchNorm1d_zero_batch', 2, 3)
After: ('test_nn_BatchNorm1d_zero_batch', 1, 2)
Before: ('test_nn_BatchNorm2d', 2, 3)
After: ('test_nn_BatchNorm2d', 1, 2)
Before: ('test_nn_BatchNorm2d_2d_simple_average', 2, 5)
After: ('test_nn_BatchNorm2d_2d_simple_average', 1, 4)
Before: ('test_nn_BatchNorm2d_momentum', 2, 3)
After: ('test_nn_BatchNorm2d_momentum', 1, 2)
Before: ('test_nn_BatchNorm2d_not_affine', 2, 3)
After: ('test_nn_BatchNorm2d_not_affine', 1, 2)
Before: ('test_nn_BatchNorm2d_zero_batch', 2, 3)
After: ('test_nn_BatchNorm2d_zero_batch', 1, 2)
Before: ('test_nn_BatchNorm3d', 2, 3)
After: ('test_nn_BatchNorm3d', 1, 2)
Before: ('test_nn_BatchNorm3d_3d_simple_average', 2, 5)
After: ('test_nn_BatchNorm3d_3d_simple_average', 1, 4)
Before: ('test_nn_BatchNorm3d_momentum', 2, 3)
After: ('test_nn_BatchNorm3d_momentum', 1, 2)
Before: ('test_nn_BatchNorm3d_not_affine', 2, 3)
After: ('test_nn_BatchNorm3d_not_affine', 1, 2)
Before: ('test_nn_BatchNorm3d_zero_batch', 2, 3)
After: ('test_nn_BatchNorm3d_zero_batch', 1, 2)
Before: ('test_nn_Transformer', 127, 467)
After: ('test_nn_Transformer', 122, 450)
```
Test Plan: Imported from OSS
Differential Revision: D21215652
Pulled By: eellison
fbshipit-source-id: 0365fc2e351caca7e1ccaa25428908a26e3f5343