https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22326

luoxhu at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |luoxhu at gcc dot gnu.org,
                   |                            |pinskia at gcc dot gnu.org,
                   |                            |segher at kernel dot 
crashing.org

--- Comment #4 from luoxhu at gcc dot gnu.org ---
float foo(float f, float x, float y) {
return (fabs(f)*x+y);
}

the input of fabs is float type, so use fabsf is enough here, drafted a patch
to avoid double promotion when generating gimple if fabs could be replaced by
fabsf as argument[0] is float type.


diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index ecc3d2119fa..1a2d7e624cc 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -10470,6 +10470,20 @@ c_parser_postfix_expression_after_primary (c_parser
*parser,
                  && fndecl_built_in_p (expr.value, BUILT_IN_NORMAL)
                  && vec_safe_length (exprlist) == 1)
                warn_for_abs (expr_loc, expr.value, (*exprlist)[0]);
+
+             if (fndecl_built_in_p (expr.value, BUILT_IN_NORMAL)
+                 && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_FABS)
+               {
+                 tree arg0 = (*exprlist)[0];
+                 if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr.value)))
+                       > TYPE_PRECISION (TREE_TYPE (arg0))
+                     && TYPE_MODE (TREE_TYPE (arg0)) == E_SFmode)
+                   {
+                     tree abs_fun = get_identifier ("fabsf");
+                     expr.value = build_external_ref (expr_loc, abs_fun, true,
+                                                      &expr.original_type);
+                   }
+               }
            }

          start = expr.get_start ();


.006t.gimple:

__attribute__((noinline))
foo (float f, float x, float y)
{
  float D.4347;

  _1 = ABS_EXPR <f>;
  _2 = x * _1;
  D.4347 = y + _2;
  return D.4347;
}


foo:
.LFB0:
        .cfi_startproc
        fabs 1,1
        fmadds 1,1,2,3
        blr

Reply via email to