[llvm] bc730b5 - [InstCombine] collectBitParts - use APInt directly to check for out of range bit shifts. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 04:50:55 PDT 2020


Author: Simon Pilgrim
Date: 2020-10-01T12:50:36+01:00
New Revision: bc730b5e43ad4b7efeca977359271fa0eaa7ed45

URL: https://github.com/llvm/llvm-project/commit/bc730b5e43ad4b7efeca977359271fa0eaa7ed45
DIFF: https://github.com/llvm/llvm-project/commit/bc730b5e43ad4b7efeca977359271fa0eaa7ed45.diff

LOG: [InstCombine] collectBitParts - use APInt directly to check for out of range bit shifts. NFCI.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/Local.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 0dacb266a063..550745673bd9 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2872,10 +2872,10 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
 
     // If this is a logical shift by a constant, recurse then shift the result.
     if (I->isLogicalShift() && isa<ConstantInt>(I->getOperand(1))) {
-      unsigned BitShift =
-          cast<ConstantInt>(I->getOperand(1))->getLimitedValue(~0U);
+      const APInt &BitShift = cast<ConstantInt>(I->getOperand(1))->getValue();
+
       // Ensure the shift amount is defined.
-      if (BitShift > BitWidth)
+      if (BitShift.uge(BitWidth))
         return Result;
 
       const auto &Res = collectBitParts(I->getOperand(0), MatchBSwaps,
@@ -2887,11 +2887,11 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
       // Perform the "shift" on BitProvenance.
       auto &P = Result->Provenance;
       if (I->getOpcode() == Instruction::Shl) {
-        P.erase(std::prev(P.end(), BitShift), P.end());
-        P.insert(P.begin(), BitShift, BitPart::Unset);
+        P.erase(std::prev(P.end(), BitShift.getZExtValue()), P.end());
+        P.insert(P.begin(), BitShift.getZExtValue(), BitPart::Unset);
       } else {
-        P.erase(P.begin(), std::next(P.begin(), BitShift));
-        P.insert(P.end(), BitShift, BitPart::Unset);
+        P.erase(P.begin(), std::next(P.begin(), BitShift.getZExtValue()));
+        P.insert(P.end(), BitShift.getZExtValue(), BitPart::Unset);
       }
 
       return Result;


        


More information about the llvm-commits mailing list