Repository: pytorch
Issue: RecursionError: maximum recursion depth exceeded in comparison
Labels: oncall: pt2

### 🐛 Describe the bug

Running following small tests results in recursion 


```py
    def test_a():
    
        def process_tensors(
            in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1
        ):
            for x0 in range(32):
                for x1 in range(6):
                    for x2 in range(64):
                        tmp0 = in_ptr0[x0, x1, x2]
                        tmp1 = in_ptr1[x1, x2]
                        tmp6 = in_ptr2[x0, x1, x2]
                        tmp13 = in_ptr3[x0 // 8, x1, x2]
                        tmp15 = in_ptr4[x0 // 8, x1, x2]
                        tmp2 = torch.cos(tmp1)
                        tmp3 = 1.0
                        tmp4 = tmp2 * tmp3
                        tmp5 = tmp0 * tmp4
                        tmp7 = torch.sin(tmp1)
                        tmp8 = tmp7 * tmp3
                        tmp9 = tmp6 * tmp8
                        tmp10 = tmp5 + tmp9
                        tmp11 = 0.3535533905932738
                        tmp12 = tmp10 * tmp11
                        tmp14 = tmp13 * tmp4
                        tmp16 = tmp15 * tmp8
                        tmp17 = tmp14 + tmp16
                        tmp18 = tmp17 * tmp11
                        out_ptr0[x0, x1, x2] = tmp12
                        out_ptr1[x0, x1, x2] = tmp18
    
        # Example usage:
        with torch.no_grad():
            in_ptr0 = torch.randn(32, 6, 64)
            in_ptr1 = torch.randn(6, 64)
            in_ptr2 = torch.randn(32, 6, 64)
            in_ptr3 = torch.randn(4, 6, 64)
            in_ptr4 = torch.randn(4, 6, 64)
            out_ptr0 = torch.zeros(32, 6, 64)
            out_ptr1 = torch.zeros(32, 6, 64)
            out_ptr0_ = torch.zeros(32, 6, 64)
            out_ptr1_ = torch.zeros(32, 6, 64)
            compiled_fn = torch.compile(
                process_tensors,
                backend="inductor",
                fullgraph=True,
            )
            process_tensors(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1)
           compiled_fn(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0_, out_ptr1_)
```

### Error logs

[log_.txt](https://github.com/user-attachments/files/18576776/log_.txt)

### Versions

PyTorch version: 2.4.1+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 19.1.5 (++20241125104649+086d8e6bb5da-1~exp1~20241125104703.66)
CMake version: version 3.29.0
Libc version: glibc-2.35

Python version: 3.10.12 (main, Nov  6 2024, 20:22:13) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-122-generic-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:                        52 bits physical, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               32
On-line CPU(s) list:                  0-31
Vendor ID:                            AuthenticAMD
Model name:                           AMD EPYC 9124 16-Core Processor
CPU family:                           25
Model:                                17
Thread(s) per core:                   1
Core(s) per socket:                   16
Socket(s):                            2
Stepping:                             1
Frequency boost:                      disabled
CPU max MHz:                          3711.9141
CPU min MHz:                          1500.0000
BogoMIPS:                             5991.11
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 pcid 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 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                       AMD-V
L1d cache:                            1 MiB (32 instances)
L1i cache:                            1 MiB (32 instances)
L2 cache:                             32 MiB (32 instances)
L3 cache:                             128 MiB (8 instances)
NUMA node(s):                         2
NUMA node0 CPU(s):                    0-15
NUMA node1 CPU(s):                    16-31
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Mitigation; safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] onnx==1.16.0
[pip3] onnxruntime==1.16.3
[pip3] onnxscript==0.1.0.dev20240327
[pip3] torch==2.4.1+cpu
[pip3] torch_geometric==2.5.2
[pip3] torch_qaic==0.1.0
[pip3] torch-tb-profiler==0.4.3
[conda] Could not collect


cc @chauhang @penguinwu