Fix a bug where we would 'promote' an allocation from one type to another

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.

llvm-svn: 23960
This commit is contained in:
Chris Lattner 2005-10-24 06:26:18 +00:00
parent 3806b84861
commit a295128ce5

View 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;