11

I've read this LWN article with great interest. Executive summary: GCC 6.x supports something called function multi-versioning which builds multiple versions of the same function, optimized for different instruction sets. Let's say you have a machine with AVX2 support and one without. It's possible to run the same binary on both, with function foo() existing in two versions, one of which uses AVX2 instructions. The function with the AVX2 instructions are, however, only called if the CPU supports it.

My question is: does clang support something similar? It doesn't seem like the most advanced feature in the world.

bolind
  • 512
  • 3
  • 15
  • 1
    there should be something, I noticed in the Xcode Instruments profiler calls like _platform_memmove$VARIANT$Haswell which hint that there should be an option. Documentation is totally silent though; target_clones doesn't work, as well as don't work separate functions marked with different target attributes – dev_null Aug 09 '17 at 19:44
  • I added a feature request for it when I discovered it was missing: https://bugs.llvm.org//show_bug.cgi?id=38097 – danblack Aug 18 '18 at 07:39

1 Answers1

3

LLVM 7 supports function multiversioning using the 'target' attribute for ELF-based x86/x86_64 targets.

'target_clones' has yet to land though.

mirh
  • 514
  • 8
  • 14
Hadi Brais
  • 22,259
  • 3
  • 54
  • 95
  • 2
    LLVM 7 is announced to have it: http://lists.llvm.org/pipermail/llvm-announce/2018-September/000080.html – Mr. White Sep 19 '18 at 17:41