10

I've recently played around with the target_clones attribute available from gcc 6.1 and onward. It's quite nifty, but, for now, it requires a somewhat clumsy approach; every function that one wants multi-versioned has to have an attribute declared manually. This is less than optimal because:

  • It puts compiler-specific stuff in the code.
  • It requires the developer to identify which functions should receive this treatment.

Let's take the example where I want to compile some code that will take advantage of AVX2 instructions, where available. -fopt-info-vect will tell me which functions were vectorized, if I build with -mavx2, so the compiler already knows this. Is there a way to, globally, tell the compiler: "If you find a function which you feel could be optimized with AVX2, make multiple versions, with and without AVX2, of that function."? And if not, can we have one, please?

bolind
  • 512
  • 3
  • 15
  • As a courtesy to other readers, here's a [link to the GCC feature request page](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78464) for this. – einpoklum May 04 '19 at 22:26
  • +1 - It would be even better if the compiler also learned to aggressively merge similar/identical functions (or parts of functions) so that in case a function does not really benefit from multiple arch-specific versions, the redundant versions can be dropped. – CAFxX Dec 13 '22 at 04:58
  • It would bloat files, but it could be laid out in memory so it will only end up touching one variation, so only those would get mapped in. It is only paged in, on demand, from the executable. Also note that modern CPUs have no extra cost for indirect calls that always go to the one place. – doug65536 Mar 12 '23 at 12:31

0 Answers0