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

Siddhesh Poyarekar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 10 02:10:49 PST 2020


siddhesh created this revision.
siddhesh added a reviewer: serge-sans-paille.
Herald added a subscriber: hiraditya.
siddhesh requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When `__builtin_dynamic_object_size` returns a non-constant expression, it cannot be `-1` since that is an invalid return value for object size. However since passes running after the substitution don't know this, they are unable to optimize away the comparison and hence the comparison and branch stays in there.  This change traverses uses of the object size when lowering the builtin to a constant or expression, and folds away comparisons with -1.

glibc is considering adopting `__builtin_dynamic_object_size` for additional protection[1] and this change will help reduce branching overhead in fortified implementations of all of the functions that don't have the `__builtin___*_chk` type builtins, e.g. __ppoll_chk.

[1] https://sourceware.org/pipermail/libc-alpha/2020-November/120191.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93015

Files:
  llvm/lib/Analysis/MemoryBuiltins.cpp
  llvm/test/Transforms/InstCombine/builtin-dynamic-object-size.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93015.310805.patch
Type: text/x-patch
Size: 3577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201210/2f526753/attachment.bin>


More information about the llvm-commits mailing list