graal icon indicating copy to clipboard operation
graal copied to clipboard

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

Open chrisseaton opened this issue 4 years ago • 3 comments

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

chrisseaton avatar Dec 07 '21 12:12 chrisseaton

Example code to repro:

def foo(a)
  a + 1 + 1
end

loop do
  foo(rand(256))
end

Same issue on CE and EE.

eregon avatar Dec 07 '21 14:12 eregon

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

oubidar-Abderrahim avatar Dec 10 '21 14:12 oubidar-Abderrahim

The issue is tracked internally on GR--35795

oubidar-Abderrahim avatar Jan 03 '22 16:01 oubidar-Abderrahim