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

LLVM cannot constant fold memchr with constant size #120913

Open
philnik777 opened this issue Dec 22, 2024 · 1 comment
Open

LLVM cannot constant fold memchr with constant size #120913

philnik777 opened this issue Dec 22, 2024 · 1 comment

Comments

@philnik777
Copy link
Contributor

void* test1(char* first, char val) {
  return __builtin_memchr(first, val, 2);
}

always generates a call to memchr, even though it could just check the two chars. I can't really see a case where calling memchr is faster than just checking the two chars. For larger N it would also be interesting to use vector comparisons for this instead of calling a function.

@nikic
Copy link
Contributor

nikic commented Dec 22, 2024

This needs an expansion to branchy code, so it could go into AggressiveInstCombine.

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

2 participants