Fix a bug where we would 'promote' an allocation from one type to another
authorChris Lattner <sabre@nondot.org>
Mon, 24 Oct 2005 06:26:18 +0000 (06:26 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 24 Oct 2005 06:26:18 +0000 (06:26 +0000)
where the second has less alignment required.  If we had explicit alignment
support in the IR, we could handle this case, but we can't until we do.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23960 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 09fee7cc4bd0e6ec3f57d8046f9f6819a6476190..bd85b4abd5d0adc6839e176af64951ece6253b54 100644 (file)
@@ -3795,10 +3795,14 @@ Instruction *InstCombiner::PromoteCastOfAllocation(CastInst &CI,
   const Type *AllocElTy = AI.getAllocatedType();
   const Type *CastElTy = PTy->getElementType();
   if (!AllocElTy->isSized() || !CastElTy->isSized()) return 0;
-  
+
+  unsigned AllocElTyAlign = TD->getTypeSize(AllocElTy);
+  unsigned CastElTyAlign = TD->getTypeSize(CastElTy);
+  if (CastElTyAlign < AllocElTyAlign) return 0;
+
   uint64_t AllocElTySize = TD->getTypeSize(AllocElTy);
   uint64_t CastElTySize = TD->getTypeSize(CastElTy);
-  
+
   // If the allocation is for an even multiple of the cast type size
   if (CastElTySize == 0 || AllocElTySize % CastElTySize != 0)
     return 0;