[PATCH] Convert a vselect into a concat_vector if possible

Nadav Rotem nrotem at apple.com
Mon May 26 22:37:12 PDT 2014



+// This function assumes all the vselect's arguments are CONCAT_VECTOR

Please add assertions that verify that. 

+// nodes and that the condition is a BV of ConstantSDNodes (or undefs).
+static SDValue ConvertSelecttoConcatVector(SDNode *N, SelectionDAG &DAG,

The name should be ConvertSelectToConcatVector  (upper case T in To).


+                                           TargetLowering::DAGCombinerInfo &DCI,
+                                           const X86Subtarget *Subtarget) {
+  SDLoc dl(N);
+  MVT VT = N->getSimpleValueType(0);
+  int NumElems = VT.getVectorNumElements();
+  SDValue Cond = N->getOperand(0);
+  SDValue LHS = N->getOperand(1);
+  SDValue RHS = N->getOperand(2);
+
+  // We're sure we have an even number of elements due to the
+  // concat_vectors we have as arguments to vselect.
+  ConstantSDNode *BottomHalf = cast<ConstantSDNode>(Cond.getOperand(0));
+  for (int i = 0; i < NumElems / 2; ++i) {
+    if (Cond->getOperand(i)->getOpcode() != ISD::UNDEF &&
+        Cond->getOperand(i).getNode() != BottomHalf)
+      return SDValue();
+  }
+
+  ConstantSDNode *TopHalf =
+      cast<ConstantSDNode>(Cond.getOperand(NumElems / 2));
+  for (int i = NumElems / 2; i < NumElems; ++i) {
+    if (Cond->getOperand(i)->getOpcode() != ISD::UNDEF &&
+        Cond->getOperand(i).getNode() != TopHalf)
+      return SDValue();
+  }
+

Can you try  to combine the loops above to one loop?  If it does not make the code more readable then don’t bother.  

+  return DAG.getNode(
+      ISD::CONCAT_VECTORS, dl, VT,
+      BottomHalf->isNullValue() ? LHS->getOperand(1) : RHS->getOperand(1),
+      TopHalf->isNullValue() ? LHS->getOperand(0) : RHS->getOperand(0));
+}


LGTM.  After these fixes you should commit. 

On May 26, 2014, at 8:36 PM, Filipe Cabecinhas <filcab+llvm.phabricator at gmail.com> wrote:

> Hi nadav, delena, grosbach,
> 
> If both vector args to vselect are concat_vectors and the condition is
> constant and picks half a vector from each argument, convert the vselect
> into a concat_vectors.
> 
> Added tests.
> 
> http://reviews.llvm.org/D3916
> 
> Files:
>  lib/Target/X86/X86ISelLowering.cpp
>  test/CodeGen/X86/vselect.ll
> <D3916.9818.patch>





More information about the llvm-commits mailing list