oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.07k stars 1.6k forks source link

[GR-35795] Graal should combine multiple exact integer arithmetic operations #4096

Open chrisseaton opened 2 years ago

chrisseaton commented 2 years ago

Ruby code that uses exact integer arithmetic such as a + 1 + 1 will not be combined to a + 2. I guess it's because it thinks the two deoptimisations that you get on the two overflows are different so need different deoptimisation points? Both sides of the IntegerAddExactSplit actually eventually lead to the same DynamicDeoptimize node though!

Screenshot 2021-12-07 at 12 55 58
        0x122ad9afe:    add     eax, 1
                                ;Comment 97:    14 BRANCH trueDestinationProbability: 0.0 condition: |of| trueDestination: B0 -> B13 falseDestination: B0 -> B1
        0x122ad9b01:    jo      0x122ad9bf5
                                ;Comment 103:   block B1 null
                                ;Comment 103:   16 [] = LABEL numbPhis: 0 align: false label: ?
                                ;Comment 103:   18 r10|DWORD = ADD rax|DWORD y: 1 size: DWORD
        0x122ad9b07:    mov     r10d, eax
        0x122ad9b0a:    add     r10d, 1
                                ;Comment 110:   20 BRANCH trueDestinationProbability: 0.0 condition: |of| trueDestination: B1 -> B12 falseDestination: B1 -> B2
        0x122ad9b0e:    jo      0x122ad9bd7
                                ;Comment 116:   block B2 null
                                ;Comment 116:   22 [] = LABEL numbPhis: 0 align: false label: ?
                                ;Comment 116:   24 rax|DWORD = LEA [r10|DWORD + 128] size: DWORD

@eregon

eregon commented 2 years ago

Example code to repro:

def foo(a)
  a + 1 + 1
end

loop do
  foo(rand(256))
end

Same issue on CE and EE.

oubidar-Abderrahim commented 2 years ago

Hi, Thank you for reporting this, we will take a look into it and get back to you

oubidar-Abderrahim commented 2 years ago

The issue is tracked internally on GR--35795