Fix a bug in the associative & commutative rewrite in constant folding:
authorA. Unique TensorFlower <gardener@tensorflow.org>
Sun, 21 Jan 2018 17:22:43 +0000 (09:22 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Sun, 21 Jan 2018 17:26:38 +0000 (09:26 -0800)
commitf31c1acda127e361b797b6f61b6ed3d30d7ea2af
tree157bdc9405212169fdb6557ef164bdd7a0ee0da8
parentc2f75aea52b0dd5c3623d96cb2334f5d7e90e69c
Fix a bug in the associative & commutative rewrite in constant folding:
I finally tracked it down to the case where we do the transformation:

    //
    //                      +                +       = parent
    //                     / \              / \
    //                    C   +    -- >    X   +     = children
    //                       / \              / \
    //                      X   Y            C   Y   = leaves

when there exists a control dependency from the child '+' to C. This control dependency creates a cycle in the graph when X and C are simply swapped. We can fix it by moving the control dependency and anchoring it on Y instead (We still need it in case we are inside a frame).

PiperOrigin-RevId: 182705910
tensorflow/core/grappler/optimizers/constant_folding.cc
tensorflow/core/grappler/optimizers/constant_folding_test.cc