diff options
author | Chris Lattner <sabre@nondot.org> | 2004-02-23 20:30:06 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-02-23 20:30:06 +0000 |
commit | 8adac752983caf4392932d53f5fb24fb39ee5344 (patch) | |
tree | a9de95e9a7be4445f2da83d48460f2f4e265d159 | |
parent | 86171b9203083835a035ed72434ffea701e97f04 (diff) | |
download | external_llvm-8adac752983caf4392932d53f5fb24fb39ee5344.tar.gz external_llvm-8adac752983caf4392932d53f5fb24fb39ee5344.tar.bz2 external_llvm-8adac752983caf4392932d53f5fb24fb39ee5344.zip |
Fix InstCombine/2004-02-23-ShiftShiftOverflow.ll
Also, turn 'shr int %X, 1234' into 'shr int %X, 31'
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11768 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 105f2ae502..74283759a1 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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)); } |