This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [PATCH] Fold (a > 0 ? 1.0 : -1.0) into copysign (1.0, a) and a * copysign (1.0, a) into abs(a)
- From: Tamar Christina <Tamar dot Christina at arm dot com>
- To: Andrew Pinski <pinskia at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: nd <nd at arm dot com>
- Date: Tue, 27 Jun 2017 14:52:28 +0000
- Subject: RE: [PATCH] Fold (a > 0 ? 1.0 : -1.0) into copysign (1.0, a) and a * copysign (1.0, a) into abs(a)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com;
- Nodisclaimer: True
- References: <CA+=Sn1m-pMkB1Vvoi3s_N0DSwLioB3T90778oSDQNOYME83txA@mail.gmail.com> <alpine.DEB.2.20.1706250909190.2070@stedding.saclay.inria.fr> <CA+=Sn1nj_TNWUCGn9V_hqF2gcPj=WbzxN565FOA02O6qFg8_cA@mail.gmail.com> <CA+=Sn1mdyqOy+6UuuTXJH6UvtdNT2AS_VLWCHU_kK3kXg+apBQ@mail.gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
> >> +(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).
we would at the very least avoid a csel or a branch then.
Regards,
Tamar