[llvm-branch-commits] [llvm-branch] r84899 - /llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Bill Wendling isanbard at gmail.com
Thu Oct 22 15:06:18 PDT 2009


Author: void
Date: Thu Oct 22 17:06:18 2009
New Revision: 84899

URL: http://llvm.org/viewvc/llvm-project?rev=84899&view=rev
Log:
Port for <rdar://problem/7098635>.

Modified:
    llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Modified: llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp?rev=84899&r1=84898&r2=84899&view=diff

==============================================================================
--- llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp (original)
+++ llvm/branches/Apple/Leela/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp Thu Oct 22 17:06:18 2009
@@ -1396,8 +1396,9 @@
 
   SmallVector<SDValue, 16> NewOps(N->op_begin(), N->op_end());
   NewOps.reserve(WidenNumElts);
+  SDValue LastElt = NewOps[NumElts - 1];
   for (unsigned i = NumElts; i < WidenNumElts; ++i)
-    NewOps.push_back(DAG.getUNDEF(EltVT));
+    NewOps.push_back(LastElt);
 
   return DAG.getNode(ISD::BUILD_VECTOR, dl, WidenVT, &NewOps[0], NewOps.size());
 }
@@ -1651,10 +1652,11 @@
       LdChain.push_back(Ops[i].getValue(1));
     }
 
-    // Fill the rest with undefs
-    SDValue UndefVal = DAG.getUNDEF(EltVT);
+    // Fill the rest with the last element instead of undefs in case the
+    // widen operation can trap.
+    unsigned last_i = i - 1;
     for (; i != WidenNumElts; ++i)
-      Ops[i] = UndefVal;
+      Ops[i] = Ops[last_i];
 
     Result =  DAG.getNode(ISD::BUILD_VECTOR, dl, WidenVT, &Ops[0], Ops.size());
   } else {
@@ -1662,6 +1664,18 @@
     unsigned int LdWidth = LdVT.getSizeInBits();
     Result = GenWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset,
                                  Align, isVolatile, LdWidth, WidenVT, dl);
+    // Splat the last element instead of leaving the values undefined in case
+    // the widen operation can trap.
+    unsigned WidenNumElts = WidenVT.getVectorNumElements();
+    unsigned NumElts = LdVT.getVectorNumElements();
+    SmallVector<int, 16> Mask;
+    unsigned i = 0;
+    for (i = 0; i < NumElts; ++i)
+      Mask.push_back(i);
+    for (; i < WidenNumElts; ++i)
+      Mask.push_back(NumElts - 1);
+    Result = DAG.getVectorShuffle(WidenVT, dl, Result, DAG.getUNDEF(WidenVT),
+                                  &Mask[0]);
   }
 
  // If we generate a single load, we can use that for the chain.  Otherwise,





More information about the llvm-branch-commits mailing list