RecursionError for backend='inductor' with a loop
Labels: oncall: pt2

### 🐛 Describe the bug

Running the following code causes RecursionError.
It's not a very practical example, but it works totally fine in eager mode and with `torch.jit.script`.

``` python
import torch
class Net(torch.nn.Module):
    def forward(self, x):
        for i in range(1000):
            x = 1.0 * x
        return x
net = Net()
net = torch.compile(net)
x = torch.tensor([1.0])
print(net(x))
```

### Error logs

...

```
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/lowering.py", line 397, in <listcomp>
    return fn(*[load(index) for load in loaders])
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/lowering.py", line 397, in inner_fn
    return fn(*[load(index) for load in loaders])
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/lowering.py", line 397, in <listcomp>
    return fn(*[load(index) for load in loaders])
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/ir.py", line 2393, in loader
    return ops.load(self.name, indexer(index))
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/virtualized.py", line 232, in inner
    return OpsWrapper._wrap(getattr(_ops, name)(*new_args, **new_kwargs))
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/virtualized.py", line 132, in inner
    line = getattr(self.parent_handler, name)(*args, **kwargs)
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/virtualized.py", line 69, in inner
    fargs = [_arg_str(a) for a in args]
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/virtualized.py", line 69, in <listcomp>
    fargs = [_arg_str(a) for a in args]
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/virtualized.py", line 59, in _arg_str
    return sympy_str(a)
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/torch/_inductor/utils.py", line 395, in sympy_str
    return str(expr)
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/sympy/core/_print_helpers.py", line 29, in __str__
    return sstr(self, order=None)
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/sympy/printing/printer.py", line 372, in __call__
    return self.__wrapped__(*args, **kwargs)
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/sympy/printing/str.py", line 999, in sstr
    p = StrPrinter(settings)
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/sympy/printing/printer.py", line 261, in __init__
    self._settings = self._get_initial_settings()
  File "/home/sdym/.conda/envs/py39/lib/python3.9/site-packages/sympy/printing/printer.py", line 252, in _get_initial_settings
    settings = cls._default_settings.copy()
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
RecursionError: maximum recursion depth exceeded while calling a Python object
```


### Minified repro

_No response_

### Versions

Collecting environment information...
PyTorch version: 2.1.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Fedora release 36 (Thirty Six) (x86_64)
GCC version: (conda-forge gcc 10.3.0-16) 10.3.0
Clang version: 11.1.0 (https://github.com/conda-forge/clangdev-feedstock 2816c2cf231a2d3a6d621af9bbb2c590c9e63fe7)
CMake version: version 3.26.1
Libc version: glibc-2.35

Python version: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:56:21)  [GCC 10.3.0] (64-bit runtime)
Python platform: Linux-6.2.15-100.fc36.x86_64-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   43 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          64
On-line CPU(s) list:             0-63
Vendor ID:                       AuthenticAMD
Model name:                      AMD Ryzen Threadripper PRO 3975WX 32-Cores
CPU family:                      23
Model:                           49
Thread(s) per core:              2
Core(s) per socket:              32
Socket(s):                       1
Stepping:                        0
Frequency boost:                 enabled
CPU(s) scaling MHz:              52%
CPU max MHz:                     4368.1641
CPU min MHz:                     2200.0000
BogoMIPS:                        6986.81
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es
Virtualization:                  AMD-V
L1d cache:                       1 MiB (32 instances)
L1i cache:                       1 MiB (32 instances)
L2 cache:                        16 MiB (32 instances)
L3 cache:                        128 MiB (8 instances)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-63
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] flake8==6.0.0
[pip3] flake8-bugbear==23.6.5
[pip3] flake8-comprehensions==3.3.0
[pip3] flake8-executable==2.0.4
[pip3] flake8-logging-format==0.9.0
[pip3] flake8-pyi==23.5.0
[pip3] flake8-simplify==0.19.3
[pip3] mypy==1.4.1
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.1
[pip3] numpydoc==1.5.0
[pip3] onnx==1.14.1
[pip3] pytorch-sphinx-theme==0.0.19
[pip3] torch==2.1.0
[pip3] torcheval-nightly==2022.12.27
[pip3] torchsnapshot-nightly==2022.11.28
[pip3] torchtnt==0.0.4
[pip3] triton==2.1.0
[conda] magma-cuda116             2.6.1                         0    pytorch
[conda] mkl                       2022.1.0           h84fe81f_915    conda-forge
[conda] mkl-include               2022.1.0           h84fe81f_915    conda-forge
[conda] numpy                     1.23.1                   pypi_0    pypi
[conda] numpydoc                  1.5.0                    pypi_0    pypi
[conda] pytorch-sphinx-theme      0.0.19                   pypi_0    pypi
[conda] torch                     2.1.0                    pypi_0    pypi
[conda] torcheval-nightly         2022.12.27               pypi_0    pypi
[conda] torchfix                  0.1.1                    pypi_0    pypi
[conda] torchsnapshot-nightly     2022.11.28               pypi_0    pypi
[conda] torchtnt                  0.0.4                    pypi_0    pypi
[conda] triton                    2.1.0                    pypi_0    pypi


cc @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @zou3519