[X86] isTargetShuffleEquivalent - early out on illegal shuffle masks. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 18 Aug 2019 16:37:58 +0000 (16:37 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 18 Aug 2019 16:37:58 +0000 (16:37 +0000)
Simplifies shuffle mask comparisons by just bailing out if the shuffle mask has any out of range values - will make an upcoming patch much simpler.

llvm-svn: 369211

llvm/lib/Target/X86/X86ISelLowering.cpp

index 37d8489..6c739d8 100644 (file)
@@ -10075,7 +10075,8 @@ static bool isShuffleEquivalent(SDValue V1, SDValue V2, ArrayRef<int> Mask,
 /// If an element in Mask matches SM_SentinelUndef (-1) then the corresponding
 /// value in ExpectedMask is always accepted. Otherwise the indices must match.
 ///
-/// SM_SentinelZero is accepted as a valid negative index but must match in both.
+/// SM_SentinelZero is accepted as a valid negative index but must match in
+/// both.
 static bool isTargetShuffleEquivalent(ArrayRef<int> Mask,
                                       ArrayRef<int> ExpectedMask) {
   int Size = Mask.size();
@@ -10084,14 +10085,15 @@ static bool isTargetShuffleEquivalent(ArrayRef<int> Mask,
   assert(isUndefOrZeroOrInRange(ExpectedMask, 0, 2 * Size) &&
          "Illegal target shuffle mask");
 
-  for (int i = 0; i < Size; ++i)
-    if (Mask[i] == SM_SentinelUndef)
-      continue;
-    else if (Mask[i] < 0 && Mask[i] != SM_SentinelZero)
-      return false;
-    else if (Mask[i] != ExpectedMask[i])
-      return false;
+  // Check for out-of-range target shuffle mask indices.
+  if (!isUndefOrZeroOrInRange(Mask, 0, 2 * Size))
+    return false;
 
+  for (int i = 0; i < Size; ++i) {
+    if (Mask[i] == SM_SentinelUndef || Mask[i] == ExpectedMask[i])
+      continue;
+    return false;
+  }
   return true;
 }