http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55742



--- Comment #36 from Sriraman Tallam <tmsriram at google dot com> 2013-01-18 
18:03:21 UTC ---

(In reply to comment #32)

> Created attachment 29207 [details]

> gcc48-pr55742.patch

> 

> This bug is open for way too long given its severity, so let's start talking

> over patches.

> 

> This patch attempts to implement what I understand from Jason's comments, just

> with "default" instead of "any", because it is indeed the default target

> attribute (whatever you specify on the command line).

> 

> Say on:

> void foo ();

> void foo () __attribute__((target ("avx")));

> void foo () __attribute__((target ("default")));

> __attribute__((target ("default"))) void foo ()

> {

> }

> __attribute__((target ("avx"))) void foo ()

> {

> }

> void (*fn) () = foo;

> 

> first we merge the first two decls, because only if target attribute is 
> present

> on both, we consider it for multi-versioning, for compatibility with 4.7 and

> older.  On e.g.

> void foo ();

> void foo () __attribute__((target ("sse4")));

> void foo () __attribute__((target ("default")));

> void foo ()

> {

> }

> we reject the last fn definition, because at that point foo is already known 
> to

> be multi-versioned, thus it is required that target attribute is specified for

> foo (either "default", or some other).  Unfortunately, for this case the error

> is reported twice for some reason.

> 

> The #c0 testcase now compiles.

> 

> Now, the issues I discovered with multiversioning, still unfixed by the patch:

> 1) the mv*.C testcases should be moved, probably to g++.dg/ext/mv*.C

> 2) can you please explain the mess in handle_target_attribute?

>   /* Do not strip invalid target attributes for targets which support function

>      multiversioning as the target string is used to determine versioned

>      functions.  */

>   else if (! targetm.target_option.valid_attribute_p (*node, name, args,

>                                                       flags)

>            && ! targetm.target_option.supports_function_versions ())

>     *no_add_attrs = true;

> Why do you need that?  



This was added because previously if I had two declarations of foo like this:



void foo ();

void foo __target__(("sse4.2")));



int main ()

{

  foo ();

}



void foo ()

{

}



__target__(("sse4.2")));

void foo ()

{

}





The call to foo in main will be treated like 2 different versions of foo exist.



However with -msse4.2 on the command-line, the target attribute will be

stripped off the second declaration which makes foo no longer multi-versioned

when the call to foo is processed. The call to foo without -msse4.2 is

multi-versioned and with -msse4.2 is not. I wanted to avoid this behaviour.





Consider complete garbage in target attribute arguments,

> which is errored about, but the above for i386/x86_64 keeps the target

> attribute around anyway, leading to lots of ICEs everywhere:

> Consider e.g.:

> __attribute__((target ("default"))) void foo (void)

> {

> }

> __attribute__((target (128))) void foo (void)

> {

> }

> 3) the multiversioning code assumes that target has a single argument, but it

> can have more than one.  Say for:

> __attribute__((target ("avx,popcnt"))) void foo (void)

> {

> }

> __attribute__((target ("popcnt","avx"))) void bar (void)

> {

> }

> the compiler handles those two as equivalent, but with -Dbar=foo

> multi-versioning only considers the first string out of that.

Reply via email to