public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [tree-optimization] Optimize or+and+or pattern to and+or
@ 2020-11-23  1:35 Eugene Rozenfeld
  2020-11-30 16:51 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Eugene Rozenfeld @ 2020-11-23  1:35 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 355 bytes --]

Simplify
((b | c) & a) | b
to 
(a & c) | b.

This fixes PR96679.

Tested on x86_64-pc-linux-gnu.

int f(int a, int b, int c)
{
    return ((b | c) & a) | b;
}

Code without the patch:
or     edx,esi
and    edx,edi
mov    eax,edx
or     eax,esi
ret

Code with the patch:
and    edi,edx
mov    eax,edi
or     eax,esi
ret

Eugene

[-- Attachment #2: 0001-Optimize-or-and-or-pattern-to-and-or.patch --]
[-- Type: application/octet-stream, Size: 890 bytes --]

From 326f186e084c1788c428d581aa3c1a20344ed5b4 Mon Sep 17 00:00:00 2001
From: Eugene Rozenfeld <erozen@microsoft.com>
Date: Fri, 20 Nov 2020 18:05:15 -0800
Subject: [PATCH] Optimize or+and+or pattern to and+or

Simplify ((b | c) & a) | b to (a & c) | b.
This fixes PR96679.

gcc/
* match.pd : New patterns.
---
 gcc/match.pd | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index cbb4bf0b32d..00294665c98 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1433,6 +1433,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (bitop:c (rbitop:c (bit_not @0) @1) @0)
   (bitop @0 @1)))
 
+/* ((x | y) & z) | x -> (z & y) | x */
+(simplify
+  (bit_ior:c (bit_and:cs (bit_ior:cs @0 @1) @2) @0)
+  (bit_ior (bit_and @2 @1) @0))
+
 /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
 (simplify
   (bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-30 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23  1:35 [PATCH] [tree-optimization] Optimize or+and+or pattern to and+or Eugene Rozenfeld
2020-11-30 16:51 ` 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).