* [PATCH] gfortran: Improve translation of POPPAR intrinsic
@ 2020-06-14 22:39 Roger Sayle
2021-11-21 0:22 ` Bernhard Reutner-Fischer
0 siblings, 1 reply; 4+ messages in thread
From: Roger Sayle @ 2020-06-14 22:39 UTC (permalink / raw)
To: gcc-patches, fortran
[-- Attachment #1: Type: text/plain, Size: 1251 bytes --]
The following patch to gfortran's trans-instrinsic.c tweaks the generic that
is produced
for popcnt on integer(kind=16). Currently, the double word popcnt is
implemented as
parityll(hipart(x))^parityll(lopart(x)), but with this patch this is now
translated as
parityll(hipart(x)^lopart(x)). This will be just an aesthetic change once
my tree-level
parity optimization patch of 12th June is reviewed and accepted, but
generating the
more efficient form initially, avoids a tiny bit of garbage collection when
the middle-end
cleans this up into its preferred form. The semantics/correctness of this
change are tested by the run-time tests in gfortran.dg/popcnt_poppar_2.F90
This patch has been tested with "make bootstrap" and "make -k check" on
x86_64-pc-linux-gnu with no regressions. If approved, I'd very much
appreciate it if the (gfortran) reviewer could commit this change for me.
2020-06-14 Roger Sayle <roger@bextmovesoftware.com>
* trans-intrinsic.c (gfc_conv_intrinsic_popcnt_poppar): Translate
poppar(kind=16) as parityll(hipart(x)^lopart(x)) instead of
parityll(hipart(x))^parityll(lopart(x)).
Thanks in advance,
Roger
--
Roger Sayle
NextMove Software
Cambridge, UK
[-- Attachment #2: patchb.txt --]
[-- Type: text/plain, Size: 2518 bytes --]
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index fd88099..363874e 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -7153,35 +7153,39 @@ gfc_conv_intrinsic_popcnt_poppar (gfc_se * se, gfc_expr *expr, int parity)
as 'long long'. */
gcc_assert (argsize == 2 * LONG_LONG_TYPE_SIZE);
- func = builtin_decl_explicit (parity
- ? BUILT_IN_PARITYLL
- : BUILT_IN_POPCOUNTLL);
-
/* Convert it to an integer, and store into a variable. */
utype = gfc_build_uint_type (argsize);
arg = fold_convert (utype, arg);
arg = gfc_evaluate_now (arg, &se->pre);
-
- /* Call the builtin twice. */
- call1 = build_call_expr_loc (input_location, func, 1,
- fold_convert (long_long_unsigned_type_node,
- arg));
-
- arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg,
- build_int_cst (utype, LONG_LONG_TYPE_SIZE));
- call2 = build_call_expr_loc (input_location, func, 1,
- fold_convert (long_long_unsigned_type_node,
- arg2));
+ arg_type = long_long_unsigned_type_node;
/* Combine the results. */
if (parity)
- se->expr = fold_build2_loc (input_location, BIT_XOR_EXPR, result_type,
- call1, call2);
+ {
+ /* Construct parityll (LOPART (arg) ^ HIPART (arg)) */
+ arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg,
+ build_int_cst (utype, LONG_LONG_TYPE_SIZE));
+ arg = fold_build2_loc (input_location, BIT_XOR_EXPR, arg_type,
+ fold_convert (arg_type, arg),
+ fold_convert (arg_type, arg2));
+ func = builtin_decl_explicit (BUILT_IN_PARITYLL);
+ argsize = LONG_LONG_TYPE_SIZE;
+ }
else
- se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type,
- call1, call2);
-
- return;
+ {
+ func = builtin_decl_explicit (BUILT_IN_POPCOUNTLL);
+
+ /* Call the builtin twice. */
+ call1 = build_call_expr_loc (input_location, func, 1,
+ fold_convert (arg_type, arg));
+ arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg,
+ build_int_cst (utype, LONG_LONG_TYPE_SIZE));
+ call2 = build_call_expr_loc (input_location, func, 1,
+ fold_convert (arg_type, arg2));
+ se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type,
+ call1, call2);
+ return;
+ }
}
/* Convert the actual argument twice: first, to the unsigned type of the
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gfortran: Improve translation of POPPAR intrinsic
2020-06-14 22:39 [PATCH] gfortran: Improve translation of POPPAR intrinsic Roger Sayle
@ 2021-11-21 0:22 ` Bernhard Reutner-Fischer
2021-11-21 18:59 ` Harald Anlauf
0 siblings, 1 reply; 4+ messages in thread
From: Bernhard Reutner-Fischer @ 2021-11-21 0:22 UTC (permalink / raw)
To: fortran; +Cc: rep.dot.nop, Roger Sayle, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]
Roger pinged this on gcc-patches some time ago fwiw.
[The commit-hooks will likely fix or ignore s/bext/next/ in his
mail-addr]
On Sun, 14 Jun 2020 23:39:32 +0100
"Roger Sayle" <roger@nextmovesoftware.com> wrote:
>
>
> The following patch to gfortran's trans-instrinsic.c tweaks the generic that
> is produced
>
> for popcnt on integer(kind=16). Currently, the double word popcnt is
> implemented as
>
> parityll(hipart(x))^parityll(lopart(x)), but with this patch this is now
> translated as
>
> parityll(hipart(x)^lopart(x)). This will be just an aesthetic change once
> my tree-level
>
> parity optimization patch of 12th June is reviewed and accepted, but
> generating the
>
> more efficient form initially, avoids a tiny bit of garbage collection when
> the middle-end
>
> cleans this up into its preferred form. The semantics/correctness of this
>
> change are tested by the run-time tests in gfortran.dg/popcnt_poppar_2.F90
>
>
>
> This patch has been tested with "make bootstrap" and "make -k check" on
>
> x86_64-pc-linux-gnu with no regressions. If approved, I'd very much
>
> appreciate it if the (gfortran) reviewer could commit this change for me.
>
>
>
> 2020-06-14 Roger Sayle <roger@bextmovesoftware.com>
>
>
>
> * trans-intrinsic.c (gfc_conv_intrinsic_popcnt_poppar): Translate
>
> poppar(kind=16) as parityll(hipart(x)^lopart(x)) instead of
>
> parityll(hipart(x))^parityll(lopart(x)).
>
>
>
>
>
> Thanks in advance,
>
> Roger
>
> --
>
> Roger Sayle
>
> NextMove Software
>
> Cambridge, UK
>
>
>
[-- Attachment #2: patchb.txt --]
[-- Type: text/plain, Size: 2453 bytes --]
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index fd88099..363874e 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -7153,35 +7153,39 @@ gfc_conv_intrinsic_popcnt_poppar (gfc_se * se, gfc_expr *expr, int parity)
as 'long long'. */
gcc_assert (argsize == 2 * LONG_LONG_TYPE_SIZE);
- func = builtin_decl_explicit (parity
- ? BUILT_IN_PARITYLL
- : BUILT_IN_POPCOUNTLL);
-
/* Convert it to an integer, and store into a variable. */
utype = gfc_build_uint_type (argsize);
arg = fold_convert (utype, arg);
arg = gfc_evaluate_now (arg, &se->pre);
-
- /* Call the builtin twice. */
- call1 = build_call_expr_loc (input_location, func, 1,
- fold_convert (long_long_unsigned_type_node,
- arg));
-
- arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg,
- build_int_cst (utype, LONG_LONG_TYPE_SIZE));
- call2 = build_call_expr_loc (input_location, func, 1,
- fold_convert (long_long_unsigned_type_node,
- arg2));
+ arg_type = long_long_unsigned_type_node;
/* Combine the results. */
if (parity)
- se->expr = fold_build2_loc (input_location, BIT_XOR_EXPR, result_type,
- call1, call2);
+ {
+ /* Construct parityll (LOPART (arg) ^ HIPART (arg)) */
+ arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg,
+ build_int_cst (utype, LONG_LONG_TYPE_SIZE));
+ arg = fold_build2_loc (input_location, BIT_XOR_EXPR, arg_type,
+ fold_convert (arg_type, arg),
+ fold_convert (arg_type, arg2));
+ func = builtin_decl_explicit (BUILT_IN_PARITYLL);
+ argsize = LONG_LONG_TYPE_SIZE;
+ }
else
- se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type,
- call1, call2);
-
- return;
+ {
+ func = builtin_decl_explicit (BUILT_IN_POPCOUNTLL);
+
+ /* Call the builtin twice. */
+ call1 = build_call_expr_loc (input_location, func, 1,
+ fold_convert (arg_type, arg));
+ arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg,
+ build_int_cst (utype, LONG_LONG_TYPE_SIZE));
+ call2 = build_call_expr_loc (input_location, func, 1,
+ fold_convert (arg_type, arg2));
+ se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type,
+ call1, call2);
+ return;
+ }
}
/* Convert the actual argument twice: first, to the unsigned type of the
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gfortran: Improve translation of POPPAR intrinsic
2021-11-21 0:22 ` Bernhard Reutner-Fischer
@ 2021-11-21 18:59 ` Harald Anlauf
2021-11-21 21:49 ` Bernhard Reutner-Fischer
0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2021-11-21 18:59 UTC (permalink / raw)
To: Bernhard Reutner-Fischer, fortran; +Cc: gcc-patches, Roger Sayle
Let's have a look at the tree-dump of the existing testcase:
integer(kind=4) runtime_poppar (integer(kind=16) & restrict i)
{
integer(kind=4) res;
{
uint128_t D.4221;
D.4221 = (uint128_t) *i;
res = __builtin_parityll ((unsigned long) D.4221 ^ (unsigned long)
(D.4221 >> 64));
}
return res;
}
My understanding is there is actually nothing left to do,
as the middle-end(?) already handles this.
Am 21.11.21 um 01:22 schrieb Bernhard Reutner-Fischer via Fortran:
> Roger pinged this on gcc-patches some time ago fwiw.
> [The commit-hooks will likely fix or ignore s/bext/next/ in his
> mail-addr]
>
>
> On Sun, 14 Jun 2020 23:39:32 +0100
> "Roger Sayle" <roger@nextmovesoftware.com> wrote:
>
>>
>>
>> The following patch to gfortran's trans-instrinsic.c tweaks the generic that
>> is produced
>>
>> for popcnt on integer(kind=16). Currently, the double word popcnt is
>> implemented as
>>
>> parityll(hipart(x))^parityll(lopart(x)), but with this patch this is now
>> translated as
>>
>> parityll(hipart(x)^lopart(x)). This will be just an aesthetic change once
>> my tree-level
>>
>> parity optimization patch of 12th June is reviewed and accepted, but
>> generating the
>>
>> more efficient form initially, avoids a tiny bit of garbage collection when
>> the middle-end
>>
>> cleans this up into its preferred form. The semantics/correctness of this
>>
>> change are tested by the run-time tests in gfortran.dg/popcnt_poppar_2.F90
>>
>>
>>
>> This patch has been tested with "make bootstrap" and "make -k check" on
>>
>> x86_64-pc-linux-gnu with no regressions. If approved, I'd very much
>>
>> appreciate it if the (gfortran) reviewer could commit this change for me.
>>
>>
>>
>> 2020-06-14 Roger Sayle <roger@bextmovesoftware.com>
>>
>>
>>
>> * trans-intrinsic.c (gfc_conv_intrinsic_popcnt_poppar): Translate
>>
>> poppar(kind=16) as parityll(hipart(x)^lopart(x)) instead of
>>
>> parityll(hipart(x))^parityll(lopart(x)).
>>
>>
>>
>>
>>
>> Thanks in advance,
>>
>> Roger
>>
>> --
>>
>> Roger Sayle
>>
>> NextMove Software
>>
>> Cambridge, UK
>>
>>
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gfortran: Improve translation of POPPAR intrinsic
2021-11-21 18:59 ` Harald Anlauf
@ 2021-11-21 21:49 ` Bernhard Reutner-Fischer
0 siblings, 0 replies; 4+ messages in thread
From: Bernhard Reutner-Fischer @ 2021-11-21 21:49 UTC (permalink / raw)
To: Harald Anlauf; +Cc: rep.dot.nop, fortran, gcc-patches, Roger Sayle
On Sun, 21 Nov 2021 19:59:35 +0100
Harald Anlauf <anlauf@gmx.de> wrote:
> Let's have a look at the tree-dump of the existing testcase:
>
> integer(kind=4) runtime_poppar (integer(kind=16) & restrict i)
> {
> integer(kind=4) res;
>
> {
> uint128_t D.4221;
>
> D.4221 = (uint128_t) *i;
> res = __builtin_parityll ((unsigned long) D.4221 ^ (unsigned long)
> (D.4221 >> 64));
> }
> return res;
> }
>
> My understanding is there is actually nothing left to do,
> as the middle-end(?) already handles this.
Well the whole point was ...
>
> Am 21.11.21 um 01:22 schrieb Bernhard Reutner-Fischer via Fortran:
> > Roger pinged this on gcc-patches some time ago fwiw.
> > [The commit-hooks will likely fix or ignore s/bext/next/ in his
> > mail-addr]
> >
> >
> > On Sun, 14 Jun 2020 23:39:32 +0100
> > "Roger Sayle" <roger@nextmovesoftware.com> wrote:
> >
> >>
> >>
> >> The following patch to gfortran's trans-instrinsic.c tweaks the generic that
> >> is produced
> >>
> >> for popcnt on integer(kind=16). Currently, the double word popcnt is
> >> implemented as
> >>
> >> parityll(hipart(x))^parityll(lopart(x)), but with this patch this is now
> >> translated as
> >>
> >> parityll(hipart(x)^lopart(x)). This will be just an aesthetic change once
> >> my tree-level
> >>
> >> parity optimization patch of 12th June is reviewed and accepted, but
> >> generating the
> >>
> >> more efficient form initially, avoids a tiny bit of garbage collection when
> >> the middle-end
> >>
> >> cleans this up into its preferred form. The semantics/correctness of this
... the above, i.e. create better code in the first place.
thanks,
> >>
> >> change are tested by the run-time tests in gfortran.dg/popcnt_poppar_2.F90
> >>
> >>
> >>
> >> This patch has been tested with "make bootstrap" and "make -k check" on
> >>
> >> x86_64-pc-linux-gnu with no regressions. If approved, I'd very much
> >>
> >> appreciate it if the (gfortran) reviewer could commit this change for me.
> >>
> >>
> >>
> >> 2020-06-14 Roger Sayle <roger@bextmovesoftware.com>
> >>
> >>
> >>
> >> * trans-intrinsic.c (gfc_conv_intrinsic_popcnt_poppar): Translate
> >>
> >> poppar(kind=16) as parityll(hipart(x)^lopart(x)) instead of
> >>
> >> parityll(hipart(x))^parityll(lopart(x)).
> >>
> >>
> >>
> >>
> >>
> >> Thanks in advance,
> >>
> >> Roger
> >>
> >> --
> >>
> >> Roger Sayle
> >>
> >> NextMove Software
> >>
> >> Cambridge, UK
> >>
> >>
> >>
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-21 21:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-14 22:39 [PATCH] gfortran: Improve translation of POPPAR intrinsic Roger Sayle
2021-11-21 0:22 ` Bernhard Reutner-Fischer
2021-11-21 18:59 ` Harald Anlauf
2021-11-21 21:49 ` Bernhard Reutner-Fischer
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).