Skip to content

[mir-opt] Simplify SwitchInts of explictly written ranges to range tests #67488

Open
@Centril

Description

@Centril

Consider the program:

fn program(x: u8) -> u8 {
    match x {
        1 | 2 | 3 | 4 => 0,
        _ => 1,
    }
}

We will generate the following SwitchInt:

switchInt(_1) -> [1u8: bb2, 2u8: bb2, 3u8: bb2, 4u8: bb2, otherwise: bb1];

Ostensibly, something like this would be more profitable:

_2 = Le(const 1u8, _1);
switchInt(move _2) -> [false: bb2, otherwise: bb3];

This is the code you get from the range pattern 0..=4.

cc @wesleywiser @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions