Skip to content

Codegen generates infinite loop

Summary

GHC seems to produce an infinite loop in C-- for nofib/real/maillist.

This infinite loop doesn't seem to get triggered at all, but I'm working on a new register allocator and it got confused by this self loop.

C--:

 Main.process5_entry() { //  [R5, R4, R3, R2]
 // ...
 c482: // global
           _s3SL::I64 = _s3Sm::I64 - _s3SK::I64 + 1;
           if (%MO_S_Ge_W64(0, _s3SL::I64)) goto c482; else goto c48i;

goto c482, but vregs involved in check are not modified.

ASM:

     REC
        c482:
                movq %vI_s3Sm,%vI_n4bJ
                    # born:    %vI_n4bJ
                     
                subq %vI_s3SK,%vI_n4bJ
                     
                leaq 1(%vI_n4bJ),%vI_s3SL
                    # born:    %vI_s3SL
                    # r_dying: %vI_n4bJ
                     
                cmpq $0,%vI_s3SL
                     
                jle _blk_c482   # <-- self loop
                     
                jmp _blk_c48i
                    # r_dying: %vI_s3Sm %vI_s3SK %vI_s3SL

Steps to reproduce

Reproduced with GHC 8.10.4 and current master.

ghc -O2 nofib/real/maillist/Main.hs

Dumps:

Main.dump-asm-liveness

Main.dump-cmm

Main.dump-stg-final

Environment

  • GHC version used: 8.10.4, HEAD

Optional:

  • Operating System: Ubuntu LTS
  • System Architecture: X86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information