-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
C23 added a bunch of type generic bitwise functions like:
stdc_leading_zerosstdc_leading_onesstdc_trailing_zerosstdc_trailing_onesstdc_first_leading_zerostdc_first_leading_one(smells likeffsbut using proper signedness)stdc_first_trailing_zerostdc_first_trailing_onestdc_count_zerosstdc_count_onesstdc_has_single_bitstdc_bit_widthstdc_bit_floorstdc_bit_ceil
Refer to section 7.18 of the latest C23 draft (n3096 is what I'm looking at).
All of the above are type generic, so I expect libc implementations to use _Generic to dispatch to the proper variant. There are type specific variants of all of the above with suffixes uc, us, ui, ul, ull for unsigned char, unsigned short, unsigned int, unsigned long, and unsigned long long respectively.
We should recognize calls to all of the above (14 type-generic functions cross 5 specific types == 70 functions) and ensure that calling them with a constant value is recognized (in hosted mode) and folded properly, thereby eliminating the library dispatch.
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp should recognize these calls in IR and ensure we can elide the libcalls.