runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[RyuJIT/ARM32][JitStress=1] JIT/CodeGenBringUpTests/DivConst/DivConst.sh

Open hqueue opened this issue 9 years ago • 5 comments

From dotnet/runtime#9227, following test is failed with a incorrect result.

FAILED   - [   2][   8s]JIT/CodeGenBringUpTests/DivConst/DivConst.sh

From the test code, following test is failed.

// tests/src/JIT/CodeGenBringUpTests/DivConst.cs
        {   
            long dividend = 45;

            if (DivConst.I8_Div_7(ref dividend) != 6)
            {   
                return Fail;   // Failed here!!
            }
        }

After looking into Jitdump, it seems that there seems to be a wrong stack manipulation regarding ref long parameter.

Without JitStress=1,

IN00fc: 0002F6      movs    r0, 45
IN00fd: 0002F8      movs    r3, 0
IN00fe: 0002FA      str     r0, [sp+0x70]       // [V04 loc4]
IN00ff: 0002FC      str     r3, [sp+0x74]       // [V04 loc4+0x04]
IN0100: 0002FE      add     r0, sp, 112 // [V04 loc4]    // r0 is sp + 112 which is (sp + 0x70),  where `long` value is stored.
IN0101: 000300      movw    r3, 0x9ce4
IN0102: 000304      movt    r3, 0x75b2
IN0103: 000308      ldr     r3, [r3]
IN0104: 00030A      blx     r3          // DivConst:I8_Div_7(byref):long
IN0105: 00030C      str     r0, [sp+0x48]       // [V21 rat4]
IN0106: 00030E      str     r1, [sp+0x4c]       // [V21 rat4+0x04]
IN0107: 000310      ldr     r0, [sp+0x48]       // [V21 rat4]
IN0108: 000312      ldr     r1, [sp+0x4c]       // [V21 rat4+0x04]
IN0109: 000314      eor     r0, r0, 6
IN010a: 000318      orrs    r0, r1
IN010b: 00031A      bne     G_M59476_IG40

With JitStress=1,

IN00fd: 0002FA      movs    r0, 45
IN00fe: 0002FC      movs    r3, 0
IN00ff: 0002FE      str     r0, [sp+0x7c]       // [V04 loc4+0x08]
IN0100: 000300      str     r3, [sp+0x80]       // [V04 loc4+0x0c]
IN0101: 000302      add     r0, sp, 116 // [V04 loc4]          // 116 is 0x74
IN0102: 000304      adds    r0, r0, 4         // r0 is now `sp+0x78`, not `sp+0x7c`.  Wrong!!!!!!!!!!!!!!!!
IN0103: 000306      movw    r3, 0x9ce4
IN0104: 00030A      movt    r3, 0x75b5
IN0105: 00030E      ldr     r3, [r3]
IN0106: 000310      blx     r3          // DivConst:I8_Div_7(byref):long
IN0107: 000312      str     r0, [sp+0x48]       // [V21 rat4]
IN0108: 000314      str     r1, [sp+0x4c]       // [V21 rat4+0x04]
IN0109: 000316      ldr     r0, [sp+0x48]       // [V21 rat4]
IN010a: 000318      ldr     r1, [sp+0x4c]       // [V21 rat4+0x04]
IN010b: 00031A      eor     r0, r0, 6
IN010c: 00031E      orrs    r0, r1
IN010d: 000320      bne     G_M59476_IG40

/cc: @dotnet/arm32-contrib

hqueue avatar Nov 09 '17 13:11 hqueue

I will take a look at this.

hqueue avatar Nov 09 '17 13:11 hqueue

@hqueue Have you made any progress with a fix?

BruceForstall avatar Nov 16 '17 05:11 BruceForstall

@BruceForstall I found some differences in morphing phases and in decompoing TYP_LONG. I will share my analysis. Because I'm not used to frontend(esp. morphing), didn't dig more by now. If you want please take a look at this issue :)

Difference before fgMorphBlocks()

  • [PASSED] Without JitStress ,
*************** In fgMarkAddressExposedLocals() 

Local V01 should not be enregistered because: it is address exposed 

Local V02 should not be enregistered because: it is address exposed

Local V03 should not be enregistered because: it is address exposed

Local V04 should not be enregistered because: it is address exposed

  • [FAILED] With JitStress=1, TYP_LONG is decomposed.
  *************** In fgMarkAddressExposedLocals()
  
  Local V01 should not be enregistered because: it is address exposed
  
  Local V02 should not be enregistered because: it is address exposed   
  
  Local V03 should not be enregistered because: it is address exposed
  
  Local V04 should not be enregistered because: it is address exposed
  
  
  *** JitStress: STRESS_LCL_FLDS ***
  
  
  Local V02 should not be enregistered because: it is address exposed
  
  Local V04 should not be enregistered because: it is address exposed

Difference during morphing

  • [PASSED] Without JitStress , During morphing, [000354] is "address exposed(AX)".
*************** In fgMorphBlocks()
...(omitted)..
***** BB29, stmt 39  
               [000356] -------------             *  STMT      void  (IL 0x1E3...0x1E6)
               [000353] -----+-------             |  /--*  CNS_LNG   long   0x000000000000002d
               [000355] -A--G+-------             \--*  ASG       long
               [000354] D---G+-N-----                \--*  LCL_VAR   long  (AX) V04 loc4

***** BB29, stmt 40 
               [000365] -------------             *  STMT      void  (IL 0x1E8...0x1F1)
               [000364] --CXG+-------             \--*  JTRUE     void
               [000362] -----+-------                |  /--*  CNS_LNG   long   0x0000000000000006
               [000363] J-CXG+-N--S--                \--*  NE        int
               [000359] --CXG+-------                   \--*  CALL      long   DivConst.I8_Div_7,NA
               [000358] L----+------- arg0 in r0           \--*  ADDR      int
               [000357] ----G+-N-----                         \--*  LCL_VAR   long  (AX) V04 loc4
  • [FAILED] With JitStress=1, TYP_LONG is decomposed. During morphing, [000611] and [000612] are inserted and [000354] is not "address exposed". Something wrong here? In the above, V04 is considered to be address exposed.
*************** In fgMorphBlocks()
...(omitted)..
  ***** BB29, stmt 39
                 [000356] -------------             *  STMT      void  (IL 0x1E3...0x1E6)
                 [000353] -----+-------             |  /--*  CNS_LNG   long   0x000000000000002d
                 [000355] -A--G+-------             \--*  ASG       long     
                 [000354] U---G+-N-----                \--*  LCL_FLD   long   V04 loc4         [+8]
  
  ***** BB29, stmt 40
                 [000365] -------------             *  STMT      void  (IL 0x1E8...0x1F1)
                 [000364] --CXG+-------             \--*  JTRUE     void
                 [000362] -----+-------                |  /--*  CNS_LNG   long   0x0000000000000006
                 [000363] J-CXG+-N--S--                \--*  NE        int
                 [000359] --CXG+-------                   \--*  CALL      long   DivConst.I8_Div_7,NA
                 [000611] -----+-------                      |  /--*  CNS_INT   int    4
                 [000612] ----G+------- arg0 in r0           \--*  ADD       byref
                 [000358] L----+-------                         \--*  ADDR      byref 
                 [000357] ----G+-N-----                            \--*  LCL_VAR   blk   (AX) V04 loc4

During decomposing TYP_LONG

  • [PASSED] Without JitStress , TYP_LONG is not decomposed. You can find that [000355] STORE_LCL_VAR is "address exposed(AX)".
Decomposing TYP_LONG tree.  BEFORE:
N001 (  4,  9) [000353] -------------      t353 =    CNS_INT   int    45
               [000876] -------------      t876 =    CNS_INT   int    0
                                                  /--*  t353   int    
                                                  +--*  t876   int    
               [000877] -------------      t877 = *  LONG      long   
                                                  /--*  t877   long
N003 ( 11, 15) [000355] DA--G--------             *  STORE_LCL_VAR long  (AX) V04 loc4
Decomposing TYP_LONG tree.  AFTER:
N001 (  4,  9) [000353] -------------      t353 =    CNS_INT   int    45 
               [000876] -------------      t876 =    CNS_INT   int    0
                                                  /--*  t353   int    
                                                  +--*  t876   int    
               [000877] -------------      t877 = *  LONG      long       
                                                  /--*  t877   long
N003 ( 11, 15) [000355] DA--G--------             *  STORE_LCL_VAR long  (AX) V04 loc4
  • [FAILED] With JitStress=1, TYP_LONG is decomposed. You can find that [000355] STORE_LCL_VAR is not "address exposed(AX)".
  Decomposing TYP_LONG tree.  BEFORE:               
  N001 (  4,  9) [000353] -------------      t353 =    CNS_INT   int    45
                 [000880] -------------      t880 =    CNS_INT   int    0
                                                    /--*  t353   int    
                                                    +--*  t880   int    
                 [000881] -------------      t881 = *  LONG      long   
                                                    /--*  t881   long
  N003 ( 11, 17) [000355] UA--G--------             *  STORE_LCL_FLD long   V04 loc4         [+8]
  New refCnts for V04: refCnt =  3, refCntWtd = 0
  
  Decomposing TYP_LONG tree.  AFTER:
  N001 (  4,  9) [000353] -------------      t353 =    CNS_INT   int    45
                 [000880] -------------      t880 =    CNS_INT   int    0
                                                    /--*  t353   int    
  N003 ( 11, 17) [000355] UA--G--------             *  STORE_LCL_FLD int    V04 loc4         [+8]

During the code generation

[PASSED] Without JitStress , TYP_LONG is not decomposed.

                                                              /--*  t353   int
                                                              +--*  t876   int     
Generating: N705 (???,???) [000877] -c-----------      t877 = *  LONG      long   REG NA
                                                              /--*  t877   long  
Generating: N707 ( 11, 15) [000355] DA--G--------             *  STORE_LCL_VAR long  (AX) V04 loc4          NA REG NA
IN00fe:             str     r0, [sp+0x70]       // [V04 loc4]
IN00ff:             str     r3, [sp+0x74]       // [V04 loc4+0x04]
    
Added IP mapping: 0x01E8 STACK_EMPTY (G_M59476_IG30,ins#4,ofs#8)
Generating: N709 ( 29, 29) [000365] -------------                IL_OFFSET void   IL offset: 0x1e8 REG NA
Generating: N711 (  3,  2) [000357] -------N-----      t357 =    LCL_VAR_ADDR byref  V04 loc4          r0 REG r0
IN0100:             add     r0, sp, 112 // [V04 loc4]   
                                                        Byref regs: 0000 {} => 0001 {r0}
                                                              /--*  t357   byref
Generating: N713 (???,???) [000885] -------------      t885 = *  PUTARG_REG byref  REG r0
                                                        Byref regs: 0001 {r0} => 0000 {}
                                                        Byref regs: 0000 {} => 0001 {r0}
       



Generating: N715 (  3,  7) [000886] -------------      t886 =    CNS_INT(h) int    0x75B47CE4 ftn REG r3
IN0101:             movw    r3, 0x7ce4
IN0102:             movt    r3, 0x75b4
                                                              /--*  t886   int
Generating: N717 (  6,  9) [000887] -------------      t887 = *  IND       int    REG r3
IN0103:             ldr     r3, [r3]
                                                              /--*  t885   byref  arg0 in r0
                                                              +--*  t887   int    control expr
Generating: N719 ( 19, 14) [000359] --CXG--------      t359 = *  CALL      long   DivConst.I8_Div_7 $38c REG r0,r1
                                                        Byref regs: 0001 {r0} => 0000 {}
Call: GCvars=00000000 {}, gcrefRegs=0000 {}, byrefRegs=0000 {}
IN0104:             blx     r3          // DivConst:I8_Div_7(byref):long

[FAILED] With JitStress=1, TYP_LONG is decomposed.

                                                                /--*  t353   int
  Generating: N709 ( 11, 17) [000355] UA--G--------             *  STORE_LCL_FLD int    V04 loc4         [+8] NA REG NA
  IN00ff:             str     r0, [sp+0x7c]       // [V04 loc4+0x08]      
                                                                /--*  t880   int
  Generating: N711 (???,???) [000882] U------------             *  STORE_LCL_FLD int    V04 loc4         [+12] NA REG NA
  IN0100:             str     r3, [sp+0x80]       // [V04 loc4+0x0c]
  
  Added IP mapping: 0x01E8 STACK_EMPTY (G_M59476_IG30,ins#4,ofs#8)
  Generating: N713 ( 31, 31) [000365] -------------                IL_OFFSET void   IL offset: 0x1e8 REG NA
  Generating: N715 (  3,  2) [000357] -------N-----      t357 =    LCL_VAR_ADDR byref  V04 loc4          r0 REG r0
  IN0101:             add     r0, sp, 116 // [V04 loc4]
                                                          Byref regs: 0000 {} => 0001 {r0}
  Generating: N717 (  1,  1) [000611] -c-----------      t611 =    CNS_INT   int    4 REG NA $55
                                                                /--*  t357   byref
                                                                +--*  t611   int
  Generating: N719 (  5,  5) [000612] ----G--------      t612 = *  ADD       byref  REG r0 $287
                                                          Byref regs: 0001 {r0} => 0000 {}
  IN0102:             adds    r0, r0, 4
                                                          Byref regs: 0000 {} => 0001 {r0}
                                                                /--*  t612   byref
  Generating: N721 (???,???) [000890] ----G--------      t890 = *  PUTARG_REG byref  REG r0
                                                          Byref regs: 0001 {r0} => 0000 {}
                                                          Byref regs: 0000 {} => 0001 {r0}
  Generating: N723 (  3,  7) [000891] -------------      t891 =    CNS_INT(h) int    0x75B61CE4 ftn REG r3
  IN0103:             movw    r3, 0x1ce4
  IN0104:             movt    r3, 0x75b6
  Generating: N725 (  6,  9) [000892] -------------      t892 = *  IND       int    REG r3
  IN0105:             ldr     r3, [r3]
                                                                /--*  t890   byref  arg0 in r0
                                                                +--*  t892   int    control expr
  Generating: N727 ( 21, 16) [000359] --CXG--------      t359 = *  CALL      long   DivConst.I8_Div_7 $38d REG r0,r1
                                                          Byref regs: 0001 {r0} => 0000 {}
  Call: GCvars=00000000 {}, gcrefRegs=0000 {}, byrefRegs=0000 {}
  IN0106:             blx     r3          // DivConst:I8_Div_7(byref):long

hqueue avatar Nov 17 '17 11:11 hqueue

Ok, I took a look. It turns out to be a very simple fix. All the crazy morphing you're seeing is a particular stress mode where we convert many LCL_VAR to BLK types. There is some ARM-specific alignment code that was getting the offset wrong for ADDR nodes.

Thanks for the investigation!

Fix is in dotnet/coreclr#15088

BruceForstall avatar Nov 18 '17 02:11 BruceForstall

@BruceForstall Thanks for the fix :) As I left comment at dotnet/coreclr#15088, the PR dotnet/coreclr#15088 fixes this issue on Raspberry pi.

hqueue avatar Nov 20 '17 04:11 hqueue