Skip to content

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?

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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