Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to remove alloca #95987

Open
Kmeakin opened this issue Jun 18, 2024 · 1 comment
Open

Failure to remove alloca #95987

Kmeakin opened this issue Jun 18, 2024 · 1 comment

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Jun 18, 2024

str::starts_with(char) and str::ends_with(char) converts the 4-byte character codepoint into a 1-4 byte buffer on the stack, then compares against the start/end of the str's bytes contents. LLVM is able to remove the stack allocation when the char is a single byte, but if it is 2 or more, it is not able:

https://godbolt.org/z/zjhanPx7j
https://alive2.llvm.org/ce/z/MiAEjE

#[no_mangle]
pub fn src1(s: &str) -> bool {
    s.starts_with('a')
}

#[no_mangle]
pub fn tgt1(s: &str) -> bool {
    s.starts_with("a")
}

#[no_mangle]
pub fn src2(s: &str) -> bool {
    s.ends_with('a')
}

#[no_mangle]
pub fn tgt2(s: &str) -> bool {
    s.ends_with("a")
}

#[no_mangle]
pub fn src3(s: &str) -> bool {
    s.starts_with('£')
}

#[no_mangle]
pub fn tgt3(s: &str) -> bool {
    s.ends_with("£")
}

#[no_mangle]
pub fn src4(s: &str) -> bool {
    s.ends_with('£')
}

#[no_mangle]
pub fn tgt4(s: &str) -> bool {
    s.ends_with("£")
}
@efriedma-quic
Copy link
Collaborator

Dup of #52701?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants