public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] combine: Handle zero_extend without subreg in change_zero_ext.
@ 2017-01-05 16:46 Dominik Vogt
  2017-01-11 18:02 ` Segher Boessenkool
  2017-01-12 17:02 ` Segher Boessenkool
  0 siblings, 2 replies; 6+ messages in thread
From: Dominik Vogt @ 2017-01-05 16:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Segher Boessenkool

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

The attached patch deals with another type of zero_extend that is
not yet handled in change_zero_ext, i.e. (zero_extend
(pseudoreg)), without a "subreg" in between.  What do you think?
(Mostly untested yet.)

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0001-combine-Handle-zero_extend-without-subreg-in-change_.patch --]
[-- Type: text/plain, Size: 1156 bytes --]

From 36be099953903aa16ec1f307f0018a3e537638a5 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Thu, 5 Jan 2017 17:37:37 +0100
Subject: [PATCH] combine: Handle zero_extend without subreg in
 change_zero_ext.

Try replacing

  (zero_extend (reg))

with

  (and (subreg (reg) 0)
       (const_int))
---
 gcc/combine.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/combine.c b/gcc/combine.c
index e77f203..b5131b8 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -11372,6 +11372,16 @@ change_zero_ext_src (subrtx_ptr_iterator *piter)
   else if (GET_CODE (x) == ZERO_EXTEND
 	   && SCALAR_INT_MODE_P (mode)
 	   && REG_P (XEXP (x, 0))
+	   && !HARD_REGISTER_P (XEXP (x, 0))
+	   && GET_MODE_PRECISION (GET_MODE (XEXP (x, 0)))
+	      < GET_MODE_PRECISION (mode))
+    {
+      /* (zero_extract (reg)) -> (and (subreg (reg) 0) (const_int)) */
+      x = gen_lowpart_SUBREG (mode, XEXP (x, 0));
+    }
+  else if (GET_CODE (x) == ZERO_EXTEND
+	   && SCALAR_INT_MODE_P (mode)
+	   && REG_P (XEXP (x, 0))
 	   && HARD_REGISTER_P (XEXP (x, 0))
 	   && can_change_dest_mode (XEXP (x, 0), 0, mode))
     {
-- 
2.3.0


[-- Attachment #3: 0001-ChangeLog --]
[-- Type: text/plain, Size: 104 bytes --]

gcc/ChangeLog-change_zero_ext-5

	* combine.c (change_zero_ext_src): Handle zero_extend without subreg.

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

* Re: [RFC] combine: Handle zero_extend without subreg in change_zero_ext.
  2017-01-05 16:46 [RFC] combine: Handle zero_extend without subreg in change_zero_ext Dominik Vogt
@ 2017-01-11 18:02 ` Segher Boessenkool
  2017-01-12 10:24   ` Dominik Vogt
  2017-01-12 17:02 ` Segher Boessenkool
  1 sibling, 1 reply; 6+ messages in thread
From: Segher Boessenkool @ 2017-01-11 18:02 UTC (permalink / raw)
  To: vogt, gcc-patches

On Thu, Jan 05, 2017 at 05:46:51PM +0100, Dominik Vogt wrote:
> The attached patch deals with another type of zero_extend that is
> not yet handled in change_zero_ext, i.e. (zero_extend
> (pseudoreg)), without a "subreg" in between.  What do you think?
> (Mostly untested yet.)

My main question is: where is this useful?  Can you show some example
please?


Segher

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

* Re: [RFC] combine: Handle zero_extend without subreg in change_zero_ext.
  2017-01-11 18:02 ` Segher Boessenkool
@ 2017-01-12 10:24   ` Dominik Vogt
  0 siblings, 0 replies; 6+ messages in thread
From: Dominik Vogt @ 2017-01-12 10:24 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-patches

On Wed, Jan 11, 2017 at 12:02:40PM -0600, Segher Boessenkool wrote:
> On Thu, Jan 05, 2017 at 05:46:51PM +0100, Dominik Vogt wrote:
> > The attached patch deals with another type of zero_extend that is
> > not yet handled in change_zero_ext, i.e. (zero_extend
> > (pseudoreg)), without a "subreg" in between.  What do you think?
> > (Mostly untested yet.)
> 
> My main question is: where is this useful?  Can you show some example
> please?

With this test program:

  int foo (int *b)
  {
    int i;
    int r;
    for (i = 0; i < 77; i++)
    {
      r |= b[0] > 0;
      r |= b[i] > 0;
    }
    return r;
  }

before combine we have

  (insn 47 45 48 7 (set (reg:SI 104)
          (zero_extend:SI (reg:QI 103)))
  (insn 48 47 49 7 (parallel [
              (set (reg/v:SI 88 [ r ])
                  (ior:SI (reg/v:SI 88 [ r ])
                      (reg:SI 104)))
              (clobber (reg:CC 33 %cc))
          ])

combine tries

  (set (reg/v:SI 88 [ r ])
      (ior:SI (zero_extend:SI (reg:QI 103))
          (reg/v:SI 88 [ r ])))

With the patch it also tries

(set (reg/v:SI 88 [ r ])
    (ior:SI (and:SI (subreg:SI (reg:QI 103) 0)
            (const_int -1 [0xffffffffffffffff]))
        (reg/v:SI 88 [ r ])))

which is just one of the standard patterns for rosbg.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

* Re: [RFC] combine: Handle zero_extend without subreg in change_zero_ext.
  2017-01-05 16:46 [RFC] combine: Handle zero_extend without subreg in change_zero_ext Dominik Vogt
  2017-01-11 18:02 ` Segher Boessenkool
@ 2017-01-12 17:02 ` Segher Boessenkool
  2017-01-12 18:28   ` Dominik Vogt
  2017-01-23  9:01   ` Dominik Vogt
  1 sibling, 2 replies; 6+ messages in thread
From: Segher Boessenkool @ 2017-01-12 17:02 UTC (permalink / raw)
  To: vogt, gcc-patches

Hi Dominik,

Thanks for the example.  ROSBG, what a weird instruction.

On Thu, Jan 05, 2017 at 05:46:51PM +0100, Dominik Vogt wrote:
> --- a/gcc/combine.c
> +++ b/gcc/combine.c
> @@ -11372,6 +11372,16 @@ change_zero_ext_src (subrtx_ptr_iterator *piter)
>    else if (GET_CODE (x) == ZERO_EXTEND
>  	   && SCALAR_INT_MODE_P (mode)
>  	   && REG_P (XEXP (x, 0))
> +	   && !HARD_REGISTER_P (XEXP (x, 0))
> +	   && GET_MODE_PRECISION (GET_MODE (XEXP (x, 0)))
> +	      < GET_MODE_PRECISION (mode))
> +    {
> +      /* (zero_extract (reg)) -> (and (subreg (reg) 0) (const_int)) */

s/zero_extract/zero_extend/

> 	* combine.c (change_zero_ext_src): Handle zero_extend without subreg.

"Handle zero_extend of a pseudo."?

Okay for trunk with that.  Thanks for the patch,


Segher

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

* Re: [RFC] combine: Handle zero_extend without subreg in change_zero_ext.
  2017-01-12 17:02 ` Segher Boessenkool
@ 2017-01-12 18:28   ` Dominik Vogt
  2017-01-23  9:01   ` Dominik Vogt
  1 sibling, 0 replies; 6+ messages in thread
From: Dominik Vogt @ 2017-01-12 18:28 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-patches

On Thu, Jan 12, 2017 at 11:02:36AM -0600, Segher Boessenkool wrote:
> Hi Dominik,
> 
> Thanks for the example.  ROSBG, what a weird instruction.
> 
> On Thu, Jan 05, 2017 at 05:46:51PM +0100, Dominik Vogt wrote:
> > --- a/gcc/combine.c
> > +++ b/gcc/combine.c
> > @@ -11372,6 +11372,16 @@ change_zero_ext_src (subrtx_ptr_iterator *piter)
> >    else if (GET_CODE (x) == ZERO_EXTEND
> >  	   && SCALAR_INT_MODE_P (mode)
> >  	   && REG_P (XEXP (x, 0))
> > +	   && !HARD_REGISTER_P (XEXP (x, 0))
> > +	   && GET_MODE_PRECISION (GET_MODE (XEXP (x, 0)))
> > +	      < GET_MODE_PRECISION (mode))
> > +    {
> > +      /* (zero_extract (reg)) -> (and (subreg (reg) 0) (const_int)) */
> 
> s/zero_extract/zero_extend/
> 
> > 	* combine.c (change_zero_ext_src): Handle zero_extend without subreg.
> 
> "Handle zero_extend of a pseudo."?

k

> Okay for trunk with that.

It still needs testing.  I'll do that in a while.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

* Re: [RFC] combine: Handle zero_extend without subreg in change_zero_ext.
  2017-01-12 17:02 ` Segher Boessenkool
  2017-01-12 18:28   ` Dominik Vogt
@ 2017-01-23  9:01   ` Dominik Vogt
  1 sibling, 0 replies; 6+ messages in thread
From: Dominik Vogt @ 2017-01-23  9:01 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-patches

On Thu, Jan 12, 2017 at 11:02:36AM -0600, Segher Boessenkool wrote:
> Thanks for the example.  ROSBG, what a weird instruction.

And it's annoying too because it does the same as RISBG in some
cases and can confuse "combine" to take a different branch that
turns out to be a dead end.

> On Thu, Jan 05, 2017 at 05:46:51PM +0100, Dominik Vogt wrote:
> > --- a/gcc/combine.c
> > +++ b/gcc/combine.c
> > @@ -11372,6 +11372,16 @@ change_zero_ext_src (subrtx_ptr_iterator *piter)
> >    else if (GET_CODE (x) == ZERO_EXTEND
> >  	   && SCALAR_INT_MODE_P (mode)
> >  	   && REG_P (XEXP (x, 0))
> > +	   && !HARD_REGISTER_P (XEXP (x, 0))
> > +	   && GET_MODE_PRECISION (GET_MODE (XEXP (x, 0)))
> > +	      < GET_MODE_PRECISION (mode))
> > +    {
> > +      /* (zero_extract (reg)) -> (and (subreg (reg) 0) (const_int)) */
> 
> s/zero_extract/zero_extend/
> 
> > 	* combine.c (change_zero_ext_src): Handle zero_extend without subreg.
> 
> "Handle zero_extend of a pseudo."?
> 
> Okay for trunk with that.  Thanks for the patch,

The patch forgot to set "size" and generated invalid Rtl because
of that.  Fixed and tested, but I'd prefer to repost my growing
stack of patches when gcc-7 is released.  There are too many
changes in "combine" and "simplify" that may depend on each other.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

end of thread, other threads:[~2017-01-23  8:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-05 16:46 [RFC] combine: Handle zero_extend without subreg in change_zero_ext Dominik Vogt
2017-01-11 18:02 ` Segher Boessenkool
2017-01-12 10:24   ` Dominik Vogt
2017-01-12 17:02 ` Segher Boessenkool
2017-01-12 18:28   ` Dominik Vogt
2017-01-23  9:01   ` Dominik Vogt

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).