avoid constructing out of range shift amounts.
authorChris Lattner <sabre@nondot.org>
Fri, 17 Jun 2005 01:29:28 +0000 (01:29 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 17 Jun 2005 01:29:28 +0000 (01:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22230 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 76f11a52b285a0230e860958d25a875694914228..321b032505c2b477c7d15ce161985cd7f4dabcae 100644 (file)
@@ -2511,8 +2511,10 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
             if (!CanFold) {
               // To test for the bad case of the signed shr, see if any
               // of the bits shifted in could be tested after the mask.
-              Constant *OShAmt = ConstantUInt::get(Type::UByteTy,
-                               Ty->getPrimitiveSizeInBits()-ShAmt->getValue());
+              int ShAmtVal = Ty->getPrimitiveSizeInBits()-ShAmt->getValue();
+              if (ShAmtVal < 0) ShAmtVal = 0; // Out of range shift.
+
+              Constant *OShAmt = ConstantUInt::get(Type::UByteTy, ShAmtVal);
               Constant *ShVal =
                 ConstantExpr::getShl(ConstantInt::getAllOnesValue(Ty), OShAmt);
               if (ConstantExpr::getAnd(ShVal, AndCST)->isNullValue())