https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120113

            Bug ID: 120113
           Summary: Attempting to multiversion a function on AVX512
                    produces nonsensical results
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: krzysio.kurek at wp dot pl
  Target Milestone: ---

Given the following code:
```
[[gnu::target("default")]]
bool compressAvailable()
{
    return false;
}

[[gnu::target("avx512vbmi2")]]
bool compressAvailable()
{
    return true;
}

int main()
{
    compressAvailable();
}
```
The program will always unconditionally return false, as gcc fails to create a
resolve function and does not create a call to ifunc, and inlines the default
target version. If instead of avx512vbmi2 avx512f is passed, the ifunc is
generated as expected and the inlining is gone.

Furthermore, if 3 versions of the function are specified, i.e.:
```
[[gnu::target("default")]]
bool compressAvailable()
{
    return false;
}

[[gnu::target("avx512f")]]
bool compressAvailable()
{
    return false;
}

[[gnu::target("avx512vbmi2")]]
bool compressAvailable()
{
    return true;
}

int main()
{
    compressAvailable();
}
```
finally a sane error appears:
```
<source>: In function '_Z17compressAvailablev.resolver':
<source>:14:6: error: ISA 'avx512vbmi2' is not supported in 'target' attribute,
use 'arch=' syntax
   14 | bool compressAvailable()
      |      ^~~~~~~~~~~~~~~~~
Compiler returned: 1
```

Reply via email to