dotnet/runtime

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

开放

#119,131 创建于 2025年8月27日

 (2 条评论) (2 个反应) (0 位负责人)C# (5,445 个派生)batch import
area-CodeGen-coreclrhelp wantedtenet-performance

仓库指标

星标
 (17,886 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南