[llvm] r310372 - [DAGCombiner] simplifyShuffleMask - handle UNDEF inputs from shuffles as well as BUILD_VECTOR

Bill Seurer via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 09:05:20 PDT 2017


After this patch there are 4 test cases that cause clang to hang (or 
possibly run a REALLY long time) on powerpc64 (BE only) in the 
llvm-test-suite tests.  You can see the initial failure in the buildbots 
here:

http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/7027

Specificially:

http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/7027/steps/test-suite/logs/test.log

(search for "FAIL:")

--- Tested: 2565 tests --
FAIL: SingleSource/UnitTests/Vector/build.compile_time (1 of 2565)
FAIL: SingleSource/UnitTests/Vector/simple.compile_time (2 of 2565)
FAIL: SingleSource/UnitTests/Vector/build.execution_time (514 of 2565)
FAIL: SingleSource/UnitTests/Vector/simple.execution_time (515 of 2565)



 From letting it run in the debugger a while and then checking where it 
was at it a few tines it appears to be hanging in DAGCombiner::Run in 
the while loop (line 1372 in my copy of 
lib/CodeGen/SelectionDAG/DAGCombiner.cpp).

. . .
   // While the worklist isn't empty, find a node and try to combine it.
   while (!WorklistMap.empty()) {
. . .



Some examples from llvm-test-suite/SingleSource/UnitTests/Vector/build.c
(which is a small test case):


Program received signal SIGINT, Interrupt.
llvm::TypedTrackingMDRef<llvm::MDNode>::TypedTrackingMDRef 
(this=0x3fffffff8d08, X=...) at 
/home/seurer/llvm/llvm-test3/include/llvm/IR/TrackingMDRef.h:115
115	  TypedTrackingMDRef(const TypedTrackingMDRef &X) : Ref(X.Ref) {}
Missing separate debuginfos, use: debuginfo-install 
ncurses-libs-5.9-13.20130511.el7.ppc64 zlib-1.2.7-17.el7.ppc64
(gdb) where
#0  llvm::TypedTrackingMDRef<llvm::MDNode>::TypedTrackingMDRef 
(this=0x3fffffff8d08, X=...) at 
/home/seurer/llvm/llvm-test3/include/llvm/IR/TrackingMDRef.h:115
#1  0x0000000011642af8 in llvm::DebugLoc::DebugLoc (this=0x3fffffff8d08) 
at /home/seurer/llvm/llvm-test3/include/llvm/IR/DebugLoc.h:34
#2  0x00000000116e8e4c in llvm::SDLoc::SDLoc (this=0x3fffffff8d08, 
N=0x1cba89f0) at 
/home/seurer/llvm/llvm-test3/include/llvm/CodeGen/SelectionDAGNodes.h:1012
#3  0x00000000116e8f24 in llvm::SDLoc::SDLoc (this=0x3fffffff8d08, 
V=...) at 
/home/seurer/llvm/llvm-test3/include/llvm/CodeGen/SelectionDAGNodes.h:1013
#4  0x00000000152216d0 in simplifyShuffleOperandRecursively 
(UsedElements=..., V=..., DAG=...) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:15031
#5  0x000000001522208c in simplifyShuffleOperands (SVN=0x1cbb3368, 
N0=..., N1=..., DAG=...) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:15107
#6  0x00000000152250b4 in (anonymous 
namespace)::DAGCombiner::visitVECTOR_SHUFFLE (this=0x3fffffff9bd0, 
N=0x1cbb3368)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:15559
#7  0x00000000151b95e4 in (anonymous namespace)::DAGCombiner::visit 
(this=0x3fffffff9bd0, N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1554
#8  0x00000000151b9730 in (anonymous namespace)::DAGCombiner::combine 
(this=0x3fffffff9bd0, N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1568
#9  0x00000000151b8620 in (anonymous namespace)::DAGCombiner::Run 
(this=0x3fffffff9bd0, AtLevel=llvm::AfterLegalizeDAG)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1416
#10 0x0000000015230514 in llvm::SelectionDAG::Combine (this=0x1cb33150, 
Level=llvm::AfterLegalizeDAG, AA=0x1cb9ed70, 
OptLevel=llvm::CodeGenOpt::Aggressive)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:17235
. . .

Program received signal SIGINT, Interrupt.
llvm::MVT::getVectorNumElements (this=0x3fffffff8bc0) at 
/home/seurer/llvm/llvm-test3/include/llvm/CodeGen/MachineValueType.h:513
513	    unsigned getVectorNumElements() const {
(gdb) where
#0  llvm::MVT::getVectorNumElements (this=0x3fffffff8bc0) at 
/home/seurer/llvm/llvm-test3/include/llvm/CodeGen/MachineValueType.h:513
#1  0x00000000116e7f34 in llvm::EVT::getVectorNumElements 
(this=0x3fffffff8bc0) at 
/home/seurer/llvm/llvm-test3/include/llvm/CodeGen/ValueTypes.h:276
#2  0x0000000011d65b74 in llvm::ShuffleVectorSDNode::getMaskElt 
(this=0x1cbb3368, Idx=6) at 
/home/seurer/llvm/llvm-test3/include/llvm/CodeGen/SelectionDAGNodes.h:1377
#3  0x0000000015304e8c in AddNodeIDCustom (ID=..., N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:510
#4  0x000000001530503c in AddNodeIDNode (ID=..., N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:538
#5  0x0000000015334ac0 in llvm::SDNode::Profile (this=0x1cbb3368, 
ID=...) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:7443
#6  0x000000001535c324 in 
llvm::DefaultFoldingSetTrait<llvm::SDNode>::Profile (X=..., ID=...) at 
/home/seurer/llvm/llvm-test3/include/llvm/ADT/FoldingSet.h:230
#7  0x000000001535c1fc in llvm::FoldingSet<llvm::SDNode>::GetNodeProfile 
(this=0x1cb33298, N=0x1cbb3368, ID=...) at 
/home/seurer/llvm/llvm-test3/include/llvm/ADT/FoldingSet.h:487
#8  0x000000001411acf8 in llvm::FoldingSetBase::GetOrInsertNode 
(this=0x1cb33298, N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/lib/Support/FoldingSet.cpp:422
#9  0x0000000015343c10 in 
llvm::FoldingSetImpl<llvm::SDNode>::GetOrInsertNode (this=0x1cb33298, 
N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/include/llvm/ADT/FoldingSet.h:444
#10 0x0000000015306650 in llvm::SelectionDAG::AddModifiedNodeToCSEMaps 
(this=0x1cb33150, N=0x1cbb3368) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:800
#11 0x0000000015332024 in llvm::SelectionDAG::ReplaceAllUsesWith 
(this=0x1cb33150, FromN=..., To=...) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6952
#12 0x0000000015268fdc in (anonymous 
namespace)::SelectionDAGLegalize::ReplaceNode (this=0x3fffffff97f8, 
Old=..., New=...)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:189
#13 0x0000000015270310 in (anonymous 
namespace)::SelectionDAGLegalize::LegalizeOp (this=0x3fffffff97f8, 
Node=0x1cba89f0)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1164
#14 0x000000001528d8d8 in llvm::SelectionDAG::LegalizeOp 
(this=0x1cb33150, N=0x1cba89f0, UpdatedNodes=...) at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:4644
#15 0x00000000151b83b8 in (anonymous namespace)::DAGCombiner::Run 
(this=0x3fffffff9bd0, AtLevel=llvm::AfterLegalizeDAG)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1396
#16 0x0000000015230514 in llvm::SelectionDAG::Combine (this=0x1cb33150, 
Level=llvm::AfterLegalizeDAG, AA=0x1cb9ed70, 
OptLevel=llvm::CodeGenOpt::Aggressive)
     at 
/home/seurer/llvm/llvm-test3/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:17235
. . .



On 08/08/2017 11:10 AM, Simon Pilgrim via llvm-commits wrote:
> Author: rksimon
> Date: Tue Aug  8 09:10:33 2017
> New Revision: 310372
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=310372&view=rev
> Log:
> [DAGCombiner] simplifyShuffleMask - handle UNDEF inputs from shuffles as well as BUILD_VECTOR
> 
> Minor extension to D36393
> 
> Modified:
>      llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>      llvm/trunk/test/CodeGen/X86/oddshuffles.ll
> 
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=310372&r1=310371&r2=310372&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Aug  8 09:10:33 2017
> @@ -15114,11 +15114,14 @@ static SDValue simplifyShuffleOperands(S
>   
>   static SDValue simplifyShuffleMask(ShuffleVectorSDNode *SVN, SDValue N0,
>                                      SDValue N1, SelectionDAG &DAG) {
> -  // TODO - handle cases other than BUILD_VECTOR.
> -  auto *BV0 = dyn_cast<BuildVectorSDNode>(N0);
> -  auto *BV1 = dyn_cast<BuildVectorSDNode>(N1);
> -  if (!BV0 && !BV1)
> -    return SDValue();
> +  auto isUndefElt = [](SDValue V, int Idx) {
> +    // TODO - handle more cases as required.
> +    if (V.getOpcode() == ISD::BUILD_VECTOR)
> +      return V.getOperand(Idx).isUndef();
> +    if (auto *SVN = dyn_cast<ShuffleVectorSDNode>(V))
> +      return SVN->getMaskElt(Idx) < 0;
> +    return false;
> +  };
>   
>     EVT VT = SVN->getValueType(0);
>     unsigned NumElts = VT.getVectorNumElements();
> @@ -15127,12 +15130,8 @@ static SDValue simplifyShuffleMask(Shuff
>     SmallVector<int, 8> NewMask;
>     for (unsigned i = 0; i != NumElts; ++i) {
>       int Idx = SVN->getMaskElt(i);
> -    if (BV0 && 0 <= Idx && Idx < (int)NumElts &&
> -        BV0->getOperand(Idx).isUndef()) {
> -      Changed = true;
> -      Idx = -1;
> -    } else if (BV1 && Idx > (int)NumElts &&
> -               BV1->getOperand(Idx - NumElts).isUndef()) {
> +    if ((0 <= Idx && Idx < (int)NumElts && isUndefElt(N0, Idx)) ||
> +        ((int)NumElts < Idx && isUndefElt(N1, Idx - NumElts))) {
>         Changed = true;
>         Idx = -1;
>       }
> 
> Modified: llvm/trunk/test/CodeGen/X86/oddshuffles.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/oddshuffles.ll?rev=310372&r1=310371&r2=310372&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/oddshuffles.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/oddshuffles.ll Tue Aug  8 09:10:33 2017
> @@ -258,7 +258,7 @@ define void @v7i8(<4 x i8> %a, <4 x i8>
>   ; SSE42-NEXT:    pextrb $0, %xmm1, 6(%rdi)
>   ; SSE42-NEXT:    pshufb {{.*#+}} xmm1 = xmm1[8,9,8,9,4,5,8,9,0,1,12,13,0,1,14,15]
>   ; SSE42-NEXT:    pblendw {{.*#+}} xmm1 = xmm0[0],xmm1[1],xmm0[2],xmm1[3],xmm0[4],xmm1[5,6,7]
> -; SSE42-NEXT:    pshufb {{.*#+}} xmm1 = xmm1[0,2,4,6,8,10,12,14,u,u,u,u,u,u,u,u]
> +; SSE42-NEXT:    pshufb {{.*#+}} xmm1 = xmm1[0,2,4,6,8,10,12,u,u,u,u,u,u,u,u,u]
>   ; SSE42-NEXT:    pextrw $2, %xmm1, 4(%rdi)
>   ; SSE42-NEXT:    movd %xmm1, (%rdi)
>   ; SSE42-NEXT:    retq
> @@ -268,7 +268,7 @@ define void @v7i8(<4 x i8> %a, <4 x i8>
>   ; AVX-NEXT:    vpshufd {{.*#+}} xmm0 = xmm0[0,3,1,3]
>   ; AVX-NEXT:    vpshufb {{.*#+}} xmm2 = xmm1[8,9,8,9,4,5,8,9,0,1,12,13,0,1,14,15]
>   ; AVX-NEXT:    vpblendw {{.*#+}} xmm0 = xmm0[0],xmm2[1],xmm0[2],xmm2[3],xmm0[4],xmm2[5,6,7]
> -; AVX-NEXT:    vpshufb {{.*#+}} xmm0 = xmm0[0,2,4,6,8,10,12,14,u,u,u,u,u,u,u,u]
> +; AVX-NEXT:    vpshufb {{.*#+}} xmm0 = xmm0[0,2,4,6,8,10,12,u,u,u,u,u,u,u,u,u]
>   ; AVX-NEXT:    vpextrb $0, %xmm1, 6(%rdi)
>   ; AVX-NEXT:    vpextrw $2, %xmm0, 4(%rdi)
>   ; AVX-NEXT:    vmovd %xmm0, (%rdi)
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 


-- 

-Bill Seurer



More information about the llvm-commits mailing list