public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vekumar at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/63949] Aarch64 instruction combiner does not optimize subsi_sxth function as expected (gcc.target/aarch64/extend.c fails)
Date: Thu, 01 Jan 2015 11:35:00 -0000	[thread overview]
Message-ID: <bug-63949-4-WkrtoRipeH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-63949-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63949

--- Comment #6 from vekumar at gcc dot gnu.org ---
In the function make_compound_operation, there a check 

      /* See if we have operations between an ASHIFTRT and an ASHIFT.
         If so, try to merge the shifts into a SIGN_EXTEND.  We could
         also do this for some cases of SIGN_EXTRACT, but it doesn't
         seem worth the effort; the case checked for occurs on Alpha.          
*/

if (!OBJECT_P (lhs)
          && ! (GET_CODE (lhs) == SUBREG
                && (OBJECT_P (SUBREG_REG (lhs))))
          && CONST_INT_P (rhs)
          && INTVAL (rhs) < HOST_BITS_PER_WIDE_INT
          && INTVAL (rhs) < mode_width
          && (new_rtx = extract_left_shift (lhs, INTVAL (rhs))) != 0)
        new_rtx = make_extraction (mode, make_compound_operation (new_rtx,
next_code),
                               0, NULL_RTX, mode_width - INTVAL (rhs),
                               code == LSHIFTRT, 0, in_code == COMPARE);

      break;



Our input RTL actually matches this case. 

For (int)i << 1  we are getting incomming RTX as 

(ashiftrt:SI (ashift:SI (reg:SI 1 x1 [ i ])
        (const_int 16 [0x10]))
    (const_int 15 [0xf]))


LHS is ashift:SI (reg:SI 1 x1 [ i ])
        (const_int 16 [0x10]) 

RHS is ashiftrt with a value of 15.

So bacially we get (i<<16)>>15, we can merge these shifts to sign_extends.

With extract_left_shift we get 

(ashift:SI (reg:SI 1 x1 [ i ])
    (const_int 1 [0x1]))

or x1<<1

When we do make_extraction with this shift pattern we get 

    (ashift:SI (sign_extend:SI (reg:HI 1 x1 [ i ]))
        (const_int 1 [0x1])))


But instead this we are the shift RTX, we are actually passing MULT RTX to
make_extraction via another make_compound_operation.

p make_compound_operation(new_rtx,MEM)
$3 = (rtx_def *) 0x7ffff77fd420
(gdb) pr
(mult:SI (reg:SI 1 x1 [ i ])
    (const_int 2 [0x2]))

Which results in 

 (subreg:SI (sign_extract:DI (mult:DI (reg:DI 1 x1 [ i ])
                (const_int 2 [0x2]))
            (const_int 17 [0x11])
            (const_int 0 [0])) 0)

When I changed the original check to

--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -7896,7 +7896,7 @@ make_compound_operation (rtx x, enum rtx_code in_code)
          && INTVAL (rhs) < HOST_BITS_PER_WIDE_INT
          && INTVAL (rhs) < mode_width
          && (new_rtx = extract_left_shift (lhs, INTVAL (rhs))) != 0)
-       new_rtx = make_extraction (mode, make_compound_operation (new_rtx,
next_
+       new_rtx = make_extraction (mode, new_rtx,
                               0, NULL_RTX, mode_width - INTVAL (rhs),
                               code == LSHIFTRT, 0, in_code == COMPARE)

Combiner was able to match the pattern successfully.

Trying 8 -> 13:
Successfully matched this instruction:
(set (reg/i:SI 0 x0)
    (minus:SI (reg:SI 0 x0 [ a ])
        (ashift:SI (sign_extend:SI (reg:HI 1 x1 [ i ]))
            (const_int 1 [0x1]))))
(minus:SI (reg:SI 0 x0 [ a ])
    (ashift:SI (sign_extend:SI (reg:HI 1 x1 [ i ]))

Any comments about this change?
        (const_int 1 [0x1])))


  parent reply	other threads:[~2015-01-01 11:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-19 10:23 [Bug target/63949] New: Aarch64 instruction combiner does not optimize subsi_sxth function as expected vekumar at gcc dot gnu.org
2014-11-19 12:05 ` [Bug target/63949] " ktkachov at gcc dot gnu.org
2014-11-19 17:20 ` pinskia at gcc dot gnu.org
2014-11-22 10:27 ` [Bug target/63949] Aarch64 instruction combiner does not optimize subsi_sxth function as expected (gcc.target/aarch64/extend.c fails) rearnsha at gcc dot gnu.org
2014-12-19 11:28 ` vekumar at gcc dot gnu.org
2014-12-19 11:52 ` vekumar at gcc dot gnu.org
2015-01-01 11:35 ` vekumar at gcc dot gnu.org [this message]
2015-01-02 13:38 ` vekumar at gcc dot gnu.org
2015-01-06  8:13 ` vekumar at gcc dot gnu.org
2015-01-08 12:07 ` segher at gcc dot gnu.org
2015-01-15 10:56 ` ramana at gcc dot gnu.org
2015-01-15 10:57 ` pinskia at gcc dot gnu.org
2015-05-26 16:36 ` vekumar at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-63949-4-WkrtoRipeH@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).