This is an archive of the discontinued LLVM Phabricator instance.

X86: If we have an instruction that sets a flag and a zero test on the input of that instruction try to eliminate the test.
ClosedPublic

Authored by bkramer on Apr 22 2014, 9:46 AM.

Details

Summary

For example
tzcntl %edi, %ebx
testl %edi, %edi
je .label

can be rewritten into
tzcntl %edi, %ebx
jae .label

A minor complication is that tzcnt sets CF instead of ZF when the input
is zero, we have to rewrite users of the flags from ZF to CF. Currently
we recognize patterns using lzcnt, tzcnt and popcnt.

Diff Detail

Event Timeline

bkramer updated this revision to Diff 8734.Apr 22 2014, 9:46 AM
bkramer retitled this revision from to X86: If we have an instruction that sets a flag and a zero test on the input of that instruction try to eliminate the test..
bkramer updated this object.
bkramer edited the test plan for this revision. (Show Details)
bkramer added reviewers: nadav, craig.topper, majnemer.
bkramer added a subscriber: Unknown Object (MLST).

Gentle ping.

Hi Benjamin,

your patch looks good to me.
However, I am not the code owner and therefore you might want to have a review from other people as well.

Originally I was a bit concerned because the example you posted in your original message contained an error:

///
tzcntl %edi, %ebx
testl %edi, %edi
je .label

can be rewritten into
tzcntl %edi, %ebx
jae .label <--- this should be 'jb' instead!.
///

That is because you want to jump to %label only if CF = 1, and not when CF = 0.

..but then I had a look at the code generated and it does the correct thing.
With your patch, your new function @testCTZ2 in test/CodeGen/X86/peep-test-4.ll correctly generates a 'jb'. So it is fine for me.

bkramer closed this revision.May 19 2014, 7:24 AM
bkramer updated this revision to Diff 9560.

Closed by commit rL208788 (authored by d0k).