use the very-handy getTruncateOrZeroExtend helper function, and

stop setting NSW: signed overflow is possible.  Thanks to Dan
for pointing these out.

llvm-svn: 122790
This commit is contained in:
Chris Lattner 2011-01-04 00:06:55 +00:00
parent 4466e981f9
commit 0ba473c218
1 changed files with 6 additions and 14 deletions

View File

@ -349,17 +349,13 @@ processLoopStoreOfSplatValue(StoreInst *SI, unsigned StoreSize,
// The # stored bytes is (BECount+1)*Size. Expand the trip count out to
// pointer size if it isn't already.
const Type *IntPtr = TD->getIntPtrType(SI->getContext());
unsigned BESize = SE->getTypeSizeInBits(BECount->getType());
if (BESize < TD->getPointerSizeInBits())
BECount = SE->getZeroExtendExpr(BECount, IntPtr);
else if (BESize > TD->getPointerSizeInBits())
BECount = SE->getTruncateExpr(BECount, IntPtr);
BECount = SE->getTruncateOrZeroExtend(BECount, IntPtr);
const SCEV *NumBytesS = SE->getAddExpr(BECount, SE->getConstant(IntPtr, 1),
true, true /*nooverflow*/);
true /*no unsigned overflow*/);
if (StoreSize != 1)
NumBytesS = SE->getMulExpr(NumBytesS, SE->getConstant(IntPtr, StoreSize),
true, true /*nooverflow*/);
true /*no unsigned overflow*/);
Value *NumBytes =
Expander.expandCodeFor(NumBytesS, IntPtr, Preheader->getTerminator());
@ -426,17 +422,13 @@ processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize,
// The # stored bytes is (BECount+1)*Size. Expand the trip count out to
// pointer size if it isn't already.
const Type *IntPtr = TD->getIntPtrType(SI->getContext());
unsigned BESize = SE->getTypeSizeInBits(BECount->getType());
if (BESize < TD->getPointerSizeInBits())
BECount = SE->getZeroExtendExpr(BECount, IntPtr);
else if (BESize > TD->getPointerSizeInBits())
BECount = SE->getTruncateExpr(BECount, IntPtr);
BECount = SE->getTruncateOrZeroExtend(BECount, IntPtr);
const SCEV *NumBytesS = SE->getAddExpr(BECount, SE->getConstant(IntPtr, 1),
true, true /*nooverflow*/);
true /*no unsigned overflow*/);
if (StoreSize != 1)
NumBytesS = SE->getMulExpr(NumBytesS, SE->getConstant(IntPtr, StoreSize),
true, true /*nooverflow*/);
true /*no unsigned overflow*/);
Value *NumBytes =
Expander.expandCodeFor(NumBytesS, IntPtr, Preheader->getTerminator());