Missed optimization: Useless branches are kept when matching pattern #74183
Labels
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
EDIT: this is now reasonably optimized: https://rust.godbolt.org/z/nP599MaKM
So it just needs tests: @rustbot label +E-needs-test
I tried this code: https://rust.godbolt.org/z/hP3YKe
The code below does not compile because I strip some code, try the godbolt link above:
I expected to see this happen:
The generated code of
is_line_doc_comment
should be optimized out useless branches.And it should be equivalent to this function:
How would the two
is_line_doc_comment
functions be able to generate the same code?When
doc_comment_kind
inlined inis_line_doc_comment
,the optimizer could see that
Some((DocCommentKind::Block, _))
branches are useless and remove itis_line_doc_comment
doesn't care aboutAttrStyle
,The first branch overlaps with second branch of
DocCommentKind::Line
branches,keep this branch.
Other
None
branches don't overlap, just make them as fallback:Final result: https://rust.godbolt.org/z/jrPGr7
Instead, this happened:
The generated code still keeps some useless branches.
Maybe I am just asking too much from optimizer.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: