[PATCH] D128011: [SimplifyLibCalls] Transform memchr(STR, C, N) to chain of ORs
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 17 06:32:55 PDT 2022
xbolva00 added a comment.
In D128011#3591797 <https://reviews.llvm.org/D128011#3591797>, @nikic wrote:
> This looks quite nice for the examples -- but can't this create a very large chain of comparisons in some cases? Like if you check every second character you'd end up with 128 comparisons? (Or maybe you need every third, I can imagine that we manage to fold every second character to am mask).
Maybe we could introduce some limit (feel free to suggest some), but on the other hand, we often end up with nice switch or very simple code.
int g(char a)
{
if (__builtin_memchr ("abcdefghijklmnopqrstuvwxyz", a, 27) != 0)
return foo();
else return -1;
}
define dso_local noundef i32 @_Z1gc(i8 noundef signext %a) local_unnamed_addr #1 {
entry:
%0 = icmp ne i8 %a, 0
%1 = add i8 %a, -123
%2 = icmp ult i8 %1, -26
%cmp.not = and i1 %0, %2
br i1 %cmp.not, label %return, label %if.then
if.then: ; preds = %entry
%call1 = tail call noundef i32 @_Z3foov()
br label %return
return: ; preds = %entry, %if.then
%retval.0 = phi i32 [ %call1, %if.then ], [ -1, %entry ]
ret i32 %retval.0
}
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128011/new/
https://reviews.llvm.org/D128011
More information about the llvm-commits
mailing list