Reodering is done with checking dependencies, including side effects:

  
      github.com
  
  
    pytorch/pytorch/blob/58a7e73a95865e5c02a581703c39edd671495a6c/torch/csrc/jit/ir/alias_analysis.h#L98-L108 1

// Move 'n' (already in the graph) after 'movePoint' in the topological order.
//
// Tries to preserve value dependencies, so other nodes might be moved. We
// make two guarantees about the postcondition of the node list:
//   - `n` is directly after `movePoint`.
//   - only nodes between `n` and `movePoint` have been moved.
//
// Returns `false` if it's impossible to move `n` after `MovePoint` without
// violating dependencies, otherwise executes the move and returns `true`
TORCH_API bool moveAfterTopologicallyValid(Node* n, Node* movePoint);
TORCH_API bool moveBeforeTopologicallyValid(Node* n, Node* movePoint);



  
  
    
    
  
  


Best regards
Thomas