This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Correctly set the is_zero_undef flag for llvm.cttz if <src> is non-zero
ClosedPublic

Authored by davide on Aug 12 2015, 1:43 PM.

Details

Summary

Implemented the approach you proposed on IRC, and it seems to work.

Testcase:
int myffs(int x)
{

return ffs(x) + 1;

}

Before the patch:

0000000000000000 <myffs>:

 0:   0f bc c7                bsf    %edi,%eax
 3:   b9 20 00 00 00          mov    $0x20,%ecx
 8:   0f 45 c8                cmovne %eax,%ecx
 b:   83 c1 02                add    $0x2,%ecx
 e:   b8 01 00 00 00          mov    $0x1,%eax
13:   85 ff                   test   %edi,%edi
15:   0f 45 c1                cmovne %ecx,%eax
18:   c3                      retq

After the patch:

0000000000000000 <myffs>:

 0:   0f bc cf                bsf    %edi,%ecx
 3:   83 c1 02                add    $0x2,%ecx
 6:   85 ff                   test   %edi,%edi
 8:   b8 01 00 00 00          mov    $0x1,%eax
 d:   0f 45 c1                cmovne %ecx,%eax
10:   c3                      retq

We can still probably use CMOVE and save another test instruction, but I feel like that can be implemented later.

Diff Detail

Repository
rL LLVM

Event Timeline

davide updated this revision to Diff 31974.Aug 12 2015, 1:43 PM
davide retitled this revision from to [SimplifyCFG] Correctly set the is_zero_undef flag for llvm.cttz if <src> is non-zero.
davide updated this object.
davide added a reviewer: majnemer.
davide added a subscriber: llvm-commits.
majnemer accepted this revision.Aug 12 2015, 1:46 PM
majnemer edited edge metadata.

Thanks for fixing this!

LGTM but please do not commit with SimplifyCFG in the commit title, this is a change to SimplifyLibCalls.

This revision is now accepted and ready to land.Aug 12 2015, 1:46 PM

Definitely, sorry for the typo.

This revision was automatically updated to reflect the committed changes.