[llvm] 1dc1d5a - [SimplifyLibCalls] Use KnownBits helper APIs (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 07:01:32 PDT 2022


Author: Nikita Popov
Date: 2022-04-06T16:01:24+02:00
New Revision: 1dc1d5a0d2d5059736828c626e230520adf39392

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

LOG: [SimplifyLibCalls] Use KnownBits helper APIs (NFC)

Use helper APIs for isNonNegative() and getMaxValue() instead of
flipping the zero value and having a long comment explaining why
that is necessary.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 329ffcdd48f2b..dc11f55f1728d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -669,21 +669,14 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilderBase &B,
 
       Value *Offset = GEP->getOperand(2);
       KnownBits Known = computeKnownBits(Offset, DL, 0, nullptr, CI, nullptr);
-      Known.Zero.flipAllBits();
       uint64_t ArrSize =
              cast<ArrayType>(GEP->getSourceElementType())->getNumElements();
 
-      // KnownZero's bits are flipped, so zeros in KnownZero now represent
-      // bits known to be zeros in Offset, and ones in KnowZero represent
-      // bits unknown in Offset. Therefore, Offset is known to be in range
-      // [0, NullTermIdx] when the flipped KnownZero is non-negative and
-      // unsigned-less-than NullTermIdx.
-      //
       // If Offset is not provably in the range [0, NullTermIdx], we can still
       // optimize if we can prove that the program has undefined behavior when
       // Offset is outside that range. That is the case when GEP->getOperand(0)
       // is a pointer to an object whose memory extent is NullTermIdx+1.
-      if ((Known.Zero.isNonNegative() && Known.Zero.ule(NullTermIdx)) ||
+      if ((Known.isNonNegative() && Known.getMaxValue().ule(NullTermIdx)) ||
           (GEP->isInBounds() && isa<GlobalVariable>(GEP->getOperand(0)) &&
            NullTermIdx == ArrSize - 1)) {
         Offset = B.CreateSExtOrTrunc(Offset, CI->getType());


        


More information about the llvm-commits mailing list