From: Kewen Lin Date: Wed, 21 Dec 2022 03:04:54 +0000 (-0600) Subject: fold-const: Treat fp conversion to a type with same mode as copy X-Git-Tag: basepoints/gcc-14~2392 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94cf7a2d95bf6db873cdcc4085a697ad40057957;p=thirdparty%2Fgcc.git fold-const: Treat fp conversion to a type with same mode as copy In function fold_convert_const_real_from_real, when the modes of two types involved in fp conversion are the same, we can simply take it as copy, rebuild with the exactly same TREE_REAL_CST and the target type. It is more efficient and helps to avoid possible unexpected signalling bit clearing in [1]. [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608533.html gcc/ChangeLog: * fold-const.cc (fold_convert_const_real_from_real): Treat floating point conversion to a type with same mode as copy instead of normal convertFormat. --- diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 00e2af0680cf..d4ee3b309834 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -2178,6 +2178,15 @@ fold_convert_const_real_from_real (tree type, const_tree arg1) REAL_VALUE_TYPE value; tree t; + /* If the underlying modes are the same, simply treat it as + copy and rebuild with TREE_REAL_CST information and the + given type. */ + if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (arg1))) + { + t = build_real (type, TREE_REAL_CST (arg1)); + return t; + } + /* Don't perform the operation if flag_signaling_nans is on and the operand is a signaling NaN. */ if (HONOR_SNANS (arg1)