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