diff options
author | Chris Lattner <sabre@nondot.org> | 2005-06-15 20:53:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-06-15 20:53:31 +0000 |
commit | e17a128a554dfc4aba74cefa7839f602dd73386f (patch) | |
tree | 9b0f696e6bcff8916ed563066cf075b90a03a5f3 /lib/Transforms | |
parent | 7833b44f6a7cb790fd6d0034b6a7d7dc820765cb (diff) |
Fix PR577 and testcase InstCombine/2005-06-15-ShiftSetCCCrash.ll.
Do not perform undefined out of range shifts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22217 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 53ee6ca01f..02438202dc 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2560,6 +2560,14 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) { default: break; case Instruction::SetEQ: case Instruction::SetNE: { + unsigned TypeBits = CI->getType()->getPrimitiveSizeInBits(); + + // Check that the shift amount is in range. If not, don't perform + // undefined shifts. When the shift is visited it will be + // simplified. + if (ShAmt->getValue() >= TypeBits) + break; + // If we are comparing against bits always shifted out, the // comparison cannot succeed. Constant *Comp = @@ -2573,7 +2581,6 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) { if (LHSI->hasOneUse()) { // Otherwise strength reduce the shift into an and. unsigned ShAmtVal = (unsigned)ShAmt->getValue(); - unsigned TypeBits = CI->getType()->getPrimitiveSizeInBits(); uint64_t Val = (1ULL << (TypeBits-ShAmtVal))-1; Constant *Mask; @@ -2603,6 +2610,14 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) { default: break; case Instruction::SetEQ: case Instruction::SetNE: { + + // Check that the shift amount is in range. If not, don't perform + // undefined shifts. When the shift is visited it will be + // simplified. + unsigned TypeBits = ShAmt->getType()->getPrimitiveSizeInBits(); + if (ShAmt->getValue() >= TypeBits) + break; + // If we are comparing against bits always shifted out, the // comparison cannot succeed. Constant *Comp = @@ -2623,7 +2638,6 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) { Constant *Mask; if (CI->getType()->isUnsigned()) { - unsigned TypeBits = CI->getType()->getPrimitiveSizeInBits(); Val &= ~0ULL >> (64-TypeBits); Mask = ConstantUInt::get(CI->getType(), Val); } else { |