This change adds a memrchr library function call emitter and simplifies the strrchr call handler to use it instead of duplicating a subset of the former function's transformations in the handler. This in turn enables transforming calls with the empty string S such as strrchr(S, C) to the test C ? S : 0. A call to memrchr when the length of the string is known is also likely to be faster than one to strrchr with the corresponding arguments.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1543 | This one probably needs an isLibFuncEmittable check, because memrchr is a GNU extension. It looks like PS targets do mark it as unavailable. |
llvm/lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1543 | isLibFuncEmittable is called from emitLibCall so I think this parts should be fine. Or am I missing something here? | |
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
362 | I did forget that memrchr isn't standard so this will fail on targets without it as you noted. Are we okay with losing that optimization on those targets or should I keep the existing optimization and use it when emitMemRChr fails? |
LGTM
llvm/lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1543 | Nope, my bad. It also looks like copyFlags will already handle a null argument correctly, so your code is fine as-is. | |
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
362 | As it's just the one target that disables it, I think it's fine to drop the optimization. |
This one probably needs an isLibFuncEmittable check, because memrchr is a GNU extension. It looks like PS targets do mark it as unavailable.