This is an archive of the discontinued LLVM Phabricator instance.

[X86] Check for already emitted TEST pattern in EmitTest function.
AbandonedPublic

Authored by aivchenk on Aug 11 2017, 6:34 AM.

Details

Summary
This will generate this:

       testb   $1, %dil
       movl    $42, %eax
       movl    $31415, %ecx
       cmovnel %eax, %ecx
       movl    $4048, %edx
       movl    $666, %eax
       cmovnel %edx, %eax
       addl    %ecx, %eax
       retq

instead of this:

       andb    $1, %dil
       movl    $4048, %eax
       movl    $666, %ecx
       cmovnel %eax, %ecx
       testb   %dil, %dil
       movl    $42, %edx
       movl    $31415, %eax
       cmovnel %edx, %eax
       addl    %ecx, %eax
       retq

for this example:

define i32 @test(i1 %c) {
entry:
  %0 = select i1 %c, i32 42, i32 31415
  %1 = select i1 %c, i32 4048, i32 666
  %ret = add i32 %0, %1
  ret i32 %ret
}

Diff Detail

Event Timeline

aivchenk created this revision.Aug 11 2017, 6:34 AM
aivchenk added a subscriber: llvm-commits.

Kind ping :)

craig.topper edited edge metadata.Aug 24 2017, 10:11 AM

It looks like Chandler's patch D37096 might also be fixing some of this and that might be a more consistent fix. I'd like to hold off on this until we disposition that patch.

RKSimon edited edge metadata.Sep 4 2017, 10:23 AM

It looks like Chandler's patch D37096 might also be fixing some of this and that might be a more consistent fix. I'd like to hold off on this until we disposition that patch.

What's happening with this? Chandler's patch landed at rL311737.

aivchenk abandoned this revision.Sep 5 2017, 4:18 AM

Chandler's patch fixed the issue in more general way.