match.pd: Optimize (x & y) ^ (x | y)

Marek Polacek polacek@redhat.com
Thu Jun 11 16:58:00 GMT 2015


On Thu, Jun 11, 2015 at 06:21:11PM +0200, Marc Glisse wrote:
> On Thu, 11 Jun 2015, Marek Polacek wrote:
> 
> >>>+  (if (single_use (@2) && single_use (@3))
> >>>+   (bit_xor @0 @1)))
> >>
> >>I don't think we should use single_use here. The result is never more
> >>complicated than the original. Sure, it might increase register pressure a
> >>bit in some cases, but we have not used that as a criterion for other
> >>simplifications in match.pd yet (LLVM does though).
> >
> >I don't have a strong preference here but we surely use single_use
> >in match.pd elsewhere.
> 
> The criterion for single_use up to now has been whether we may end up with
> more operations after the transformation than before. Take:
> (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x
> 
> If (x & ~m) and (y & m) have other uses, we are going to compute them
> anyway, and the original is essentially a single bit_ior operation. After
> the transformation, we have 2 more operations. That's worse than we started
> with, so we don't do it.

Hmm, yeah.  And it was me who added that pattern ;).

So I'm going to apply the following as obvious to remove the single_uses in
my latest pattern, if testing passes.  Thanks,

2015-06-11  Marek Polacek  <polacek@redhat.com>

	* match.pd ((x & y) ^ (x | y)): Don't check for single_use.

diff --git gcc/match.pd gcc/match.pd
index 9a1317e..1ab2b1c 100644
--- gcc/match.pd
+++ gcc/match.pd
@@ -322,9 +322,8 @@ along with GCC; see the file COPYING3.  If not see
 
 /* (x & y) ^ (x | y) -> x ^ y */
 (simplify
- (bit_xor:c (bit_and@2 @0 @1) (bit_ior@3 @0 @1))
-  (if (single_use (@2) && single_use (@3))
-   (bit_xor @0 @1)))
+ (bit_xor:c (bit_and @0 @1) (bit_ior @0 @1))
+ (bit_xor @0 @1))
 
 (simplify
  (abs (negate @0))

	Marek



More information about the Gcc-patches mailing list