diff --git a/gcc/expr.cc b/gcc/expr.cc index d4414e242cb..9f66d479445 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -355,8 +355,16 @@ convert_mode_scalar (rtx to, rtx from, int unsignedp) && REAL_MODE_FORMAT (from_mode) == &ieee_half_format)); if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode)) - /* Conversion between decimal float and binary float, same size. */ - tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab; + { + if (REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format + && REAL_MODE_FORMAT (from_mode) == &ieee_half_format) + /* libgcc implements just __trunchfbf2, not __extendhfbf2. */ + tab = trunc_optab; + else + /* Conversion between decimal float and binary float, same + size. */ + tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab; + } else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)) tab = sext_optab; else diff --git a/gcc/optabs-libfuncs.cc b/gcc/optabs-libfuncs.cc index 02e9bf6ea5a..26729910d92 100644 --- a/gcc/optabs-libfuncs.cc +++ b/gcc/optabs-libfuncs.cc @@ -589,7 +589,9 @@ gen_trunc_conv_libfunc (convert_optab tab, if (GET_MODE_CLASS (float_tmode) != GET_MODE_CLASS (float_fmode)) gen_interclass_conv_libfunc (tab, opname, float_tmode, float_fmode); - if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode)) + if (GET_MODE_PRECISION (float_fmode) <= GET_MODE_PRECISION (float_tmode) + && (REAL_MODE_FORMAT (float_tmode) != &arm_bfloat_half_format + || REAL_MODE_FORMAT (float_fmode) != &ieee_half_format)) return; if (GET_MODE_CLASS (float_tmode) == GET_MODE_CLASS (float_fmode)) diff --git a/gcc/testsuite/gcc.dg/pr114907.c b/gcc/testsuite/gcc.dg/pr114907.c new file mode 100644 index 00000000000..628746e1f8c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr114907.c @@ -0,0 +1,27 @@ +/* PR middle-end/114907 */ +/* { dg-do run } */ +/* { dg-options "" } */ +/* { dg-add-options float16 } */ +/* { dg-require-effective-target float16_runtime } */ +/* { dg-add-options bfloat16 } */ +/* { dg-require-effective-target bfloat16_runtime } */ + +__attribute__((noipa)) _Float16 +foo (__bf16 x) +{ + return (_Float16) x; +} + +__attribute__((noipa)) __bf16 +bar (_Float16 x) +{ + return (__bf16) x; +} + +int +main () +{ + if (foo (11.125bf16) != 11.125f16 + || bar (11.125f16) != 11.125bf16) + __builtin_abort (); +}