[PyTorch] Cache self.size(dim) in TensorShape functions (#55336)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/55336
The compiler cannot optimize this away because it does not know that size() has no side effects and doesn't get changed by anything else that goes on in the function.
ghstack-source-id: 125775704
Test Plan: Spot-check assembly to verify assertion I made in the summary
Reviewed By: ngimel
Differential Revision: D27577299
fbshipit-source-id: 7b7ce1044c4c0b437d95103a5d149acb5d86c1bd