dotnet/runtime

CSE seems to fail when writing `x / cns` and `x % cns` for unsigned integers

Aberta

#119.131 aberto em 27 de ago. de 2025

 (2 comentários) (2 reações) (0 responsável)C# (5.445 forks)batch import
area-CodeGen-coreclrhelp wantedtenet-performance

Métricas do repositório

Stars
 (17.886 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

Description

CSE seems to fail if I write something like:

uint Natural(uint index)
{
    uint arrIndex = index / 3;
    uint bitIndex = index % 3;

    return arrIndex + bitIndex;
}

(it does the division twice).

This seems to only be an issue for unsigned integers not using DivRem.

Godbolt.

Configuration

Seems to reproduce on any .NET version on godbolt - I've only checked the issue on x64.

Regression?

Probably not.

Analysis

@tannergooding was saying it seems that UMOD might be missing early expansion altogether & it's getting carried down to rationalisation.

Guia do colaborador