[PATCH] D93015: Fold comparison of __builtin_object_size expression with -1 for non-const size

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 18 06:51:49 PST 2020


serge-sans-paille added a comment.

@siddhesh what anout the following?

  diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
  index cbb54e8..7c4342d 100644
  --- a/llvm/lib/Analysis/MemoryBuiltins.cpp
  +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
  @@ -559,6 +559,14 @@ Value *llvm::lowerObjectSizeCall(IntrinsicInst *ObjectSize,
         IRBuilder<TargetFolder> Builder(Ctx, TargetFolder(DL));
         Builder.SetInsertPoint(ObjectSize);
   
  +      if (!isa<Constant>(SizeOffsetPair.first) ||
  +          !isa<Constant>(SizeOffsetPair.second)) {
  +        auto Iter = ObjectSize->getIterator();
  +        ++Iter;
  +        IRBuilder<> Builder(&*Iter);
  +        Builder.CreateAssumption(Builder.CreateICmpSGE(ObjectSize, ConstantInt::get(ResultType, 0)));
  +      }
  +
         // If we've outside the end of the object, then we can always access
         // exactly 0 bytes.
         Value *ResultSize =


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93015/new/

https://reviews.llvm.org/D93015



More information about the llvm-commits mailing list