KEMBAR78
[RyuJIT][ARM] Redundant overflow check in "C / X" · Issue #46010 · dotnet/runtime · GitHub
Skip to content

[RyuJIT][ARM] Redundant overflow check in "C / X" #46010

@EgorBo

Description

@EgorBo
int Test(int a) => 1000 / b; // same for 'C % b'

Current arm64 codegen:

G_M17171_IG01: 
        A9BF7BFD          stp     fp, lr, [sp,#-16]!
        910003FD          mov     fp, sp
G_M17171_IG02:       
        52807D00          mov     w0, #0x3e8
        7100005F          cmp     w2, #0
        54000140          beq     G_M17171_IG06
        3100045F          cmn     w2, #1
        54000081          bne     G_M17171_IG03
        2B00001F          adds    wzr, w0, w0
        54000041          bne     G_M17171_IG03 ; <-- btw, two subsequent jumps?? 
        54000086          bvs     G_M17171_IG05
G_M17171_IG03:       
        1AC20C00          sdiv    w0, w0, w2
G_M17171_IG04:       
        A8C17BFD          ldp     fp, lr, [sp],#16
        D65F03C0          ret     lr
G_M17171_IG05:           
        94000000          bl      CORINFO_HELP_OVERFLOW
G_M17171_IG06:            
        94000000          bl      CORINFO_HELP_THROWDIVZERO
        D43E0000          bkpt
; Total bytes of code 64

As far as I understand overflow can only happen if we divide int.MinValue by -1 so it's not the case for C / x where C is not int.MinValue

Also, GT_ARRLEN can't be -1 and int.MinValue so e.g. array.Length % x or x % array.Length shouldn't produce any overflow checks as well.

category:cq
theme:div-mod-rem
skill-level:intermediate
cost:medium
impact:medium

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions