This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PR71078] x / abs(x) -> copysign (1.0, x)

On Mon, 25 Jul 2016, Prathamesh Kulkarni wrote:

> Hi,
> The attached patch tries to fix PR71078.
> I am not sure if I have got the converts right.
> I put (convert? @0) and (convert1? (abs @1))
> to match for cases when operands's types may
> be different from outermost type like in pr71078-3.c

Types of RDIV_EXPR have to be the same so as you have a
match on @0 the converts need to be either both present
or not present.

+  (if (FLOAT_TYPE_P (type)

as you special-case several types below please use SCALAR_FLOAT_TYPE_P

+       && ! HONOR_NANS (type)
+       && ! HONOR_INFINITIES (type))
+   (switch
+    (if (type == float_type_node)
+     (BUILT_IN_COPYSIGNF { build_one_cst (type); } (convert @0)))

please use if (types_match (type, float_type_node)) instead of
pointer equality.  I _think_ you can do better here by using
IFN_COPYSIGN but possibly only so if the target supports it.
Richard - this seems to be the first pattern in need of
generating a builtin where no other was there to match the type
to - any idea how we can safely use the internal function here?
I see those do not have an expander that would fall back to
expanding the regular builtin, correct?

Please place the pattern next to

/* Optimize -A / A to -1.0 if we don't care about
   NaNs or Infinities.  */
 (rdiv:C @0 (negate @0))
 (if (FLOAT_TYPE_P (type)
      && ! HONOR_NANS (type)
      && ! HONOR_INFINITIES (type))
  { build_minus_one_cst (type); }))

where it logically belongs.


> test-case (included in patch).
> Bootstrap+test in progress on x86_64-unknown-linux-gnu.
> Thanks,
> Prathamesh

Richard Biener <>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]