[PATCH] Don't expand bswap with shuffle of illegal vector type.

Matt Arsenault Matthew.Arsenault at amd.com
Thu Jun 26 23:46:41 PDT 2014


Vector operations are legalized after types, so it isn't
OK to introduce a new illegal type. On R600, an i32 vector and
shuffle is always legal, but the produced vNi8 vector is not.
   
This is already covered by the existing R600 bswap test
combined with a future patch which exposes this problem.

http://reviews.llvm.org/D4320

Files:
  lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Index: lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
@@ -689,14 +689,21 @@
 SDValue VectorLegalizer::ExpandBSWAP(SDValue Op) {
   EVT VT = Op.getValueType();
 
+  int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
+  int NElts = VT.getVectorNumElements();
+  int NShuffleElts = ScalarSizeInBytes * NElts;
+  EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, NShuffleElts);
+
+  // Don't create a shuffle on an illegal type.
+  if (!TLI.isTypeLegal(ByteVT))
+    return DAG.UnrollVectorOp(Op.getNode());
+
   // Generate a byte wise shuffle mask for the BSWAP.
   SmallVector<int, 16> ShuffleMask;
-  int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
-  for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
+  for (int I = 0; I != NElts; ++I) {
     for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
       ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
-
-  EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size());
+  }
 
   // Only emit a shuffle if the mask is legal.
   if (!TLI.isShuffleMaskLegal(ShuffleMask, ByteVT))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4320.10912.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140627/9a9eaa67/attachment.bin>


More information about the llvm-commits mailing list