Skip to content

Missed optimization on only used once allocation #67199

@tesuji

Description

@tesuji

godbolt link: https://rust.godbolt.org/z/d_VvSo
Here are two snippets that I expect that they should have the same assembly:

pub fn foo(s: &str) -> bool {
    s != "FOOFOOLONGLONG"
}
pub fn foo(s: &str) -> bool {
     s.to_string() != "FOOFOOLONGLONG"
}

EDIT: For C version, gcc and clang also fails to optimized this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.I-slowIssue: 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.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions