diff options
| author | Evan Cheng <evan.cheng@apple.com> | 2009-04-22 23:39:28 +0000 |
|---|---|---|
| committer | Evan Cheng <evan.cheng@apple.com> | 2009-04-22 23:39:28 +0000 |
| commit | d8174d3d09355adb15480d2b39506814f8c673cb (patch) | |
| tree | 61bf82f880c9233ef11fde2a7373e68919e27293 /llvm/lib/Transforms | |
| parent | 85e110828e4ca7e60db59b210bd739dcf98c1b91 (diff) | |
| download | bcm5719-llvm-d8174d3d09355adb15480d2b39506814f8c673cb.tar.gz bcm5719-llvm-d8174d3d09355adb15480d2b39506814f8c673cb.zip | |
Make sure both operands have binary instructions have the same type.
llvm-svn: 69844
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 1dd84b1816b..63ef021eb31 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -751,11 +751,14 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // We've determined this is (i+constant) and it won't overflow. if (isa<SExtInst>(UInst->use_begin())) { SExtInst* oldSext = dyn_cast<SExtInst>(UInst->use_begin()); + uint64_t truncSize = oldSext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, L, oldSext->getType(), Rewriter, InsertPt); - APInt APcopy = APInt(AddRHS->getValue()); - ConstantInt* newAddRHS =ConstantInt::get(APcopy.sext(newBitSize)); + APInt APnewAddRHS = APInt(AddRHS->getValue()).sext(newBitSize); + if (newBitSize > truncSize) + APnewAddRHS = APnewAddRHS.trunc(truncSize); + ConstantInt* newAddRHS =ConstantInt::get(APnewAddRHS); Value *NewAdd = BinaryOperator::CreateAdd(TruncIndVar, newAddRHS, UInst->getName()+".nosex", UInst); @@ -779,18 +782,21 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { if (!RHS->getValue().isNegative()) { uint64_t newBitSize = LargestType->getPrimitiveSizeInBits(); SExtInst* oldSext = dyn_cast<SExtInst>(UInst->use_begin()); + uint64_t truncSize = oldSext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, L, oldSext->getType(), Rewriter, InsertPt); - APInt APcopy = APInt(RHS->getValue()); - ConstantInt* newRHS =ConstantInt::get(APcopy.sext(newBitSize)); - Value *NewAdd = - BinaryOperator::CreateOr(TruncIndVar, newRHS, + APInt APnewOrRHS = APInt(RHS->getValue()).sext(newBitSize); + if (newBitSize > truncSize) + APnewOrRHS = APnewOrRHS.trunc(truncSize); + ConstantInt* newOrRHS =ConstantInt::get(APnewOrRHS); + Value *NewOr = + BinaryOperator::CreateOr(TruncIndVar, newOrRHS, UInst->getName()+".nosex", UInst); for (Value::use_iterator UI2 = UInst->use_begin(), UE2 = UInst->use_end(); UI2 != UE2; ++UI2) { Instruction *II = dyn_cast<Instruction>(UI2); - II->replaceAllUsesWith(NewAdd); + II->replaceAllUsesWith(NewOr); DeadInsts.insert(II); } DeadInsts.insert(UInst); @@ -814,10 +820,13 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { uint64_t newBitSize = LargestType->getPrimitiveSizeInBits(); ConstantInt* AndRHS = dyn_cast<ConstantInt>(UInst->getOperand(1)); ZExtInst* oldZext = dyn_cast<ZExtInst>(UInst->use_begin()); + uint64_t truncSize = oldZext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, L, oldZext->getType(), Rewriter, InsertPt); - APInt APcopy = APInt(AndRHS->getValue()); - ConstantInt* newAndRHS = ConstantInt::get(APcopy.zext(newBitSize)); + APInt APnewAndRHS = APInt(AndRHS->getValue()).zext(newBitSize); + if (newBitSize > truncSize) + APnewAndRHS = APnewAndRHS.trunc(truncSize); + ConstantInt* newAndRHS = ConstantInt::get(APnewAndRHS); Value *NewAnd = BinaryOperator::CreateAnd(TruncIndVar, newAndRHS, UInst->getName()+".nozex", UInst); @@ -847,11 +856,14 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { allUsesAreSameTyped(Instruction::ZExt, UInst2) && isa<ConstantInt>(UInst2->getOperand(1))) { ZExtInst* oldZext = dyn_cast<ZExtInst>(UInst2->use_begin()); + uint64_t truncSize = oldZext->getType()->getPrimitiveSizeInBits(); Value *TruncIndVar = getSignExtendedTruncVar(AR, SE, LargestType, L, oldZext->getType(), Rewriter, InsertPt); ConstantInt* AndRHS = dyn_cast<ConstantInt>(UInst2->getOperand(1)); - APInt APcopy = APInt(AddRHS->getValue()); - ConstantInt* newAddRHS = ConstantInt::get(APcopy.zext(newBitSize)); + APInt APnewAddRHS = APInt(AddRHS->getValue()).zext(newBitSize); + if (newBitSize > truncSize) + APnewAddRHS = APnewAddRHS.trunc(truncSize); + ConstantInt* newAddRHS = ConstantInt::get(APnewAddRHS); Value *NewAdd = ((UInst->getOpcode()==Instruction::Add) ? BinaryOperator::CreateAdd(TruncIndVar, newAddRHS, UInst->getName()+".nozex", UInst2) : |

