This is the mail archive of the gcc-patches@gcc.gnu.org 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: [PATCH] Fold (a > 0 ? 1.0 : -1.0) into copysign (1.0, a) and a * copysign (1.0, a) into abs(a)


On Tue, Jun 27, 2017 at 7:56 AM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On June 27, 2017 4:52:28 PM GMT+02:00, Tamar Christina <Tamar.Christina@arm.com> wrote:
>>> >> +(for cmp (gt ge lt le)
>>> >> +     outp (convert convert negate negate)
>>> >> +     outn (negate negate convert convert)
>>> >> + /* Transform (X > 0.0 ? 1.0 : -1.0) into copysign(1, X). */
>>> >> + /* Transform (X >= 0.0 ? 1.0 : -1.0) into copysign(1, X). */
>>> >> + /* Transform (X < 0.0 ? 1.0 : -1.0) into copysign(1,-X). */
>>> >> + /* Transform (X <= 0.0 ? 1.0 : -1.0) into copysign(1,-X). */
>>> >> +(simplify
>>> >> +  (cond (cmp @0 real_zerop) real_onep real_minus_onep)
>>> >> +  (if (!HONOR_NANS (type) && !HONOR_SIGNED_ZEROS (type)
>>> >> +       && types_match (type, TREE_TYPE (@0)))
>>> >> +   (switch
>>> >> +    (if (types_match (type, float_type_node))
>>> >> +     (BUILT_IN_COPYSIGNF { build_one_cst (type); } (outp @0)))
>>> >> +    (if (types_match (type, double_type_node))
>>> >> +     (BUILT_IN_COPYSIGN { build_one_cst (type); } (outp @0)))
>>> >> +    (if (types_match (type, long_double_type_node))
>>> >> +     (BUILT_IN_COPYSIGNL { build_one_cst (type); } (outp @0))))))
>>> >>
>>
>>Hi,
>>
>>Out of curiosity is there any reason why this transformation can't be
>>more general?
>>
>>e.g. Transform (X > 0.0 ? CST : -CST) into copysign(CST, X).
>
> That's also possible, yes.

I will be implementing that latter today.

Thanks,
Andrew Pinski

>
>>we would at the very least avoid a csel or a branch then.
>>
>>Regards,
>>Tamar
>


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