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

