public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] simplify-rtx: Generalize (and X (ior (not X) Y) -> (and X Y)
@ 2014-12-24 17:12 Segher Boessenkool
       [not found] ` <CAOckXuOAECjyUg_QWRD_5wU819Odce1NUMRHY7BymY=1YhJWtg@mail.gmail.com>
  2015-01-05 20:28 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Segher Boessenkool @ 2014-12-24 17:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: Segher Boessenkool

The existing transform

  (and X (ior (not X) Y) -> (and X Y)

has two shortcomings: it only handles identical RTX for X, i.e. registers,
not e.g. subregs of registers; and it only handles the case where the NOT
is the first arm of the IOR (it can be the second arm e.g. if the first
arm is a NOT as well).  Fix both.  This fixes gcc.dg/and-1.c on powerpc64.

Bootstrapped and tested on powerpc64-linux; okay for mainline?


Segher


2014-12-24  Segher Boessenkool  <segher@kernel.crashing.org>

gcc/
	* simplify-rtx.c (simplify_binary_operation_1): Handle more cases
	for the "(and X (ior (not X) Y) -> (and X Y)" transform.

---
 gcc/simplify-rtx.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 277288a..ae0b49d 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -2933,15 +2933,27 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode,
       /* (and X (ior (not X) Y) -> (and X Y) */
       if (GET_CODE (op1) == IOR
 	  && GET_CODE (XEXP (op1, 0)) == NOT
-	  && op0 == XEXP (XEXP (op1, 0), 0))
+	  && rtx_equal_p (op0, XEXP (XEXP (op1, 0), 0)))
        return simplify_gen_binary (AND, mode, op0, XEXP (op1, 1));
 
       /* (and (ior (not X) Y) X) -> (and X Y) */
       if (GET_CODE (op0) == IOR
 	  && GET_CODE (XEXP (op0, 0)) == NOT
-	  && op1 == XEXP (XEXP (op0, 0), 0))
+	  && rtx_equal_p (op1, XEXP (XEXP (op0, 0), 0)))
 	return simplify_gen_binary (AND, mode, op1, XEXP (op0, 1));
 
+      /* (and X (ior Y (not X)) -> (and X Y) */
+      if (GET_CODE (op1) == IOR
+	  && GET_CODE (XEXP (op1, 1)) == NOT
+	  && rtx_equal_p (op0, XEXP (XEXP (op1, 1), 0)))
+       return simplify_gen_binary (AND, mode, op0, XEXP (op1, 0));
+
+      /* (and (ior Y (not X)) X) -> (and X Y) */
+      if (GET_CODE (op0) == IOR
+	  && GET_CODE (XEXP (op0, 1)) == NOT
+	  && rtx_equal_p (op1, XEXP (XEXP (op0, 1), 0)))
+	return simplify_gen_binary (AND, mode, op1, XEXP (op0, 0));
+
       tem = simplify_byte_swapping_operation (code, mode, op0, op1);
       if (tem)
 	return tem;
-- 
1.8.1.4

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

* Re: [PATCH] simplify-rtx: Generalize (and X (ior (not X) Y) -> (and X Y)
       [not found] ` <CAOckXuOAECjyUg_QWRD_5wU819Odce1NUMRHY7BymY=1YhJWtg@mail.gmail.com>
@ 2014-12-30 18:50   ` Segher Boessenkool
  0 siblings, 0 replies; 3+ messages in thread
From: Segher Boessenkool @ 2014-12-30 18:50 UTC (permalink / raw)
  To: Alan Lawrence; +Cc: gcc-patches

On Mon, Dec 29, 2014 at 12:14:31PM +0000, Alan Lawrence wrote:
> Just a quick thought: will this catch e.g. (and (not X) (ior X Y))?

It doesn't (and nothing else does, either; I checked).

> That's
> equivalent to (and (not X) (ior (not (not X)) Y)), i.e. (and X' (ior (not
> X') Y)) with X'=(not X), under the assumption that (not (not X)) is
> equivalent to X. However I suspect for cases of this form, GET_CODE (XEXP
> (op1, <n>)) != NOT...?

Right.  We'd have to check that in  (and A (ior B C))  A is equal to the
NOT of B or C.  Or, we could transform it to  (ior (and A B) (and A C))
and see if that simplifies to something simpler.  Also for IOR and AND
swapped.  Dunno what other cases we miss.  I'm a bit worried about the
cost of a more general test, and how do you determine "what is simpler"
anyway, in not-so-simple cases.

Either way, my patch fixes a testsuite fail ;-)


Segher

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

* Re: [PATCH] simplify-rtx: Generalize (and X (ior (not X) Y) -> (and X Y)
  2014-12-24 17:12 [PATCH] simplify-rtx: Generalize (and X (ior (not X) Y) -> (and X Y) Segher Boessenkool
       [not found] ` <CAOckXuOAECjyUg_QWRD_5wU819Odce1NUMRHY7BymY=1YhJWtg@mail.gmail.com>
@ 2015-01-05 20:28 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2015-01-05 20:28 UTC (permalink / raw)
  To: Segher Boessenkool, gcc-patches

On 12/24/14 10:05, Segher Boessenkool wrote:
> The existing transform
>
>    (and X (ior (not X) Y) -> (and X Y)
>
> has two shortcomings: it only handles identical RTX for X, i.e. registers,
> not e.g. subregs of registers; and it only handles the case where the NOT
> is the first arm of the IOR (it can be the second arm e.g. if the first
> arm is a NOT as well).  Fix both.  This fixes gcc.dg/and-1.c on powerpc64.
>
> Bootstrapped and tested on powerpc64-linux; okay for mainline?
>
>
> Segher
>
>
> 2014-12-24  Segher Boessenkool  <segher@kernel.crashing.org>
>
> gcc/
> 	* simplify-rtx.c (simplify_binary_operation_1): Handle more cases
> 	for the "(and X (ior (not X) Y) -> (and X Y)" transform.
OK.
jeff

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

end of thread, other threads:[~2015-01-05 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-24 17:12 [PATCH] simplify-rtx: Generalize (and X (ior (not X) Y) -> (and X Y) Segher Boessenkool
     [not found] ` <CAOckXuOAECjyUg_QWRD_5wU819Odce1NUMRHY7BymY=1YhJWtg@mail.gmail.com>
2014-12-30 18:50   ` Segher Boessenkool
2015-01-05 20:28 ` 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).