[InstSimplify] Cleanup out-of-range shift amount handling.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 22 Feb 2021 17:00:49 +0000 (17:00 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 22 Feb 2021 17:00:49 +0000 (17:00 +0000)
Use APInt::uge() direct instead of getLimitedValue().

Use KnownBits::getMinValue() to make the bounds check more obvious.

llvm/lib/Analysis/InstructionSimplify.cpp

index 1faf009..4c8340c 100644 (file)
@@ -1209,8 +1209,7 @@ static bool isPoisonShift(Value *Amount, const SimplifyQuery &Q) {
 
   // Shifting by the bitwidth or more is undefined.
   if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
-    if (CI->getValue().getLimitedValue() >=
-        CI->getType()->getScalarSizeInBits())
+    if (CI->getValue().uge(CI->getType()->getScalarSizeInBits()))
       return true;
 
   // If all lanes of a vector shift are undefined the whole shift is.
@@ -1264,7 +1263,7 @@ static Value *SimplifyShift(Instruction::BinaryOps Opcode, Value *Op0,
   // If any bits in the shift amount make that value greater than or equal to
   // the number of bits in the type, the shift is undefined.
   KnownBits Known = computeKnownBits(Op1, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
-  if (Known.One.getLimitedValue() >= Known.getBitWidth())
+  if (Known.getMinValue().uge(Known.getBitWidth()))
     return PoisonValue::get(Op0->getType());
 
   // If all valid bits in the shift amount are known zero, the first operand is