This is an archive of the discontinued LLVM Phabricator instance.

[X86] Directly legalize v16i16/v8i16 vselect to vXi8 vselect to use VPBLENDVB
ClosedPublic

Authored by craig.topper on May 17 2018, 12:26 PM.

Details

Summary

The intrinsic legalization for masked truncate uses ISD::TRUNCATE which can be constant folded by getNode. This prevents getVectorMaskingNode from seeing the ISD::TRUNCATE special case where it should emit X86ISD::SELECT instead of ISD::VSELECT. This causes a vselect with a v16i1 or v8i1 condition to be emitted during vector legalization. but vector legalization doesn't revisit nodes it creates. DAG combine will then promote this condition to match the result type. Then op legalization will try to legalize it, but the custom lowering hook returned SDValue(). But op legalization doesn't have an Expand for VSELECT because it expects vector legalization to have taken care of it. So the operation sticks around and fails in isel.

This patch adds a custom legalization hook to morph it to a vXi8 vselect instead.

This also simplifies the normal vXi16 vselect handling because vector legalization was normally expanding to AND/ANDN/OR and DAG combine was turning that into VBLENDVB. So we can skip a step by doing it directly.

Fixes PR37499

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.May 17 2018, 12:26 PM
RKSimon added inline comments.May 17 2018, 3:15 PM
lib/Target/X86/X86ISelLowering.cpp
15036 ↗(On Diff #147369)

Its not clear without the context - is there anything to check that numSignBits(Cond) == 16?

craig.topper added inline comments.May 17 2018, 3:30 PM
lib/Target/X86/X86ISelLowering.cpp
15036 ↗(On Diff #147369)

Doesn't ISD::VSELECT condition have to be all 0s or all 1s? If we optimize we turn into SHRUNKBLEND which shouldn't go through here.

RKSimon accepted this revision.May 18 2018, 4:40 AM

LGTM

lib/Target/X86/X86ISelLowering.cpp
15036 ↗(On Diff #147369)

Ah yes you're right - "The condition follows the BooleanContent format of the target."

This revision is now accepted and ready to land.May 18 2018, 4:40 AM
This revision was automatically updated to reflect the committed changes.