This is an archive of the discontinued LLVM Phabricator instance.

[X86] Match bitcast of vxi1 to pmovmsk
ClosedPublic

Authored by zvi on May 18 2017, 12:33 AM.

Details

Summary

Add an early combine to match patterns such as:

(i16 bitcast (v16i1 x))
->
(i16 movmsk (v16i8 sext (v16i1 x)))

This combine needs to happen early enough before
type-legalization scalarizes the result of the setcc.

Diff Detail

Repository
rL LLVM

Event Timeline

zvi created this revision.May 18 2017, 12:33 AM
zvi updated this revision to Diff 99418.May 18 2017, 4:25 AM

Rebase

igorb accepted this revision.May 18 2017, 5:32 AM

LGTM

This revision is now accepted and ready to land.May 18 2017, 5:32 AM
RKSimon edited edge metadata.May 18 2017, 5:35 AM

Why don't you use MOVMSKPD/MOVMSKPS for the 32/64 bit cases and avoid the vector truncation?

zvi added a comment.May 18 2017, 5:59 AM

Why don't you use MOVMSKPD/MOVMSKPS for the 32/64 bit cases and avoid the vector truncation?

That's a good point. thanks!

delena added inline comments.May 18 2017, 6:20 AM
lib/Target/X86/X86ISelLowering.cpp
29020 ↗(On Diff #99418)

Can you use if (VT.isInteger() && DAG.ComputeNumSignBits(N) == EltBits) ?

35127 ↗(On Diff #99418)

We usually pass DCI to check the phase.

zvi updated this revision to Diff 99434.May 18 2017, 7:49 AM

Thanks, Simon, for reminding me that the integer and FP MOVMSK operations are assymetrical, so we get more types covered without having to shuffle.

zvi marked an inline comment as done.May 18 2017, 7:50 AM
zvi added inline comments.
lib/Target/X86/X86ISelLowering.cpp
29020 ↗(On Diff #99418)

i didn't understand the question. Can you please explain this point?

delena added inline comments.May 21 2017, 4:04 AM
lib/Target/X86/X86ISelLowering.cpp
29020 ↗(On Diff #99418)

ISD::SETCC is a private case when you know about all-ones or all-zeroes. DAG.ComputeNumSignBits(N) == EltBits is more general.

zvi added inline comments.May 22 2017, 12:31 AM
lib/Target/X86/X86ISelLowering.cpp
29020 ↗(On Diff #99418)

That's a good idea. Do you have an example of such a case?

zvi updated this revision to Diff 99717.May 22 2017, 12:32 AM

Generalize to catch cases where the setcc operands are illegal types.

RKSimon added inline comments.May 22 2017, 3:45 AM
lib/Target/X86/X86ISelLowering.cpp
29020 ↗(On Diff #99418)

combineVectorSignBitsTruncation should be a good example - it started with using the 'all bits' of a comparison result and was generalised to use DAG.ComputeNumSignBits later on

zvi updated this revision to Diff 100664.May 29 2017, 10:50 PM

Generalize combine to match (ix bitcast (vxi1 t)) where t is not necessarily a setcc.

zvi retitled this revision from [X86] Match bitcast of vsetcc to pmovmsk to [X86] Match bitcast of vxi1 to pmovmsk.May 29 2017, 10:54 PM
zvi edited the summary of this revision. (Show Details)
RKSimon accepted this revision.Jun 1 2017, 2:49 AM

LGTM with one minor - thanks.

lib/Target/X86/X86ISelLowering.cpp
29017 ↗(On Diff #100664)

Possibly add a TODO about handling pre-AVX2 cases (split with 2 16i8 MOVMSK) - add a SSE/AVX1 test with current codegen as well if you can.

zvi updated this revision to Diff 101005.Jun 1 2017, 4:21 AM

Addressing Simon's comments.

zvi marked an inline comment as done.Jun 1 2017, 4:24 AM
This revision was automatically updated to reflect the committed changes.