[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Feb 23 14:31:03 PST 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.161 -> 1.162
---
Log message:
Fix InstCombine/2004-02-23-ShiftShiftOverflow.ll
Also, turn 'shr int %X, 1234' into 'shr int %X, 31'
---
Diffs of the changes: (+10 -3)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.161 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.162
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.161 Mon Feb 23 01:16:20 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Feb 23 14:30:06 2004
@@ -1570,9 +1570,14 @@
// 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 @@
// 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));
}
More information about the llvm-commits
mailing list