<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Function multi-versioning __attribute__((target("foo"))) doesn't support multiple values"
   href="https://bugs.llvm.org/show_bug.cgi?id=41386">41386</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Function multi-versioning __attribute__((target("foo"))) doesn't support multiple values
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nheart@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21732" name="attach_21732" title="Example function multi-versioning">attachment 21732</a> <a href="attachment.cgi?id=21732&action=edit" title="Example function multi-versioning">[details]</a></span>
Example function multi-versioning

Hey,

I am not sure if this is the correct place for this report. It is a mild
enhancement/feature request.

Function multi-versioning was introduced recently in clang and seems to work
quite well. However GCC allows for multiple targets to be specified in a single
function definition, so that if you have some code that captures AVX and AVX2
you don't have to write two different functions for two different architectures
if the codepath is the same. You can do:

__attribute__((target("avx2", "avx512f"))) int foo(int i) {
        return 1;
}

Or

__attribute__((target("sse4.2"), target("avx"))) int foo(int i) {
        return 3;
}

(The latter version compiles, but I'm not sure if it produces the correct
result).

Currently these do not compile on clang resulting in the following error:

test.cpp:7:16: error: 'target' attribute takes one argument
__attribute__((target("sse2", "ssse3"))) int foo(int i) {

Could we have something akin to the first option in Clang? Reference to the
relevant GCC documentation bit:

```
Multiple target back ends implement the target attribute to specify that a
function is to be compiled with different target options than specified on the
command line. One or more strings can be provided as arguments. Each string
consists of one or more comma-separated suffixes to the -m prefix jointly
forming the name of a machine-dependent option. See Machine-Dependent Options.
```

Attached a code sample that compiles on GCC.

Cheers,

Nick</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>