summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-02-23 20:30:06 +0000
committerChris Lattner <sabre@nondot.org>2004-02-23 20:30:06 +0000
commitf5ce254692bc6d06e5ac46d38e361645f6dbdaa0 (patch)
tree7a4a9d862a09a0cec5e9d73f72e433a8e7d40c63 /llvm/lib/Transforms
parent7eaa535d4d58620df9f754e5a778e21813bcc856 (diff)
downloadbcm5719-llvm-f5ce254692bc6d06e5ac46d38e361645f6dbdaa0.tar.gz
bcm5719-llvm-f5ce254692bc6d06e5ac46d38e361645f6dbdaa0.zip
Fix InstCombine/2004-02-23-ShiftShiftOverflow.ll
Also, turn 'shr int %X, 1234' into 'shr int %X, 31' llvm-svn: 11768
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 105f2ae5020..74283759a14 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1570,9 +1570,14 @@ Instruction *InstCombiner::visitShiftInst(ShiftInst &I) {
// of a signed value.
//
unsigned TypeBits = Op0->getType()->getPrimitiveSize()*8;
- if (CUI->getValue() >= TypeBits &&
- (!Op0->getType()->isSigned() || isLeftShift))
- return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
+ if (CUI->getValue() >= TypeBits) {
+ if (!Op0->getType()->isSigned() || isLeftShift)
+ return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
+ else {
+ I.setOperand(1, ConstantUInt::get(Type::UByteTy, TypeBits-1));
+ return &I;
+ }
+ }
// ((X*C1) << C2) == (X * (C1 << C2))
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0))
@@ -1636,6 +1641,8 @@ Instruction *InstCombiner::visitShiftInst(ShiftInst &I) {
// Check for (A << c1) << c2 and (A >> c1) >> c2
if (I.getOpcode() == Op0SI->getOpcode()) {
unsigned Amt = ShiftAmt1+ShiftAmt2; // Fold into one big shift...
+ if (Op0->getType()->getPrimitiveSize()*8 < Amt)
+ Amt = Op0->getType()->getPrimitiveSize()*8;
return new ShiftInst(I.getOpcode(), Op0SI->getOperand(0),
ConstantUInt::get(Type::UByteTy, Amt));
}
OpenPOWER on IntegriCloud