[PATCH] D105440: [RFC] Implement support for __builtin_memcmp_inline

Andre Vieira via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 5 10:27:56 PDT 2021


avieira created this revision.
avieira added a reviewer: gchatelet.
Herald added a subscriber: hiraditya.
avieira requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

Hi all,

This is my initial attempt at implementing a __builtin_memcmp_inline function in LLVM. The motivation is to use it in an optimized LLVM Libc implementation of memcmp whilst still using `-ffreestanding` and `-fno-builtin-memcmp`.

I haven't added any tests and I know for a fact this goes completely wrong if your memcmp size is big enough to hit the maximum number of loads, or if you compile for size. I just wanted to bring up this RFC before I start going down the wrong path.

My current thinking is the following:

1. Inline when compiling for size, the use of this builtin should force inlining where possible, regardless of global compilation options. My reasoning here is that if people really don't want to inline due to size considerations, don't use the inline variant of this builtin.
2. I'm split on what to do for when the memcmp size is large enough to hit the maximum number of loads. I think there are three options: a) We  ignore the maximum number of loads and just generate a lot of code... (kind of the same strategy with memcpy) b) We use a call to memcmp (and issue a diagnostic saying we did so?) c) Error out I'm not keen on (c), I suspect (a) would probably make the most sense and hope that users of the builtin are sensible?

Let me know if there are any strong opinions on this. Please add other reviewers if you know they would have an interest in this.

Kind regards,
Andre


https://reviews.llvm.org/D105440

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/ExpandMemCmp.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/Transforms/Utils/MemoryOpRemark.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105440.356525.patch
Type: text/x-patch
Size: 8237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210705/558978e1/attachment.bin>


More information about the llvm-commits mailing list