Set __FLT_EVAL_METHOD__/__FLT_EVAL_METHOD_TS_18661_3__ to FLT_EVAL_METHOD_PROMOTE_TO_FLOAT when FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.

Message ID 20211227014851.21972-1-hongtao.liu@intel.com
State New
Headers
Series Set __FLT_EVAL_METHOD__/__FLT_EVAL_METHOD_TS_18661_3__ to FLT_EVAL_METHOD_PROMOTE_TO_FLOAT when FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16. |

Commit Message

Liu, Hongtao Dec. 27, 2021, 1:48 a.m. UTC
  Since FLT_EVAL_METHOD only accepts negative value, 0, 1 or 2.

gcc/c-family/ChangeLog:

	PR c/100854
	* c-common.c (excess_precision_mode_join): Return
	FLT_EVAL_METHOD_PROMOTE_TO_FLOAT when both x and y are
	FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.
---
 gcc/c-family/c-common.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Joseph Myers Dec. 30, 2021, 11:11 p.m. UTC | #1
On Mon, 27 Dec 2021, liuhongt via Gcc-patches wrote:

> Since FLT_EVAL_METHOD only accepts negative value, 0, 1 or 2.
> 
> gcc/c-family/ChangeLog:
> 
> 	PR c/100854
> 	* c-common.c (excess_precision_mode_join): Return
> 	FLT_EVAL_METHOD_PROMOTE_TO_FLOAT when both x and y are
> 	FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.

This patch is incorrect.  The function excess_precision_mode_join 
correctly implements the semantics defined in the comment above the 
function, resulting in the correct value of FLT_EVAL_METHOD being defined 
in <float.h> (taking proper account of whether C23 values for 
FLT_EVAL_METHOD are permitted or not, including the 
-fpermitted-flt-eval-methods= option).
  

Patch

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a25d59fa77b..4dab4d60773 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -8842,6 +8842,10 @@  excess_precision_mode_join (enum flt_eval_method x,
       || y == FLT_EVAL_METHOD_UNPREDICTABLE)
     return FLT_EVAL_METHOD_UNPREDICTABLE;
 
+  /* FLT_EVAL_METHOD only accepts negative values, 0, 1 or 2, but
+     FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 is 16.  */
+    if (x == y && x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
+      return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
   /* GCC only supports one interchange type right now, _Float16.  If
      we're evaluating _Float16 in 16-bit precision, then flt_eval_method
      will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */