[PATCH] D56313: [SelectionDAG][RFC] Allow the user to specify a memeq function (v3).

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 4 04:47:48 PST 2019


courbet created this revision.

Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.

This is sub-optimal because memcmp has to compute much more than
equality.

This patch adds a way for the user to specify a `memeq` library
function using a function attribute, e.g.:

  attributes #0 = { "memeq-func-name"="user_memeq" }
  
  ...
  
    %m = tail call i32 @memcmp(i8* %a, i8* %b, i64 %s) nounwind #0
    %c = icmp eq i32 %m, 0
    ret i1 %c

This function will be called instead of `memcmp()` when the result of the memcmp
call is only used for equality comparison.

`memeq` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.


Repository:
  rL LLVM

https://reviews.llvm.org/D56313

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  test/CodeGen/X86/memcmp-memeq.ll
  test/CodeGen/X86/memcmp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56313.180224.patch
Type: text/x-patch
Size: 12588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190104/4ef0b91d/attachment.bin>


More information about the llvm-commits mailing list