From: Andrew Pinski <pinskia@gmail.com>
To: Tamar Christina <Tamar.Christina@arm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, nd <nd@arm.com>,
"law@redhat.com" <law@redhat.com>, "ian@airs.com" <ian@airs.com>,
"rguenther@suse.de" <rguenther@suse.de>
Subject: Re: [GCC][PATCH][mid-end] Optimize x * copysign (1.0, y) [Patch (1/2)]
Date: Mon, 26 Jun 2017 02:09:00 -0000 [thread overview]
Message-ID: <CA+=Sn1=FB_GDC9LeOJMtFu+7x9+o5wUbMR20phaaof9G+dhQAA@mail.gmail.com> (raw)
In-Reply-To: <CA+=Sn1kGGn7RPTtzWbw42Z9PaizBMxSqURDwsenZucn8mBrFkQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3289 bytes --]
On Sat, Jun 24, 2017 at 4:53 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Mon, Jun 12, 2017 at 12:56 AM, Tamar Christina
> <Tamar.Christina@arm.com> wrote:
>> Hi All,
>>
>> this patch implements a optimization rewriting
>>
>> x * copysign (1.0, y) and
>> x * copysign (-1.0, y)
>
>
> This reminds me:
> copysign(-1.0, y) can be just optimized to:
> copysign(1.0, y)
>
> I did that in my patch here:
> https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01860.html
I updated the patch to handle all constants and not just -1.0.
>
> This should allow you to reduce the number of patterns needed to match here.
> Note I still think we could do this in expand without a new
> builtin/internal function.
> I might go and code that up soonish.
Also something like attached (NOTE this is NOT a full patch and needs
the xorsign optabs part of your patch) should work for the expand side
rather than creating a new builtin. There still needs to handling of
the vector based copysign. But you should get the general idea. I
would like to see more of these special expand patterns really.
NOTE you can remove the target hook part and just check if xorsign
optab is there. I don't know if that is what we want to do if not
allow for generic expanding of this.
Thanks,
Andrew Pinski
>
> Thanks,
> Andrew
>
>>
>> to:
>>
>> x ^ (y & (1 << sign_bit_position))
>>
>> This is done by creating a special builtin during matching and generate the
>> appropriate instructions during expand. This new builtin is called XORSIGN.
>>
>> The expansion of xorsign depends on if the backend has an appropriate optab
>> available. If this is not the case then we use a modified version of the existing
>> copysign which does not take the abs value of the first argument as a fall back.
>>
>> This patch is a revival of a previous patch
>> https://gcc.gnu.org/ml/gcc-patches/2015-10/msg00069.html
>>
>> Bootstrapped on both aarch64-none-linux-gnu and x86_64 with no issues.
>> Regression done on aarch64-none-linux-gnu and no regressions.
>>
>> Ok for trunk?
>>
>> gcc/
>> 2017-06-07 Tamar Christina <tamar.christina@arm.com>
>>
>> * builtins.def (BUILT_IN_XORSIGN, BUILT_IN_XORSIGNF): New.
>> (BUILT_IN_XORSIGNL, BUILT_IN_XORSIGN_FLOAT_NX): Likewise.
>> * match.pd (mult (COPYSIGN:s real_onep @0) @1): New simplifier.
>> (mult (COPYSIGN:s real_mus_onep @0) @1): Likewise.
>> (copysigns @0 (negate @1)): Likewise.
>> * builtins.c (expand_builtin_copysign): Promoted local to argument.
>> (expand_builtin): Added CASE_FLT_FN_FLOATN_NX (BUILT_IN_XORSIGN) and
>> CASE_FLT_FN (BUILT_IN_XORSIGN).
>> (BUILT_IN_COPYSIGN): Updated function call.
>> * optabs.h (expand_copysign): New bool.
>> (expand_xorsign): New.
>> * optabs.def (xorsign_optab): New.
>> * optabs.c (expand_copysign): New parameter.
>> * fortran/f95-lang.c (xorsignl, xorsign, xorsignf): New.
>> * fortran/mathbuiltins.def (XORSIGN): New.
>>
>> gcc/testsuite/
>> 2017-06-07 Tamar Christina <tamar.christina@arm.com>
>>
>> * gcc.dg/tree-ssa/xorsign.c: New.
>> * gcc.dg/xorsign_exec.c: New.
>> * gcc.dg/vec-xorsign_exec.c: New.
>> * gcc.dg/tree-ssa/reassoc-39.c (f2, f3): Updated constant to 2.
[-- Attachment #2: startmult-copysign.diff.txt --]
[-- Type: text/plain, Size: 2493 bytes --]
Index: gcc/expr.c
===================================================================
--- gcc/expr.c (revision 249619)
+++ gcc/expr.c (working copy)
@@ -8182,6 +8182,59 @@
return NULL_RTX;
}
+static bool
+is_copysign_call_with_1 (gimple *call)
+{
+ if (!is_gimple_call (call))
+ return false;
+
+ if (gimple_call_builtin_p (call, BUILT_IN_NORMAL))
+ {
+ gcall *c = as_a<gcall*> (call);
+ tree decl = gimple_call_fndecl (call);
+ switch (DECL_FUNCTION_CODE (decl))
+ {
+ CASE_FLT_FN (BUILT_IN_COPYSIGN):
+ CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
+ return real_one_p (gimple_call_arg (c, 0));
+ default:
+ return false;
+ }
+ }
+}
+
+static rtx
+maybe_expand_mult_copysign (tree treeop0, tree treeop1, rtx target)
+{
+ tree type = TREE_TYPE (treeop0);
+ rtx op0, op1;
+
+ if (!SCALAR_FLOAT_TYPE_P (type)
+ && VECTOR_FLOAT_TYPE_P (type))
+ return NULL;
+
+ if (HONOR_SNANS (type))
+ return NULL;
+
+ if (!targetm.expand_mult_copysign_xor ())
+ return NULL;
+
+ if (TREE_CODE (treeop0) == SSA_NAME)
+ {
+ gimple *call0 = SSA_NAME_DEF_STMT (treeop0);
+ if (is_copysign_call_with_1 (call0))
+ {
+ gcall *c = as_a<gcall*> (call0);
+ treeop0 = gimple_call_arg (c, 1);
+ expand_operands (treeop1, treeop0, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
+ return expand_copysign (op0, op1, target, true);
+ }
+ }
+
+ return NULL;
+}
+
+
rtx
expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
enum expand_modifier modifier)
@@ -8791,6 +8844,10 @@
if (modifier == EXPAND_STACK_PARM)
target = 0;
+ temp = maybe_expand_mult_copysign (treeop0, treeop1);
+ if (temp)
+ return temp;
+
expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
Index: gcc/target.def
===================================================================
--- gcc/target.def (revision 249619)
+++ gcc/target.def (working copy)
@@ -2640,6 +2640,13 @@
default_have_conditional_execution)
DEFHOOK
+(expand_mult_copysign_xor,
+ "This target hook returns true if the target wants to use xor's\n
+to expand x * copysign (1., y) as x ^ (y & (1 << sign_bit_position)).\n"
+ bool, (void),
+ hook_bool_void_false)
+
+DEFHOOK
(gen_ccmp_first,
"This function prepares to emit a comparison insn for the first compare in a\n\
sequence of conditional comparisions. It returns an appropriate comparison\n\
next prev parent reply other threads:[~2017-06-26 2:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-12 7:56 Tamar Christina
2017-06-12 9:10 ` Richard Biener
2017-06-12 16:27 ` Richard Sandiford
2017-06-13 10:22 ` Tamar Christina
2017-06-13 10:17 ` Tamar Christina
2017-06-12 16:52 ` Joseph Myers
2017-06-12 19:50 ` Michael Meissner
2017-06-13 10:14 ` Tamar Christina
2017-06-24 23:53 ` Andrew Pinski
2017-06-26 2:09 ` Andrew Pinski [this message]
2017-06-26 8:46 ` Tamar Christina
2017-06-26 7:26 ` Richard Biener
2017-07-09 23:21 ` Andrew Pinski
2017-07-10 15:47 ` Tamar Christina
2017-07-18 8:05 ` Tamar Christina
2017-07-18 8:38 ` Richard Biener
2017-07-18 9:22 ` Tamar Christina
2017-07-18 10:19 ` Richard Biener
2017-07-18 11:00 ` Tamar Christina
2017-07-18 11:19 ` Richard Biener
2017-07-18 11:24 ` Tamar Christina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+=Sn1=FB_GDC9LeOJMtFu+7x9+o5wUbMR20phaaof9G+dhQAA@mail.gmail.com' \
--to=pinskia@gmail.com \
--cc=Tamar.Christina@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ian@airs.com \
--cc=law@redhat.com \
--cc=nd@arm.com \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).