[PATCH][X86] Improved tablegen patters for matching TZCNT/LZCNT.

Andrea Di Biagio andrea.dibiagio at gmail.com
Mon Dec 8 09:48:12 PST 2014


Thanks Nadav!
Committed revision 223668.

On Mon, Dec 8, 2014 at 5:38 PM, Nadav Rotem <nrotem at apple.com> wrote:
> LGTM!  Thanks Andrea.
>
>> On Dec 8, 2014, at 9:36 AM, Andrea Di Biagio <andrea.dibiagio at gmail.com> wrote:
>>
>> Hi Nadav, Quentin (and all).
>>
>> This patch teaches ISel how to match a TZCNT/LZCNT from a conditional
>> move if the condition code is equal to X86_COND_NE.
>>
>> Existing tablegen patterns only allowed to match a TZCNT/LZCNT from a
>> X86cond with condition code equal to X86_COND_E. To avoid introducing
>> extra rules, I added an 'ImmLeaf' definition to check if the condition
>> code is COND_E or COND_NE.
>>
>> Example:
>> ///
>> unsigned foo(unsigned A) {
>>  unsigned bar = __builtin_clz(A);
>>  return !A ? 32 : bar;
>> }
>> ///
>>
>> Before, (on targets that feature LZCNT), we generated the following
>> sub-optimal assembly:
>>   lzcntl  %edi, %ecx
>>   movl  $32, %eax
>>   cmovael  %ecx, %eax
>>   retq
>>
>> Now we simply generate:
>>   lzcntl  %edi, %eax
>>   retq
>>
>> Please let me know if ok to submit.
>>
>> Thanks,
>> Andrea
>> <patch-lzcnt-tzcnt.diff>
>



More information about the llvm-commits mailing list