[PATCH] SelectionDAG: Teach the legalizer to split SETCC if VSELECT needs splitting too.

Juergen Ributzka juergen at apple.com
Fri Sep 20 18:48:33 PDT 2013

Hi @ll,

the problem these two patches solve is related to the formation of vector min/max instructions on X86 for the following example code:

define <16 x i16> @split16(<16 x i16> %a, <16 x i16> %b, <16 x i8> %__mask) {
  %1 = icmp ult <16 x i16> %a, %b
  %2 = select <16 x i1> %1, <16 x i16> %a, <16 x i16> %b
  ret <16 x i16> %2

The Type Legalizer recognizes that VSELECT needs to be split, because the type is to wide for the given target. The same does not always apply to SETCC, because less space is required to encode the result of a comparison. As a result VSELECT is split and SETCC is unrolled into scalar comparisons (depending on the SSE feature level this gets expanded from as little as 17 instruction to over 100).

The first patch fixes the issue by checking for VSELECT-SETCC patterns in the DAG Combiner. If a matching pattern is found, then the result mask of SETCC is promoted to the expected vector mask for the given target. This mask has usually the same size as the VSELECT return type (except for Intel KNL). Now the type legalizer will split both VSELECT and SETCC.

This allows the following X86 DAG Combine code to successfully detect the MIN/MAX pattern. This fixes PR16695, PR17002, and <rdar://problem/14594431>.

The second patch addresses a special X86 AVX case. It emulates AVX 256bit MIN/MAX support by splitting the vector. AVX only supports MIN/MAX on 128bit vectors and this patch enables vector splitting for this special case in the X86 DAG Combiner.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: minmax1.diff
Type: application/octet-stream
Size: 4763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130920/61eae976/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minmax2.diff
Type: application/octet-stream
Size: 5844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130920/61eae976/attachment-0001.obj>

More information about the llvm-commits mailing list