[llvm-commits] [llvm] r127320 - /llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp

Cameron Zwarich zwarich at apple.com
Tue Mar 8 23:34:11 PST 2011


Author: zwarich
Date: Wed Mar  9 01:34:11 2011
New Revision: 127320

URL: http://llvm.org/viewvc/llvm-project?rev=127320&view=rev
Log:
Fix a crasher introduced by r127317 that is seen on the bots when using an
alloca as both integer and floating-point vectors of the same size. Bugpoint is
not cooperating with me, but I'll try to find a manual testcase tomorrow.

Modified:
    llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=127320&r1=127319&r2=127320&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Wed Mar  9 01:34:11 2011
@@ -681,25 +681,28 @@
   // access or a bitcast to another vector type of the same size.
   if (const VectorType *VTy = dyn_cast<VectorType>(FromVal->getType())) {
     if (ToType->isVectorTy()) {
-      if (isPowerOf2_64(AllocaSize / TD.getTypeAllocSize(ToType))) {
-        assert(Offset == 0 && "Can't extract a value of a smaller vector type "
-                              "from a nonzero offset.");
-
-        const Type *ToElementTy = cast<VectorType>(ToType)->getElementType();
-        unsigned Scale = AllocaSize / TD.getTypeAllocSize(ToType);
-        const Type *CastElementTy = getScaledElementType(ToElementTy, Scale);
-        unsigned NumCastVectorElements = VTy->getNumElements() / Scale;
-
-        LLVMContext &Context = FromVal->getContext();
-        const Type *CastTy = VectorType::get(CastElementTy,
-                                             NumCastVectorElements);
-        Value *Cast = Builder.CreateBitCast(FromVal, CastTy, "tmp");
-        Value *Extract = Builder.CreateExtractElement(Cast, ConstantInt::get(
-                                          Type::getInt32Ty(Context), 0), "tmp");
-        return Builder.CreateBitCast(Extract, ToType, "tmp");
-      }
+      unsigned ToTypeSize = TD.getTypeAllocSize(ToType);
+      if (ToTypeSize == AllocaSize)
+        return Builder.CreateBitCast(FromVal, ToType, "tmp");
+
+      assert(isPowerOf2_64(AllocaSize / ToTypeSize) &&
+             "Partial vector access of an alloca must have a power-of-2 size "
+             "ratio.");
+      assert(Offset == 0 && "Can't extract a value of a smaller vector type "
+                            "from a nonzero offset.");
+
+      const Type *ToElementTy = cast<VectorType>(ToType)->getElementType();
+      unsigned Scale = AllocaSize / ToTypeSize;
+      const Type *CastElementTy = getScaledElementType(ToElementTy, Scale);
+      unsigned NumCastVectorElements = VTy->getNumElements() / Scale;
 
-      return Builder.CreateBitCast(FromVal, ToType, "tmp");
+      LLVMContext &Context = FromVal->getContext();
+      const Type *CastTy = VectorType::get(CastElementTy,
+                                           NumCastVectorElements);
+      Value *Cast = Builder.CreateBitCast(FromVal, CastTy, "tmp");
+      Value *Extract = Builder.CreateExtractElement(Cast, ConstantInt::get(
+                                        Type::getInt32Ty(Context), 0), "tmp");
+      return Builder.CreateBitCast(Extract, ToType, "tmp");
     }
 
     // Otherwise it must be an element access.





More information about the llvm-commits mailing list