This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Add a generic isSplatValue function.
ClosedPublic

Authored by RKSimon on Dec 7 2018, 4:43 AM.

Details

Summary

This patch introduces a generic function to determine whether a given vector type is known to be a splat value for the specified demanded elements, recursing up the DAG looking for BUILD_VECTOR or VECTOR_SHUFFLE splat patterns.

It also keeps track of the elements that are known to be UNDEF - it returns true if all the demanded elements are UNDEF (as this may be useful under some circumstances), so this needs to be handled by the caller.

A wrapper variant is also provided that doesn't take the DemandedElts or UndefElts arguments for cases where we just want to know if the SDValue is a splat or not (with/without UNDEFS).

I had hoped to completely remove the X86 local version of this function, but I'm seeing some regressions in shift/rotate codegen that will take a little longer to fix and I hope to get this in sooner so I can continue work on PR38243 which needs more capable splat detection.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Dec 7 2018, 4:43 AM

gentle ping

andreadb added inline comments.Dec 12 2018, 8:51 AM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
2129 ↗(On Diff #177179)

nit: remove extra semicolon.

2155–2160 ↗(On Diff #177179)

Let say that we have a shuffle with a mask of <1,1,2,1>

That mask is not a splat mask because the third element is different. However, that element is not demanded (i.e. DemandedElts[2] == false), it is fair to assume that this mask is in practice a splat?

In the case of ISD::BUILD_VECTOR, your code skips elements that are non-demanded.
In this case instead, SVN->isSplat() doesn't know about demanded elements, so it would return false for <1,1,2,1>.

RKSimon updated this revision to Diff 177873.Dec 12 2018, 9:47 AM

Addressed @andreadb's comments

RKSimon marked 2 inline comments as done.Dec 12 2018, 9:47 AM
andreadb accepted this revision.Dec 12 2018, 9:53 AM

Thanks Simon.

LGTM.

This revision is now accepted and ready to land.Dec 12 2018, 9:53 AM
This revision was automatically updated to reflect the committed changes.