dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

Dead load of constant on entry #27417

Open rmacnak-google opened 8 years ago

rmacnak-google commented 8 years ago
Code for optimized function 'dart:collection__CustomHashMap@3220832_containsKey' {
...
        ;; Enter frame
0xee49c624    e92d4860               stmdb sp!, {pp, r6, fp, lr}
0xee49c628    e28db008               add fp, sp, #8
0xee49c62c    e596500b               ldr pp, [r6, #+11]
0xee49c630    e24dd00c               sub sp, sp, #12
        ;; B0
        ;; B1
0xee49c634    e59b100c               ldr r1, [fp, #+12]
0xee49c638    e59a0028               ldr r0, [r10, #+40]   true
        ;; CheckStackOverflow:4()
0xee49c63c    e59ac004               ldr ip, [r10, #+4]
0xee49c640    e15d000c               cmp sp, ip
0xee49c644    9a000090               bls +584 ; 0xee49c88c
        ;; v5 <- LoadField(v3, 28 {_validKey@3220832} [nullable dynamic], immutable=1)
0xee49c648    e591201b               ldr r2, [r1, #+27]
        ;; PushArgument(v5)
0xee49c64c    e52d2004               str r2, [sp, #-4]!
        ;; PushArgument(v4)
0xee49c650    e59bc008               ldr ip, [fp, #+8]
0xee49c654    e52dc004               str ip, [sp, #-4]!
        ;; v7 <- InstanceCall:8( call, v5, v4 IC[0: ])
        ;; SwitchableCall
0xee49c658    e59d0004               ldr r0, [sp, #+4]
0xee49c65c    e595900b               ldr r9, [pp, #+11]   ICData target:'call' num-args: 1 num-checks: 0
0xee49c660    e595600f               ldr r6, [pp, #+15]   [stub: ICCallThroughFunction]
0xee49c664    e596e007               ldr lr, [r6, #+7]
0xee49c668    e12fff3e               blx lr
0xee49c66c    e28dd008               add sp, sp, #8
        ;; ParallelMove r1 <- r0, r0 <- C
0xee49c670    e1a01000               mov r1, r0
0xee49c674    e59a0028               ldr r0, [r10, #+40]   true
        ;; Branch if StrictCompare:10(!==, v7, v9) goto (2, 3)
0xee49c678    e1510000               cmp r1, r0
0xee49c67c    0a000004               beq +24 ; 0xee49c694
...

The first load of r0 is dead. @fsc8000

fsc8000 commented 8 years ago

Is this a known register allocation issue @mraleph ?

mraleph commented 8 years ago

I will check it up.

rmacnak-google commented 6 years ago

I saw another example today which makes the issue more obvious because it uses a dozens of constants: dart:convert._Base64Decoder._inverseAlphabet. There it looks like the register allocator initially assigns all constants a live range extending for the whole GraphEntry. The first several constants are assigned to a register at entry, but due to register pressure the live range is split and the first range goes unused. This unused range also extends over the CheckStackOverflow instr, causing all the allocated constants to be spilled and restored in the slow path.