* [Patch][PR91504] Inlining misses some logical operation folding
@ 2019-08-26 8:50 kamlesh kumar
2019-08-26 12:24 ` Richard Biener
2019-09-03 20:13 ` Jeff Law
0 siblings, 2 replies; 5+ messages in thread
From: kamlesh kumar @ 2019-08-26 8:50 UTC (permalink / raw)
To: gcc-patches, rguenth
2019-08-26 Kamlesh Kumar <kamleshbhalui@gmail.com>
* gcc/match.pd: Added simplification
pattern.
* gcc.dg/tree-ssa/pr91504.c: New test.
====================
diff --git a/gcc/match.pd b/gcc/match.pd
index 93dcef9..b3734f8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -831,6 +831,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_xor:c (bit_and:cs @0 (bit_not @1)) (bit_not @0))
(bit_not (bit_and @0 @1)))
+/* (~a & b) ^ a --> (a | b) */
+(simplify
+ (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
+ (bit_ior @0 @1))
+
/* (a | b) & ~(a ^ b) --> a & b */
(simplify
(bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
new file mode 100644
index 0000000..a52dea4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+static inline unsigned deposit32(unsigned value, int start, int length,
+ unsigned fieldval)
+{
+ unsigned mask = (~0U >> (32 - length)) << start;
+ return (value & ~mask) | ((fieldval << start) & mask);
+}
+
+unsigned foo(unsigned value)
+{
+ return deposit32(value, 10, 1, 1);
+}
+
+/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch][PR91504] Inlining misses some logical operation folding
2019-08-26 8:50 [Patch][PR91504] Inlining misses some logical operation folding kamlesh kumar
@ 2019-08-26 12:24 ` Richard Biener
2019-08-26 17:15 ` Segher Boessenkool
2019-09-03 20:13 ` Jeff Law
1 sibling, 1 reply; 5+ messages in thread
From: Richard Biener @ 2019-08-26 12:24 UTC (permalink / raw)
To: kamlesh kumar; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 2138 bytes --]
On Mon, 26 Aug 2019, kamlesh kumar wrote:
> 2019-08-26 Kamlesh Kumar <kamleshbhalui@gmail.com>
>
> * gcc/match.pd: Added simplification
> pattern.
> * gcc.dg/tree-ssa/pr91504.c: New test.
> ====================
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 93dcef9..b3734f8 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -831,6 +831,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (bit_xor:c (bit_and:cs @0 (bit_not @1)) (bit_not @0))
> (bit_not (bit_and @0 @1)))
>
> +/* (~a & b) ^ a --> (a | b) */
> +(simplify
> + (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
> + (bit_ior @0 @1))
> +
Are you sure?
(~1804289383 & 846930886) ^ 1804289383 != 1804289383 | 846930886
#include <stdio.h>
#include <stdlib.h>
int main ()
{
while (1)
{
int a = random();
int b = random();
if ((~a & b) ^ a != a | b)
{
fprintf (stderr, "%d, %d\n", a, b);
abort ();
}
}
}
> /* (a | b) & ~(a ^ b) --> a & b */
> (simplify
> (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
> b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
> new file mode 100644
> index 0000000..a52dea4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
> @@ -0,0 +1,18 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-optimized-raw" } */
> +
> +static inline unsigned deposit32(unsigned value, int start, int length,
> + unsigned fieldval)
> +{
> + unsigned mask = (~0U >> (32 - length)) << start;
> + return (value & ~mask) | ((fieldval << start) & mask);
> +}
> +
> +unsigned foo(unsigned value)
> +{
> + return deposit32(value, 10, 1, 1);
> +}
> +
> +/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "bit_xor_expr" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 247165 (AG München)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch][PR91504] Inlining misses some logical operation folding
2019-08-26 12:24 ` Richard Biener
@ 2019-08-26 17:15 ` Segher Boessenkool
2019-08-27 8:33 ` Richard Biener
0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2019-08-26 17:15 UTC (permalink / raw)
To: Richard Biener; +Cc: kamlesh kumar, gcc-patches
On Mon, Aug 26, 2019 at 02:04:25PM +0200, Richard Biener wrote:
> On Mon, 26 Aug 2019, kamlesh kumar wrote:
> > +/* (~a & b) ^ a --> (a | b) */
> > +(simplify
> > + (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
> > + (bit_ior @0 @1))
> > +
>
> Are you sure?
>
> (~1804289383 & 846930886) ^ 1804289383 != 1804289383 | 846930886
Both are hex 7bfb67e7.
a|b = a|(b&~a) = a^(b&~a)
> if ((~a & b) ^ a != a | b)
!= has higher precedence than ^ and | (and &).
Segher
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch][PR91504] Inlining misses some logical operation folding
2019-08-26 17:15 ` Segher Boessenkool
@ 2019-08-27 8:33 ` Richard Biener
0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2019-08-27 8:33 UTC (permalink / raw)
To: Segher Boessenkool; +Cc: kamlesh kumar, gcc-patches
On Mon, 26 Aug 2019, Segher Boessenkool wrote:
> On Mon, Aug 26, 2019 at 02:04:25PM +0200, Richard Biener wrote:
> > On Mon, 26 Aug 2019, kamlesh kumar wrote:
> > > +/* (~a & b) ^ a --> (a | b) */
> > > +(simplify
> > > + (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
> > > + (bit_ior @0 @1))
> > > +
> >
> > Are you sure?
> >
> > (~1804289383 & 846930886) ^ 1804289383 != 1804289383 | 846930886
>
> Both are hex 7bfb67e7.
>
> a|b = a|(b&~a) = a^(b&~a)
>
> > if ((~a & b) ^ a != a | b)
>
> != has higher precedence than ^ and | (and &).
Oops. Need more coffee (and -Wall).
Patch is OK.
Thanks,
Richard.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch][PR91504] Inlining misses some logical operation folding
2019-08-26 8:50 [Patch][PR91504] Inlining misses some logical operation folding kamlesh kumar
2019-08-26 12:24 ` Richard Biener
@ 2019-09-03 20:13 ` Jeff Law
1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2019-09-03 20:13 UTC (permalink / raw)
To: kamlesh kumar, gcc-patches, rguenth
On 8/26/19 1:06 AM, kamlesh kumar wrote:
> 2019-08-26 Kamlesh Kumar <kamleshbhalui@gmail.com>
>
> * gcc/match.pd: Added simplification
> pattern.
> * gcc.dg/tree-ssa/pr91504.c: New test.
Thanks. I've installed this on the trunk.
jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-09-03 20:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26 8:50 [Patch][PR91504] Inlining misses some logical operation folding kamlesh kumar
2019-08-26 12:24 ` Richard Biener
2019-08-26 17:15 ` Segher Boessenkool
2019-08-27 8:33 ` Richard Biener
2019-09-03 20:13 ` Jeff Law
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).