]> granicus.if.org Git - llvm/commitdiff
[DAGCombiner] Do a better job of ensuring we don't split elements when combining...
authorCraig Topper <craig.topper@intel.com>
Thu, 31 Aug 2017 17:02:22 +0000 (17:02 +0000)
committerCraig Topper <craig.topper@intel.com>
Thu, 31 Aug 2017 17:02:22 +0000 (17:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312253 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index db87f8a62757619230b1b7554ff8142b9f5ba879..6dbfced44d19a43247eaab2a01040a89e5876b7c 100644 (file)
@@ -15173,14 +15173,17 @@ SDValue DAGCombiner::visitEXTRACT_SUBVECTOR(SDNode* N) {
   if (V->getOpcode() == ISD::BUILD_VECTOR) {
     if (auto *Idx = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
       EVT InVT = V->getValueType(0);
-      unsigned NumElems = NVT.getSizeInBits() / InVT.getScalarSizeInBits();
-      if (NumElems > 0) {
+      unsigned ExtractSize = NVT.getSizeInBits();
+      unsigned EltSize = InVT.getScalarSizeInBits();
+      // Only do this if we won't split any elements.
+      if (ExtractSize % EltSize == 0) {
+        unsigned NumElems = ExtractSize / EltSize;
         EVT ExtractVT = EVT::getVectorVT(*DAG.getContext(),
                                          InVT.getVectorElementType(), NumElems);
         if (!LegalOperations ||
             TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {
-          unsigned IdxVal = Idx->getZExtValue() * NVT.getScalarSizeInBits() /
-                            InVT.getScalarSizeInBits();
+          unsigned IdxVal = (Idx->getZExtValue() * NVT.getScalarSizeInBits()) /
+                            EltSize;
 
           // Extract the pieces from the original build_vector.
           SDValue BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),