This is an archive of the discontinued LLVM Phabricator instance.

[X86][MCU] replace select with bit manipulation instead of branches
ClosedPublic

Authored by AsafBadouh on Jan 5 2017, 7:26 AM.

Details

Summary

In case of the following select pattern, where :

  1. the condition is a result of "x & 0x1"
  2. the select operand are (z ^ y) , y or (z | y) , y

we can eliminate the branch (there is no "cmov" in MCU) by generate bitwise sequence.

select (and (x & 0x1) == 0) , y,  (z ^ y) )

to:

(-(and (x & 0x1)) & z ) ^ y

Diff Detail

Repository
rL LLVM

Event Timeline

AsafBadouh updated this revision to Diff 83233.Jan 5 2017, 7:26 AM
AsafBadouh retitled this revision from to [X86][MCU] replace select with bit manipulation instead of branches.
AsafBadouh updated this object.
AsafBadouh added reviewers: aaboud, igorb, zvi.
AsafBadouh set the repository for this revision to rL LLVM.
AsafBadouh added a subscriber: llvm-commits.
igorb added inline comments.Jan 10 2017, 7:36 AM
../tunkClang/lib/Target/X86/X86ISelLowering.cpp
16846

Could you please add comments.
I think the function name is misleading.

16963

what do you mean "(and (x & 0x1)" ?

17014

Could you implement isOrXorPattern as lambda function?

AsafBadouh updated this revision to Diff 84485.Jan 15 2017, 1:40 AM

changes according to Igor review.

igorb edited edge metadata.Jan 17 2017, 2:16 AM

please recheck the algorithm, it looks like it incorrect.

AsafBadouh updated this revision to Diff 85543.Jan 24 2017, 2:00 AM
AsafBadouh edited the summary of this revision. (Show Details)

Great catch Igor,
the transformation is not valid to select (and (x & 0x1) == 0) , (z ^ y), y ),
for that we will need an extra instruction to create the mask.
I change the algorithm to catch only: select (and (x & 0x1) == 0) , y, (z ^ y) )

igorb accepted this revision.Jan 29 2017, 4:20 AM
This revision is now accepted and ready to land.Jan 29 2017, 4:20 AM
This revision was automatically updated to reflect the committed changes.