Promoted constants lead to poor MIR from comparisons #139093
Labels
A-MIR
Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
A-mir-opt
Area: MIR optimizations
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-mir-opt
Working group: MIR optimizations
Follow-along at https://rust.godbolt.org/z/Trzrobvo5
Consider these two functions that ought to be equivalent:
The latter ends up with about the MIR you'd expect: it checks for
Some
, then forEqual
The former, though, ends up with way more MIR because of the promoted const:
Apparently we can't even tell what the discriminant is of that
const direct::promoted[0]
, so we end up emitting even LLVM IR checks on the value of the constant, which it then has to turn around and optimize away again.Can we maybe just unilaterally un-promote simple (
Copy
+NoCell
+Scalar
/ScalarPair
) constants like this?The text was updated successfully, but these errors were encountered: