On 08/04/2017 01:38 PM, Wilco Dijkstra wrote:
>> For constant strings of small length (upto 3?), I was wondering if it'd be a
>> good idea to manually unroll strcmp loop, similar to __strcmp_* macros in
>> bits/string.h?>
>> For eg in gimple-fold, transform
>> x = __builtin_strcmp(s, "ab")
>> to
>> x = s[0] - 'a';
>> if (x == 0)
>> {
>>    x = s[1] - 'b';
>>    if (x == 0)
>>      x = s[2];
>> }
> 
> If there is already code that does something similar (see comment #1 in 
> PR78809),
> it could be easily adapted to handle more cases.

There's emit_block_cmp_hints and compare_by_pieces.
There is not anything at present that will do the above
such that we avoid extra loads.

> Even better would be wider loads if you either know the alignment 
> of s or it's max size (although given the overhead of creating the
> return value that works best for equality).

It looks like compare_by_pieces does that.


r~

Reply via email to