Skip to content

Store the type of each GVN value #143271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Jul 1, 2025

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum Value when defining a value index. This allows to simplify a lot of code.

Fixes #128094
Fixes #135128

r? @ghost for perf

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 1, 2025
@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 1, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 1, 2025
bors added a commit that referenced this pull request Jul 1, 2025
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

r? `@ghost` for perf
@bors
Copy link
Collaborator

bors commented Jul 1, 2025

⌛ Trying commit 2684875 with merge 0debe2b...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

☀️ Try build successful - checks-actions
Build commit: 0debe2b (0debe2b1f819bc0387b12f860b7de22201171ddc)

@rust-timer

This comment has been minimized.

@cjgillot cjgillot added the A-mir-opt-GVN Area: MIR opt Global Value Numbering (GVN) label Jul 1, 2025
@Kobzol
Copy link
Member

Kobzol commented Jul 1, 2025

Note: this benchmark will be delayed a bit, because we just switched to a new benchmarking machine and I need to backfill stable benchmark results. Sorry for that! It should be done sometime tomorrow, hopefully.

@rust-log-analyzer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0debe2b): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: missing data
Artifact size: 372.23 MiB -> 371.76 MiB (-0.13%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 2, 2025
@cjgillot cjgillot marked this pull request as ready for review July 3, 2025 09:56
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 3, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 3, 2025

r? compiler

@SparrowLii
Copy link
Member

Thanks for the great work!
r? @rust-lang/wg-mir-opt
since they should be more familar with this

@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2025

Failed to set assignee to eddyb: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@SparrowLii
Copy link
Member

SparrowLii commented Jul 7, 2025

r? @oli-obk
I think you know about GVN or can figure out who are available to review this work?

Comment on lines 399 to 402
let ty = self.ty(value);
let ty = self.ecx.layout_of(ty).ok()?;
let op = match *self.get(value) {
_ if ty.is_zst() => ImmTy::uninit(ty).into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly keeping notes to myself: this is why we get a test change from this PR. It is otherwise a transparent change that just tracks more data

ty.backend_repr,
BackendRepr::Scalar(..) | BackendRepr::ScalarPair(..)
) {
let variant = if ty.ty.is_enum() { Some(variant) } else { None };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orthogonal, but this check seems like it could just be removed and the if let Some(variant) =variant below could do the enum check instead.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 16, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 16, 2025

📌 Commit 4a95b16 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2025
fmease added a commit to fmease/rust that referenced this pull request Jul 17, 2025
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang#128094
Fixes rust-lang#135128

r? ``@ghost`` for perf
fmease added a commit to fmease/rust that referenced this pull request Jul 17, 2025
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang#128094
Fixes rust-lang#135128

r? ```@ghost``` for perf
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 15 pull requests

Successful merges:

 - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled)
 - #143271 (Store the type of each GVN value)
 - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143833 (Ban projecting into SIMD types [MCP838])
 - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests)
 - #143879 (parse `const trait Trait`)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143967 (constify `Option` methods)
 - #143985 (rustc_public: de-StableMIR-ize)
 - #144008 (Fix false positive double negations with macro invocation)
 - #144010 (Boostrap: add warning on `optimize = false`)
 - #144034 (tests: Test line number in debuginfo for diverging function calls)
 - #144049 (rustc-dev-guide subtree update)
 - #144056 (Copy GCC sources into the build directory even outside CI)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 17, 2025
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang#128094
Fixes rust-lang#135128

r? ````@ghost```` for perf
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 12 pull requests

Successful merges:

 - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled)
 - #143271 (Store the type of each GVN value)
 - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143967 (constify `Option` methods)
 - #144008 (Fix false positive double negations with macro invocation)
 - #144010 (Boostrap: add warning on `optimize = false`)
 - #144034 (tests: Test line number in debuginfo for diverging function calls)
 - #144049 (rustc-dev-guide subtree update)
 - #144056 (Copy GCC sources into the build directory even outside CI)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 12 pull requests

Successful merges:

 - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled)
 - #143271 (Store the type of each GVN value)
 - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143967 (constify `Option` methods)
 - #144008 (Fix false positive double negations with macro invocation)
 - #144010 (Boostrap: add warning on `optimize = false`)
 - #144034 (tests: Test line number in debuginfo for diverging function calls)
 - #144049 (rustc-dev-guide subtree update)
 - #144056 (Copy GCC sources into the build directory even outside CI)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 18, 2025
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang#128094
Fixes rust-lang#135128

r? `````@ghost````` for perf
bors added a commit that referenced this pull request Jul 18, 2025
Rollup of 12 pull requests

Successful merges:

 - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled)
 - #143271 (Store the type of each GVN value)
 - #143280 (Remove duplicate error about raw underscore lifetime)
 - #143649 (Add test for `default_field_values` and `const_default`)
 - #143699 (Make `AsyncDrop` check that it's being implemented on a local ADT)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143833 (Ban projecting into SIMD types [MCP838])
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143908 (`tests/ui`: A New Order [0/28] )
 - #143909 (docs(alloc::fmt): Make type optional, instead of matching empty string)
 - #143925 (Make slice comparisons const)
 - #143997 (Use $crate in macros for rustc_public (aka stable_mir))

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 18, 2025
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang#128094
Fixes rust-lang#135128

r? ``````@ghost`````` for perf
bors added a commit that referenced this pull request Jul 18, 2025
Rollup of 11 pull requests

Successful merges:

 - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled)
 - #143271 (Store the type of each GVN value)
 - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests)
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143967 (constify `Option` methods)
 - #144008 (Fix false positive double negations with macro invocation)
 - #144010 (Boostrap: add warning on `optimize = false`)
 - #144049 (rustc-dev-guide subtree update)
 - #144056 (Copy GCC sources into the build directory even outside CI)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt-GVN Area: MIR opt Global Value Numbering (GVN) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
8 participants