Skip to content

Const prop creates assignments from large constants #73203

Closed
@oli-obk

Description

@oli-obk

Background discussion: #71911 (comment)

If we have an assignment of Rvalue::Aggregate in const-prop, and we can figure out that all fields are Operand::Const, we end up replacing the Rvalue::Aggregate with an Rvalue::Use of a constant that contains the entire aggregate. This may end up creating large assignments that copy from constant memory to the stack at runtime. It may sometimes be cheaper to just build the constant at runtime. This is very true if the constant is actually a None where the Some part is a huge value. We'd have a very big constant with most bits undefined that we copy over, even if the runtime operation would just be "set the discriminant bits".

cc @rust-lang/wg-mir-opt

Should we have some heuristic here? Should we only do this optimization for Scalars and ScalarPairs? Other opinions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-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