https://gcc.gnu.org/g:c8a9bc5cf5d788a3bc796341f8070d073076b91b
commit r17-3843-gc8a9bc5cf5d788a3bc796341f8070d073076b91b Author: Hongyu Wang <[email protected]> Date: Fri Aug 28 14:10:01 2026 +0800 i386: Allow round for HFmode in optab hook [PR127114] The match.pd narrowing of (_Float16) round ((double) x) to a native HF round query direct_internal_fn_supported_p with OPTIMIZE_FOR_BOTH, so align the backend optab_supported_p hook like the ceil/floor/btrunc did to avoid enforced extend/truncate at vectorization. gcc/ChangeLog: PR target/127114 * config/i386/i386.cc (ix86_optab_supported_p): Return true for round_optab in HFmode. gcc/testsuite/ChangeLog: PR target/127114 * gcc.target/i386/pr127114.c: New test. Diff: --- gcc/config/i386/i386.cc | 8 +++++++- gcc/testsuite/gcc.target/i386/pr127114.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 7cfbb6dfdf8b..32d5a598c5af 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -28054,10 +28054,16 @@ ix86_optab_supported_p (int op, machine_mode mode1, machine_mode, case expm1_optab: case ldexp_optab: case scalb_optab: - case round_optab: case lround_optab: return opt_type == OPTIMIZE_FOR_SPEED; + case round_optab: + /* Inlined sequence for round may takes 2 more insns + than current -Os path. */ + if (mode1 == HFmode) + return true; + return opt_type == OPTIMIZE_FOR_SPEED; + case rint_optab: if (SSE_FLOAT_MODE_P (mode1) && TARGET_SSE_MATH diff --git a/gcc/testsuite/gcc.target/i386/pr127114.c b/gcc/testsuite/gcc.target/i386/pr127114.c new file mode 100644 index 000000000000..66f188431cfd --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr127114.c @@ -0,0 +1,14 @@ +/* PR target/127114 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -fno-trapping-math" } */ + +void +round_hf_narrow (_Float16 *__restrict a, _Float16 *__restrict b, int n) +{ + for (int i = 0; i < n; i++) + a[i] = (_Float16) __builtin_round (b[i]); +} + +/* { dg-final { scan-assembler "vrndscaleph" } } */ +/* { dg-final { scan-assembler-not "call\[ \t\]*round" } } */ +/* { dg-final { scan-assembler-not "vcvtsh2sd" } } */
