ShiftAmt might equal to zero. Handle this situation.
authorZhou Sheng <zhousheng00@gmail.com>
Wed, 14 Mar 2007 09:07:33 +0000 (09:07 +0000)
committerZhou Sheng <zhousheng00@gmail.com>
Wed, 14 Mar 2007 09:07:33 +0000 (09:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35094 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index e072d966a7b315264726cdcd343a9a56c7e008a6..1e5b7ec3ca2f23bcdba428cf57f4d82b15afac1d 100644 (file)
@@ -1997,7 +1997,8 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, APInt DemandedMask,
       RHSKnownZero <<= ShiftAmt;
       RHSKnownOne  <<= ShiftAmt;
       // low bits known zero.
-      RHSKnownZero |= APInt::getAllOnesValue(ShiftAmt).zextOrCopy(BitWidth);
+      if (ShiftAmt)
+        RHSKnownZero |= APInt::getAllOnesValue(ShiftAmt).zextOrCopy(BitWidth);
     }
     break;
   case Instruction::LShr:
@@ -2013,14 +2014,16 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, APInt DemandedMask,
         return true;
       assert((RHSKnownZero & RHSKnownOne) == 0 && 
              "Bits known to be one AND zero?"); 
-      // Compute the new bits that are at the top now.
-      APInt HighBits(APInt::getAllOnesValue(ShiftAmt).zextOrCopy(BitWidth).shl(
-              BitWidth - ShiftAmt));
       RHSKnownZero &= TypeMask;
       RHSKnownOne  &= TypeMask;
       RHSKnownZero = APIntOps::lshr(RHSKnownZero, ShiftAmt);
       RHSKnownOne  = APIntOps::lshr(RHSKnownOne, ShiftAmt);
-      RHSKnownZero |= HighBits;  // high bits known zero.
+      if (ShiftAmt) {
+        // Compute the new bits that are at the top now.
+        APInt HighBits(APInt::getAllOnesValue(BitWidth).shl(
+                         BitWidth - ShiftAmt));
+        RHSKnownZero |= HighBits;  // high bits known zero.
+      }
     }
     break;
   case Instruction::AShr:
@@ -2048,8 +2051,7 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, APInt DemandedMask,
       assert((RHSKnownZero & RHSKnownOne) == 0 && 
              "Bits known to be one AND zero?"); 
       // Compute the new bits that are at the top now.
-      APInt HighBits(APInt::getAllOnesValue(ShiftAmt).zextOrCopy(BitWidth).shl(
-              BitWidth - ShiftAmt));
+      APInt HighBits(APInt::getAllOnesValue(BitWidth).shl(BitWidth - ShiftAmt));
       RHSKnownZero &= TypeMask;
       RHSKnownOne  &= TypeMask;
       RHSKnownZero = APIntOps::lshr(RHSKnownZero, ShiftAmt);