public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59865] New: gnu multiversion calculates wrong target
@ 2014-01-17 19:27 mib.bugzilla at gmail dot com
  2014-01-20  9:13 ` [Bug c++/59865] " rguenth at gcc dot gnu.org
  2014-01-20 15:00 ` mib.bugzilla at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: mib.bugzilla at gmail dot com @ 2014-01-17 19:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59865
           Summary: gnu multiversion calculates wrong target
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mib.bugzilla at gmail dot com

According to the gnu multiversion wiki, if a target function is specified with
arch=corei7, and another taret function is specified with "popcnt", then the
arch= function should win, because corei7 supports popcnt as well.

however, gcc 4.8.1 is choosing the popcnt target, not the corei7 target.

Do you expect this discrepancy will be fixed?

Test case:
cat corei7.C
#include <cstdio>
int __attribute__ ((target("default")))
foo() { puts("default wins\n"); }

int __attribute__((target("arch=corei7")))
foo() { puts("corei7 wins\n"); }

int __attribute__((target("popcnt")))
foo() { puts("popcnt wins\n"); }

int main ()
{
  int val = foo ();
  return 0;
}
-bash-4.1$ g++ corei7.C
-bash-4.1$ ./a.out
popcnt wins

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/rdrive/ref/gcc/4.8.1/rhel60/efi2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
/rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/configure
--prefix=/rdrive/ref/gcc/4.8.1/rhel60/efi2
--enable-languages=c,c++,objc,fortran --disable-multilib --enable-bootstrap
--target=x86_64-unknown-linux-gnu --disable-bootstrap --enable-decimal-float
--with-gmp=/rusers/sys_cron/grab_gcc/downloads_rel/lib/efi2
--with-mpfr=/rusers/sys_cron/grab_gcc/downloads_rel/lib/efi2
--with-mpc=/rusers/sys_cron/grab_gcc/downloads_rel/lib/efi2
Thread model: posix
gcc version 4.8.1 (GCC)

Quoting the wiki: 
When a function version with target attribute "arch=<processor X>" is compared
with a function version with attribute "<ISA Y>", then the highest priority of
the any ISA supported by processor X is compared to the priority of ISA Y to
decide which version should be dispatched first. If the priorities are the same
then the version with "arch=" is given precedence. For instance, when comparing
"arch=corei7" and "popcnt", "arch=corei7" wins since the priority of the
highest ISA supported by corei7 is popcnt.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/59865] gnu multiversion calculates wrong target
  2014-01-17 19:27 [Bug c++/59865] New: gnu multiversion calculates wrong target mib.bugzilla at gmail dot com
@ 2014-01-20  9:13 ` rguenth at gcc dot gnu.org
  2014-01-20 15:00 ` mib.bugzilla at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-01-20  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2014-01-20
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
What's the target you are running on?   Please provide /proc/cpuinfo output.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/59865] gnu multiversion calculates wrong target
  2014-01-17 19:27 [Bug c++/59865] New: gnu multiversion calculates wrong target mib.bugzilla at gmail dot com
  2014-01-20  9:13 ` [Bug c++/59865] " rguenth at gcc dot gnu.org
@ 2014-01-20 15:00 ` mib.bugzilla at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: mib.bugzilla at gmail dot com @ 2014-01-20 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from mib.bugzilla at gmail dot com ---
Thanks. I realized after I posted that the test case isn't definitive. Improved
test case pasted below.

Inspection of the assembly listing shows that popcnt is being checked before
arch=corei7.  I was testing to see the precendence of arch= versus isa by
creating foo for all isa, then seeing where a single arch= is sorted in the
dispatch function.

cat core-pop.C
#include <assert.h>
#include <string.h>
#include <cstdio>
const char * __attribute__ ((target("default"))) foo(void)
{ return("default wins\n");}
const char* __attribute__ ((target("arch=corei7"))) foo(void)
{ return("corei7 wins\n");}
const char* __attribute__ ((target("popcnt"))) foo(void)
{ return("popcnt wins\n");}
int main ()
{
  const char *result = foo ();
  if (__builtin_cpu_is ("corei7")) puts("builtin cpu is corei7\n");
  if (__builtin_cpu_is ("corei7"))
    assert ( 0 == strcmp(result, "corei7 wins"));
  return 0;
}
-bash-4.1$ g++ core-pop.C -S
-bash-4.1$ g++ core-pop.C
-bash-4.1$ grep movl core-pop.s | grep foov //From dispatch function
        movl    $_Z3foov.popcnt, %eax
        movl    $_Z3foov.arch_corei7, %eax
        movl    $_Z3foov, %eax
-bash-4.1$ ./a.out
builtin cpu is corei7

a.out: core-pop.C:15: int main(): Assertion `0 == strcmp(result, "corei7
wins")' failed.
Aborted (core dumped)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-20 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-17 19:27 [Bug c++/59865] New: gnu multiversion calculates wrong target mib.bugzilla at gmail dot com
2014-01-20  9:13 ` [Bug c++/59865] " rguenth at gcc dot gnu.org
2014-01-20 15:00 ` mib.bugzilla at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).