[llvm] r355713 - [x86] prevent infinite looping from inverse shuffle transforms

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 8 11:20:29 PST 2019


Author: spatel
Date: Fri Mar  8 11:20:28 2019
New Revision: 355713

URL: http://llvm.org/viewvc/llvm-project?rev=355713&view=rev
Log:
[x86] prevent infinite looping from inverse shuffle transforms

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/vector-shuffle-128-unpck.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=355713&r1=355712&r2=355713&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Mar  8 11:20:28 2019
@@ -9850,11 +9850,16 @@ static bool is128BitUnpackShuffleMask(Ar
   MVT EltVT = MVT::getIntegerVT(128 / Mask.size());
   MVT VT = MVT::getVectorVT(EltVT, Mask.size());
 
+  // We can't assume a canonical shuffle mask, so try the commuted version too.
+  SmallVector<int, 4> CommutedMask(Mask.begin(), Mask.end());
+  ShuffleVectorSDNode::commuteMask(CommutedMask);
+
   // Match any of unary/binary or low/high.
   for (unsigned i = 0; i != 4; ++i) {
     SmallVector<int, 16> UnpackMask;
     createUnpackShuffleMask(VT, UnpackMask, (i >> 1) % 2, i % 2);
-    if (isTargetShuffleEquivalent(Mask, UnpackMask))
+    if (isTargetShuffleEquivalent(Mask, UnpackMask) ||
+        isTargetShuffleEquivalent(CommutedMask, UnpackMask))
       return true;
   }
   return false;

Modified: llvm/trunk/test/CodeGen/X86/vector-shuffle-128-unpck.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vector-shuffle-128-unpck.ll?rev=355713&r1=355712&r2=355713&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/vector-shuffle-128-unpck.ll (original)
+++ llvm/trunk/test/CodeGen/X86/vector-shuffle-128-unpck.ll Fri Mar  8 11:20:28 2019
@@ -221,3 +221,15 @@ define <16 x i8> @unpckl_unary_extracted
   ret <16 x i8> %r
 }
 
+; This would infinite loop because we did not recognize the unpack shuffle mask in commuted form.
+
+define <8 x i32> @extract_unpckl_v8i32(<8 x i32> %a) {
+; ALL-LABEL: extract_unpckl_v8i32:
+; ALL:       # %bb.0:
+; ALL-NEXT:    vextractf128 $1, %ymm0, %xmm1
+; ALL-NEXT:    vunpcklps {{.*#+}} xmm0 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
+; ALL-NEXT:    retq
+  %shuffle = shufflevector <8 x i32> %a, <8 x i32> undef, <8 x i32> <i32 4, i32 undef, i32 5, i32 1, i32 undef, i32 undef, i32 undef, i32 undef>
+  ret <8 x i32> %shuffle
+}
+




More information about the llvm-commits mailing list