[cfe-commits] [PATCH][Review request] correct initialization of AltiVec vectors

Douglas Gregor dgregor at apple.com
Mon Jan 17 10:59:38 PST 2011


On Dec 29, 2010, at 4:14 PM, Anton Yartsev wrote:

> Hi all,
> 
> made changes according to the rules for the '(...)' form of vector initialization in AltiVec: the number of initializers must be one or must match the size of the vector. If a single value is specified in the initializer then it will be replicated to all the components of the vector.
> 
> Can I commit the patch?

+    // '(...)' form of vector initialization in AltiVec: the number of
+    // initializers must be one or must match the size of the vector.
+    // If a single value is specified in the initializer then it will be
+    // replicated to all the components of the vector
+    if (Ty->getAs<VectorType>()->getVectorKind() ==
+        VectorType::AltiVecVector) {
+      unsigned numElems = Ty->getAs<VectorType>()->getNumElements();
+      // The number of initializers must be one or must match the size of the
+      // vector. If a single value is specified in the initializer then it will
+      // be replicated to all the components of the vector
+      if (PE->getNumExprs() == 1) {
+        Expr* initExpr = PE->getExpr(0);
+        for (unsigned i = 0; i != numElems; ++i)
+          initExprs.push_back(initExpr);

This is effectively just a vector splat, so why not model it as an explicit C-style cast with kind CK_VectorSplat? That would more accurately describe what's happening than making this look like a vector initialization.

	- Doug



More information about the cfe-commits mailing list