[TensorExpr] Fix bug in For elimination in the IRSimplifier. (#36965)
Summary:
When doing elimination of For loops which execute once, e.g. `for i = 0; i < 1; ++i { thing; } => thing;` we do var substitution while the temporary simplifier ExprNodes still exist, which could put them in an invalid state and leave unsimplified terms in the expression. The fix is to apply substitution before simplifying the body of the for loop.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36965
Differential Revision: D21145248
Pulled By: nickgg
fbshipit-source-id: d874600c7a098fc05b8ef3109e516e2eaa2c24e0