Skip to content

Regression test for const promotion with Option<Ordering> #145651

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 1 commit into
base: master
Choose a base branch
from

Conversation

borsakv
Copy link

@borsakv borsakv commented Aug 20, 2025

https://rust.godbolt.org/z/EjxqE8WcT

Fixes #139093

Add a regression test to ensure that comparing Option<Ordering> to
Some(Ordering::Equal) does not trigger unnecessary const promotion
in MIR.

Previously, inlined constants like Some(Ordering::Equal) would get
promoted, leading to more complex MIR and redundant LLVM IR checks.
This test verifies that both the direct form and the let-binding form
now generate equivalent, simplified MIR.

r? cjgillot

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 20, 2025
@rustbot

This comment has been minimized.

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

What we are testing here is not really the absence of promoted constants. What we want to test is that both versions produce the same optimized MIR.

@@ -0,0 +1,31 @@
//@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=0
// EMIT_MIR_FOR_EACH_BIT_WIDTH
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promoted constants lead to poor MIR from comparisons
3 participants