Have irange use `if constexpr` (#94050)
Test Plan: Sandcastle
Differential Revision: D42997779
Pull Request resolved: https://github.com/pytorch/pytorch/pull/94050
Approved by: https://github.com/Skylion007, https://github.com/soumith, https://github.com/malfet