[PATCH] Fix vselect when getSetCCResultType returns a different type from the operands

Matt Arsenault Matthew.Arsenault at amd.com
Tue May 7 12:11:34 PDT 2013


  Don't check that the scalar select (for what was also the wrong type) is legal first.

  Looking at it again, the condition from Micah's original patch this was based on didn't make any sense to me. The types should be able to not match, and this should only be done if the sizes don't match.

  e.g. a test that broke: v4f32 = select <4 x i32> .... should not be unrolled, but was before.

Hi nadav,

http://llvm-reviews.chandlerc.com/D743

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D743?vs=1830&id=1866#toc

Files:
  lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Index: lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
@@ -652,13 +652,14 @@
 SDValue VectorLegalizer::ExpandVSELECT(SDValue Op) {
   // Implement VSELECT in terms of XOR, AND, OR
   // on platforms which do not support blend natively.
-  EVT VT =  Op.getOperand(0).getValueType();
   DebugLoc DL = Op.getDebugLoc();
 
   SDValue Mask = Op.getOperand(0);
   SDValue Op1 = Op.getOperand(1);
   SDValue Op2 = Op.getOperand(2);
 
+  EVT VT = Mask.getValueType();
+
   // If we can't even use the basic vector operations of
   // AND,OR,XOR, we will have to scalarize the op.
   // Notice that the operation may be 'promoted' which means that it is
@@ -673,8 +674,21 @@
       TargetLowering::ZeroOrNegativeOneBooleanContent)
     return DAG.UnrollVectorOp(Op.getNode());
 
+  // If the mask and the type do not match and Select is legal,
+  // go ahead and unroll the vector op.
+  // This occurs when getSetCCResultType returns something that
+  // is different than the operand types. For example,
+  // v4i8 = select v4i32, v4i8, v4i8.
+  if (VT.isVector() &&
+      Op1.getValueType().getSizeInBits() != VT.getSizeInBits() &&
+      TLI.getTypeAction(*DAG.getContext(), VT.getScalarType())
+        == TargetLowering::TypeLegal) {
+    return DAG.UnrollVectorOp(Op.getNode());
+  }
+
   assert(VT.getSizeInBits() == Op1.getValueType().getSizeInBits()
          && "Invalid mask size");
+
   // Bitcast the operands to be the same type as the mask.
   // This is needed when we select between FP types because
   // the mask is a vector of integers.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D743.2.patch
Type: text/x-patch
Size: 1719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130507/a76412f8/attachment.bin>


More information about the llvm-commits mailing list