<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Hi Tom,<div><br></div><div>I took a quick look yesterday night and I didn’t see a quick fix either. I will look into it today.</div></div><div><br></div><div>Cheers,</div><div>Juergen</div><div><br></div><div><br></div><div><div><div>On Nov 14, 2013, at 8:45 PM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Wed, Nov 13, 2013 at 01:57:54AM -0000, Juergen Ributzka wrote:<br><blockquote type="cite">Author: ributzka<br>Date: Tue Nov 12 19:57:54 2013<br>New Revision: 194542<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=194542&view=rev">http://llvm.org/viewvc/llvm-project?rev=194542&view=rev</a><br>Log:<br>SelectionDAG: Teach the legalizer to split SETCC if VSELECT needs splitting too.<br><br>This patch reapplies r193676 with an additional fix for the Hexagon backend. The<br>SystemZ backend has already been fixed by r194148.<br><br>The Type Legalizer recognizes that VSELECT needs to be split, because the type<br>is to wide for the given target. The same does not always apply to SETCC,<br>because less space is required to encode the result of a comparison. As a result<br>VSELECT is split and SETCC is unrolled into scalar comparisons.<br><br>This commit fixes the issue by checking for VSELECT-SETCC patterns in the DAG<br>Combiner. If a matching pattern is found, then the result mask of SETCC is<br>promoted to the expected vector mask type for the given target. Now the type<br>legalizer will split both VSELECT and SETCC.<br><br>This allows the following X86 DAG Combine code to sucessfully detect the MIN/MAX<br>pattern. This fixes PR16695, PR17002, and <<a href="rdar://problem/14594431">rdar://problem/14594431</a>>.<br><br>Reviewed by Nadav<br><br></blockquote><br>Hi Juergen,<br><br>This caused a regression on R600.  I have attached a patch to this email<br>with a testcase.  See my comments below.<br><br><blockquote type="cite">Added:<br>   llvm/trunk/test/CodeGen/X86/vec_split.ll<br>Modified:<br>   llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>   llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp<br>   llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h<br>   llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br><br>Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=194542&r1=194541&r2=194542&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=194542&r1=194541&r2=194542&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Nov 12 19:57:54 2013<br>@@ -4364,6 +4364,29 @@ SDValue DAGCombiner::visitVSELECT(SDNode<br>    }<br>  }<br><br>+  // Treat SETCC as a vector mask and promote the result type based on the<br>+  // targets expected SETCC result type. This will ensure that SETCC and VSELECT<br>+  // are both split by the type legalizer. This is done to prevent the type<br>+  // legalizer from unrolling SETCC into scalar comparions.<br>+  EVT SelectVT = N->getValueType(0);<br>+  EVT MaskVT = getSetCCResultType(SelectVT);<br>+  assert(MaskVT.isVector() && "Expected a vector type.");<br>+  if (N0.getOpcode() == ISD::SETCC && N0.getValueType() != MaskVT) {<br>+    SDLoc MaskDL(N0);<br>+<br>+    // Extend the mask to the desired value type.<br>+    ISD::NodeType ExtendCode =<br>+      TargetLowering::getExtendForContent(TLI.getBooleanContents(true));<br>+    SDValue Mask = DAG.getNode(ExtendCode, MaskDL, MaskVT, N0);<br>+<br>+    AddToWorkList(Mask.getNode());<br>+<br>+    SDValue LHS = N->getOperand(1);<br>+    SDValue RHS = N->getOperand(2);<br>+<br>+    return DAG.getNode(ISD::VSELECT, DL, SelectVT, Mask, LHS, RHS);<br>+  }<br>+<br>  return SDValue();<br>}<br><br><br>Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp?rev=194542&r1=194541&r2=194542&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp?rev=194542&r1=194541&r2=194542&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp Tue Nov 12 19:57:54 2013<br>@@ -492,14 +492,19 @@ void DAGTypeLegalizer::SplitRes_SELECT(S<br>  SDValue Cond = N->getOperand(0);<br>  CL = CH = Cond;<br>  if (Cond.getValueType().isVector()) {<br>-    assert(Cond.getValueType().getVectorElementType() == MVT::i1 &&<br>-           "Condition legalized before result?");<br>-    unsigned NumElements = Cond.getValueType().getVectorNumElements();<br>-    EVT VCondTy = EVT::getVectorVT(*DAG.getContext(), MVT::i1, NumElements / 2);<br>-    CL = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VCondTy, Cond,<br>-                     DAG.getConstant(0, TLI.getVectorIdxTy()));<br>-    CH = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VCondTy, Cond,<br>-                     DAG.getConstant(NumElements / 2, TLI.getVectorIdxTy()));<br>+    if (Cond.getOpcode() == ISD::SETCC) {<br>+      assert(Cond.getValueType() == getSetCCResultType(N->getValueType(0)) &&<br>+             "Condition has not been prepared for split!");<br>+      GetSplitVector(Cond, CL, CH);<br></blockquote><br>Even with the adjustment to getSetCCResultType in the attached patch,<br>when GetSplitVector() is called here, I am getting an assertion failure:<br><br>llc: LegalizeTypes.cpp:828: void llvm::DAGTypeLegalizer::GetSplitVector(llvm::SDValue, llvm::SDValue &, llvm::SDValue &): Assertion `Entry.first.getNode() && "Operand isn't split"' failed.<br><br>From what I can tell the problem here is that 'Cond' has a value type<br>of v4i32 which is legal on R600, so the operation was not split, and<br>therefore there is no entry in the SplitVectors map for it (This is what<br>is causing the assertion failure).<br><br>The SELECT in this example has a type of v4i64 which is not a legal type<br>on R600, so the problem occurs when a SELECT node has an illegal type,<br>but Operand 0 is a SETCC node with a legal type.  I'm not sure the best<br>way to fix this issue.  Do you have any suggestions?<br><br>Thanks,<br>Tom</div></blockquote><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br><br><blockquote type="cite">+    } else {<br>+      EVT ETy = Cond.getValueType().getVectorElementType();<br>+      unsigned NumElements = Cond.getValueType().getVectorNumElements();<br>+      EVT VCondTy = EVT::getVectorVT(*DAG.getContext(), ETy, NumElements / 2);<br>+      CL = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VCondTy, Cond,<br>+                       DAG.getConstant(0, TLI.getVectorIdxTy()));<br>+      CH = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VCondTy, Cond,<br>+                       DAG.getConstant(NumElements / 2, TLI.getVectorIdxTy()));<br>+    }<br>  }<br><br>  Lo = DAG.getNode(N->getOpcode(), dl, LL.getValueType(), CL, LL, RL);<br><br>Modified: llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h?rev=194542&r1=194541&r2=194542&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h?rev=194542&r1=194541&r2=194542&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h (original)<br>+++ llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h Tue Nov 12 19:57:54 2013<br>@@ -141,8 +141,11 @@ namespace llvm {<br><br>    SDValue  LowerVASTART(SDValue Op, SelectionDAG &DAG) const;<br>    SDValue  LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;<br>-    virtual EVT getSetCCResultType(LLVMContext &, EVT) const {<br>-      return MVT::i1;<br>+    virtual EVT getSetCCResultType(LLVMContext &C, EVT VT) const {<br>+      if (!VT.isVector())<br>+        return MVT::i1;<br>+      else<br>+        return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements());<br>    }<br><br>    virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,<br><br>Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=194542&r1=194541&r2=194542&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=194542&r1=194541&r2=194542&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Nov 12 19:57:54 2013<br>@@ -1547,7 +1547,16 @@ void X86TargetLowering::resetOperationAc<br>}<br><br>EVT X86TargetLowering::getSetCCResultType(LLVMContext &, EVT VT) const {<br>-  if (!VT.isVector()) return MVT::i8;<br>+  if (!VT.isVector())<br>+    return MVT::i8;<br>+<br>+  const TargetMachine &TM = getTargetMachine();<br>+  if (!TM.Options.UseSoftFloat && Subtarget->hasAVX512())<br>+    switch(VT.getVectorNumElements()) {<br>+    case  8: return MVT::v8i1;<br>+    case 16: return MVT::v16i1;<br>+    }<br>+<br>  return VT.changeVectorElementTypeToInteger();<br>}<br><br><br>Added: llvm/trunk/test/CodeGen/X86/vec_split.ll<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_split.ll?rev=194542&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_split.ll?rev=194542&view=auto</a><br>==============================================================================<br>--- llvm/trunk/test/CodeGen/X86/vec_split.ll (added)<br>+++ llvm/trunk/test/CodeGen/X86/vec_split.ll Tue Nov 12 19:57:54 2013<br>@@ -0,0 +1,42 @@<br>+; RUN: llc -march=x86-64 -mcpu=corei7 < %s | FileCheck %s -check-prefix=SSE4<br>+; RUN: llc -march=x86-64 -mcpu=corei7-avx < %s | FileCheck %s -check-prefix=AVX1<br>+; RUN: llc -march=x86-64 -mcpu=core-avx2 < %s | FileCheck %s -check-prefix=AVX2<br>+<br>+define <16 x i16> @split16(<16 x i16> %a, <16 x i16> %b, <16 x i8> %__mask) {<br>+; SSE4-LABEL: split16:<br>+; SSE4: pminuw<br>+; SSE4: pminuw<br>+; SSE4: ret<br>+; AVX1-LABEL: split16:<br>+; AVX1: vpminuw<br>+; AVX1: vpminuw<br>+; AVX1: ret<br>+; AVX2-LABEL: split16:<br>+; AVX2: vpminuw<br>+; AVX2: ret<br>+  %1 = icmp ult <16 x i16> %a, %b<br>+  %2 = select <16 x i1> %1, <16 x i16> %a, <16 x i16> %b<br>+  ret <16 x i16> %2<br>+}<br>+<br>+define <32 x i16> @split32(<32 x i16> %a, <32 x i16> %b, <32 x i8> %__mask) {<br>+; SSE4-LABEL: split32:<br>+; SSE4: pminuw<br>+; SSE4: pminuw<br>+; SSE4: pminuw<br>+; SSE4: pminuw<br>+; SSE4: ret<br>+; AVX1-LABEL: split32:<br>+; AVX1: vpminuw<br>+; AVX1: vpminuw<br>+; AVX1: vpminuw<br>+; AVX1: vpminuw<br>+; AVX1: ret<br>+; AVX2-LABEL: split32:<br>+; AVX2: vpminuw<br>+; AVX2: vpminuw<br>+; AVX2: ret<br>+  %1 = icmp ult <32 x i16> %a, %b<br>+  %2 = select <32 x i1> %1, <32 x i16> %a, <32 x i16> %b<br>+  ret <32 x i16> %2<br>+}<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote><span><0001-R600-Fix-getSetCCResultType-to-handle-new-VSELECT-DA.patch></span></div></blockquote></div><br></div></body></html>