[Bug ipa/95790] Incorrect static target dispatch

yyc1992 at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Jun 20 19:25:04 GMT 2020


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

--- Comment #2 from Yichao Yu <yyc1992 at gmail dot com> ---
The C++ code attached above produces the following incorrect code with `g++ -O2
-S`

        .file   "a.c"
        .text
        .p2align 4
        .globl  _Z3barv
        .type   _Z3barv, @function
_Z3barv:
.LFB3:
        .cfi_startproc
        movl    $4096, %eax
        ret
        .cfi_endproc
.LFE3:
        .size   _Z3barv, .-_Z3barv
        .p2align 4
        .globl  _Z3barv.avx
        .type   _Z3barv.avx, @function
_Z3barv.avx:
.LFB4:
        .cfi_startproc
        movl    $8192, %eax
        ret
        .cfi_endproc
.LFE4:
        .size   _Z3barv.avx, .-_Z3barv.avx
        .ident  "GCC: (GNU) 10.1.0"
        .section        .note.GNU-stack,"",@progbits



Triggering the bug PR95778 with

__attribute__ ((flatten,target ("default")))
static unsigned foo(const char *buf, unsigned size) {
  return 1;
}

__attribute__ ((flatten,target ("avx")))
static unsigned foo(const char *buf, unsigned size) {
  return 2;
}

__attribute__ ((flatten,target ("avx512f")))
static unsigned foo(const char *buf, unsigned size) {
  return 3;
}

__attribute__ ((target ("default")))
unsigned bar() {
  char buf[4096];
  unsigned acc = 0;
  for (int i = 0; i < sizeof(buf); i++) {
    acc += foo(&buf[i], 1);
  }
  return acc;
}

__attribute__ ((target ("avx")))
unsigned bar() {
  char buf[4096];
  unsigned acc = 0;
  for (int i = 0; i < sizeof(buf); i++) {
    acc += foo(&buf[i], 1);
  }
  return acc;
}

produces the correct code.


More information about the Gcc-bugs mailing list