[PATCH] D127461: [SelectionDAG] Use __memcmpeq to replace bcmp and bool usage memcmp

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 17:09:07 PDT 2022


goldstein.w.n created this revision.
Herald added subscribers: jsji, ecnelises, pengfei, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add __memcmpeq as a LibCall enabled by cl::opt option:
'--with-builtin-memcmpeq'.

If enabled calls to bcmp will be replaced with __memcmpeq and calls to
memcmp that only use the result as a boolean will be replaced
with __memcmpeq.

If not enabled this patch has no effect.

This is essentially a follow up to: https://reviews.llvm.org/D56593

In glibc we decided against adding an optimized bcmp:
https://marc.info/?t=163157542200002&r=1&w=3
because its not in a reserved namespace.

To get the functionality (and make the bool usage memcmp optimization
meaningful on GNU systems) we added __memcmpeq:
https://sourceware.org/git/?p=glibc.git;a=commit;h=44829b3ddb64e99e37343a0f25b2c082387d31a5

Which was release with GLIBC 2.35.

Unlike bcmp which is an alias to memcmp on all targets in GLIBC,
__memcmpeq is actually better optimized on some targets (x86 as
of writing this patch).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127461

Files:
  llvm/include/llvm/Analysis/TargetLibraryInfo.def
  llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
  llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
  llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/memcmp-1.ll
  llvm/test/Transforms/InstCombine/strcmp-1.ll
  llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127461.435743.patch
Type: text/x-patch
Size: 12943 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220610/2bdbe942/attachment.bin>


More information about the llvm-commits mailing list