Odd Loop x86 CodeGen Behavior

Vladimir Kozlov Vladimir.Kozlov at Sun.COM
Tue Dec 9 13:29:55 PST 2008


The stack spills you see are generated by Register Allocator.
And I agree they are not needed.
Do you have a small test to show this problem?

Thanks,
Vladimir

Edward Lee wrote:
> Some reason codegen is adding unnecessary stores that in turn cause
> unnecessary loads to be added. Below is a snippet of the output of
> opto assembly after some changes I've done to the nodes such as
> removing the safepoint for this particular backedge. Any tips on where
> I should look would be useful.
> 
> The high level code is doing HashMap.get where the object has a custom
> equals method inlined that checks a long field. Kinda like..
> 
> if (entry.hash == hash_ECX && entry.key.longField == long_ESP_64)
> 
> The odd behavior is in B8 and B10, where long_ESP_64 gets loaded into
> EAX,EDX in B8 and written back to the stack in B10 even though both
> pair of load/stores are unnecessary. It seems that code gen is
> confused by the fact that B3 loads long_ESP_64 into EAX,EDX for the
> long compare and the branch from B3->B9 has a higher frequency
> (0.029548) than the branch B2->B8 (0.023747).
> 
> But the really odd thing is why does B10 even exist in the first
> place? There's no point in writing EAX,EDX back to the stack, and this
> seems to be purely an artifact of code gen as the ideal graph doesn't
> have any store nodes to that location.
> 
> 080   B2: # B8 B3 <- B1 B10   Loop: B2-B10 inner  Freq: 1.01271
> 080     MOV    EDI,[EBX + #8] ! Field java/util/HashMap$Entry.hash
> 083     CMP    EDI,ECX
> 085     Jne,s  B8  P=0.023747 C=6443.000000
> 085
> 087   B3: # B9 B4 <- B2  Freq: 0.98866
> 087     MOV    ESI,[EBX + #12] ! Field java/util/HashMap$Entry.key
> 08a     MOV    EBP.lo,[ESI + #8]
>   MOV    EBP.hi,[ESI + #8]+4 ! Field customEquals.longField
> 090     MOV    EAX,[ESP + #64]
>   MOV    EDX,[ESP + #68]
> 098     CMP    EAX.lo,EBP.lo  ! Long compare; set flags for low bits
>   JNE,s  skip
>   CMP    EAX.hi,EBP.hi
>   skip:
> 09e     Jne,s  B9  P=0.029548 C=6701.000000
> 09e
> 0a0   B4: # B5 <- B3 B9  Freq: 0.959448
> 0a0     MOV    EBX,[EBX + #16] ! Field java/util/HashMap$Entry.value
> ...
> 0d8     RET
> 
> 0e0   B8: # B9 <- B2  Freq: 0.0240485
> 0e0     MOV    EAX,[ESP + #64]
>   MOV    EDX,[ESP + #68]
> 0e0
> 0e8   B9: # B7 B10 <- B3 B8  Freq: 0.0532613
> 0e8     MOV    EBX,[EBX + #20] ! Field java/util/HashMap$Entry.next
> 0eb     TEST   EBX,EBX
> 0ed     Je,s  B4  P=0.038502 C=718.000000
> 0ed
> 0ef   B10: #  B2 <- B9  Freq: 0.0512106
> 0ef     MOV    [ESP + #64],EAX
>   MOV    [ESP + #68],EDX
> 0f7     JMP    B2
> 
> Ed



More information about the hotspot-dev mailing list