-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
MIR optimization produces worse code by losing provenance information #146844
Copy link
Copy link
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-rust-for-linuxRelevant for the Rust-for-Linux projectRelevant for the Rust-for-Linux projectC-bugCategory: This is a bug.Category: This is a bug.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-rust-for-linuxRelevant for the Rust-for-Linux projectRelevant for the Rust-for-Linux projectC-bugCategory: This is a bug.Category: This is a bug.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code:
With
-O, thefoo()call cannot be optimized away. It can be optimized away however, if I use-Zmir-opt-level=0.https://godbolt.org/z/c5qE7Tvsf
My hypothesis is that:
format_argstakesxby referencexis annotated asnoaliaswhen passing to relevantArgumentconstructorsxcannot change duringstd::io::stdio::_printArgumentand thisArgumentis passed tostd::io::stdio::_print, and hence it has to assume conservatively that the value may change.This was affecting Rust-for-Linux as we have a
build_assert!which performs build-time assertions by requiring calls to be optimized away (Rust equivalent of C'sBUILD_BUG_ON), and @joelagnel discovered that adding a print can cause such assertion to trip up.@rustbot label: +A-rust-for-linux +I-slow +I-heavy