public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing
@ 2024-05-02 10:17 mat.mcroci at gmail dot com
  2024-05-02 11:42 ` [Bug c++/114921] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mat.mcroci at gmail dot com @ 2024-05-02 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

* [Bug c++/114921] Optimization flags cause _Float16 to __bf16 casting to do nothing
  2024-05-02 10:17 [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing mat.mcroci at gmail dot com
@ 2024-05-02 11:42 ` rguenth at gcc dot gnu.org
  2024-05-03  6:20 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-02 11:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
           Keywords|                            |wrong-code
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-05-02
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  We vectorize the loop to

  <bb 2> [local count: 119292720]:
  vect_temp_9.6_3 = MEM <vector(4) _Float16> [(_Float16 *)f_7(D)];
  vect__4.7_9 = VIEW_CONVERT_EXPR<vector(4) __bf16>(vect_temp_9.6_3);
  MEM <vector(4) __bf16> [(__bf16 *)f_7(D)] = vect__4.7_9;
  vect_temp_9.6_17 = MEM <vector(4) _Float16> [(_Float16 *)f_7(D) + 8B];
  vect__4.7_18 = VIEW_CONVERT_EXPR<vector(4) __bf16>(vect_temp_9.6_17);
  MEM <vector(4) __bf16> [(__bf16 *)f_7(D) + 8B] = vect__4.7_18;

likely because the vectorizer thinks this is a noop conversion, it handles
it via vectorizable_assignment.

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

* [Bug c++/114921] Optimization flags cause _Float16 to __bf16 casting to do nothing
  2024-05-02 10:17 [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing mat.mcroci at gmail dot com
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-03  6:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:87e35da16df74cd1c4729a55d94e7bc592487f48

commit r15-124-g87e35da16df74cd1c4729a55d94e7bc592487f48
Author: Richard Biener <rguenther@suse.de>
Date:   Thu May 2 13:55:15 2024 +0200

    tree-optimization/114921 - _Float16 -> __bf16 isn't noop

    The vectorizer handles a _Float16 to __bf16 conversion through
    vectorizable_assignment, thinking it's a noop.  The following
    fixes this by requiring the same vector component mode when
    checking for CONVERT_EXPR_CODE_P, being stricter than for
    VIEW_CONVERT_EXPR.

            PR tree-optimization/114921
            * tree-vect-stmts.cc (vectorizable_assignment): Require
            same vector component modes for input and output for
            CONVERT_EXPR_CODE_P.

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

* [Bug tree-optimization/114921] Optimization flags cause _Float16 to __bf16 casting to do nothing
  2024-05-02 10:17 [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing mat.mcroci at gmail dot com
  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 ` 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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-03  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:fa7e05d90bb672b58424ddbe37a05a0fd0949b35

commit r14-10159-gfa7e05d90bb672b58424ddbe37a05a0fd0949b35
Author: Richard Biener <rguenther@suse.de>
Date:   Thu May 2 13:55:15 2024 +0200

    tree-optimization/114921 - _Float16 -> __bf16 isn't noop

    The vectorizer handles a _Float16 to __bf16 conversion through
    vectorizable_assignment, thinking it's a noop.  The following
    fixes this by requiring the same vector component mode when
    checking for CONVERT_EXPR_CODE_P, being stricter than for
    VIEW_CONVERT_EXPR.

            PR tree-optimization/114921
            * tree-vect-stmts.cc (vectorizable_assignment): Require
            same vector component modes for input and output for
            CONVERT_EXPR_CODE_P.

    (cherry picked from commit 87e35da16df74cd1c4729a55d94e7bc592487f48)

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

* [Bug tree-optimization/114921] Optimization flags cause _Float16 to __bf16 casting to do nothing
  2024-05-02 10:17 [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing mat.mcroci at gmail dot com
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-07  6:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:d0d6dcc019cd32eebf85d625f56e0f7573938319

commit r15-223-gd0d6dcc019cd32eebf85d625f56e0f7573938319
Author: Richard Biener <rguenther@suse.de>
Date:   Mon May 6 12:03:09 2024 +0200

    tree-optimization/114921 - _Float16 -> __bf16 isn't noop fixup

    The following further strengthens the check which convert expressions
    we allow to vectorize as simple copy by resorting to
    tree_nop_conversion_p on the vector components.

            PR tree-optimization/114921
            * tree-vect-stmts.cc (vectorizable_assignment): Use
            tree_nop_conversion_p to identify converts we can vectorize
            with a simple assignment.

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

* [Bug tree-optimization/114921] Optimization flags cause _Float16 to __bf16 casting to do nothing
  2024-05-02 10:17 [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing mat.mcroci at gmail dot com
                   ` (3 preceding siblings ...)
  2024-05-07  6:26 ` cvs-commit at gcc dot gnu.org
@ 2024-05-29  6:29 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-29  6:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:9e971c671ded9647beb0a1c5b9430b4e64060862

commit r14-10255-g9e971c671ded9647beb0a1c5b9430b4e64060862
Author: Richard Biener <rguenther@suse.de>
Date:   Mon May 6 12:03:09 2024 +0200

    tree-optimization/114921 - _Float16 -> __bf16 isn't noop fixup

    The following further strengthens the check which convert expressions
    we allow to vectorize as simple copy by resorting to
    tree_nop_conversion_p on the vector components.

            PR tree-optimization/114921
            * tree-vect-stmts.cc (vectorizable_assignment): Use
            tree_nop_conversion_p to identify converts we can vectorize
            with a simple assignment.

    (cherry picked from commit d0d6dcc019cd32eebf85d625f56e0f7573938319)

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

end of thread, other threads:[~2024-05-29  6:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 10:17 [Bug c++/114921] New: Optimization flags cause _Float16 to __bf16 casting to do nothing mat.mcroci at gmail dot com
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

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).