Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Function multi-versioning __attribute__((target("foo"))) doesn't support multiple values #40356

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR41386
Status NEW
Importance P enhancement
Reported by Nick (nheart@gmail.com)
Reported on 2019-04-04 15:31:48 -0700
Last modified on 2019-04-04 15:36:15 -0700
Version 8.0
Hardware PC Linux
CC blitzrakete@gmail.com, dblaikie@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments test.cpp (453 bytes, text/x-c++src)
test.cpp (504 bytes, text/x-c++src)
Blocks
Blocked by
See also

Created attachment 21732 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

Quuxplusone commented 5 years ago

Attached test.cpp (453 bytes, text/x-c++src): Example function multi-versioning

Quuxplusone commented 5 years ago

Attached test.cpp (504 bytes, text/x-c++src): Example function multi-versioning,correct this time