public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mat.mcroci at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing
Date: Thu, 02 May 2024 10:17:08 +0000	[thread overview]
Message-ID: <bug-114921-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114921
           Summary: Optimization flags cause _Float16 to __bf16 casting to
                    do nothing
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mat.mcroci at gmail dot com
  Target Milestone: ---

When compiling the following code (assuming it's in a file called test.cpp)

#include <stdlib.h>
#include <cstdint>
#include <array>
#include <iostream>

#define SIZE 8

typedef _Float16 T;
//typedef volatile float T;

void fp16tobf16(_Float16 * f) {
        __bf16 * b = reinterpret_cast<__bf16*>(f);
        for(int i=0; i<SIZE; i++){
            T temp = f[i];
            b[i] = (__bf16) temp;
        }
}

with:

g++ -c -S -O2 -std=c++23 -o test.s test.cpp

using gcc 13.2.0 compiled with binutils 2.42 using spack, the assembler does
not do any casting and simply returns. You can also check this behaviour on
godbolt. The resulting assembly code is simply

fp16tobf16(_Float16*):
        ret

When using -O1 or -O0, the assembler generates the command __extendhfbf2 which
causes a separate issue, which is related to this bug:

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

P.s. I reported this bug in binutils already, but they suggested I reported it
here instead, see

https://sourceware.org/bugzilla/show_bug.cgi?id=31685

             reply	other threads:[~2024-05-02 10:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 10:17 mat.mcroci at gmail dot com [this message]
2024-05-02 11:42 ` [Bug c++/114921] " rguenth at gcc dot gnu.org
2024-05-03  6:20 ` cvs-commit at gcc dot gnu.org
2024-05-03  7:28 ` [Bug tree-optimization/114921] " cvs-commit at gcc dot gnu.org
2024-05-07  6:26 ` cvs-commit at gcc dot gnu.org
2024-05-29  6:29 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114921-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).