public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mohamed Shafi <shafitvm@gmail.com>
To: Richard Henderson <rth@redhat.com>
Cc: GCC <gcc@gcc.gnu.org>
Subject: Re: How to write shift and add pattern?
Date: Fri, 06 Nov 2009 13:30:00 -0000	[thread overview]
Message-ID: <ba0bd44d0911060529r5f6b9a3al83a8dea954a836a5@mail.gmail.com> (raw)
In-Reply-To: <4A97E98C.8040009@redhat.com>

2009/8/28 Richard Henderson <rth@redhat.com>:
> On 08/28/2009 06:51 AM, Mohamed Shafi wrote:
>>
>> Hello all,
>>
>> I am trying to port a 32bit arch in GCC 4.4.0. My target has support
>> for 1bit, 2bit shift and add operations. I tried to write patterns for
>> this , but gcc is not generating those. The following are the patterns
>> that i have written in md file:
>>
>> (define_insn "shift_add_<mode>"
>>  [(set (match_operand:SI 0 "register_operand" "")
>>        (plus:SI (match_operand:SI 3 "register_operand" "")
>>                  (ashift:SI (match_operand:SI 1 "register_operand" "")
>>                              (match_operand:SI 2 "immediate_operand"
>> ""))))]
>>  ""
>>  "shadd1\\t%1, %0"
>> )
>
> ...
>> Is GCC generating patterns with multiply due to
>> cost issues? I havent mentioned any cost details.
>
> No, it's merely using multiply because someone way back when
> decided that should be the canonical way to represent this.
> We canonicalize patterns so that the target file doesn't have
> to match both shifts and multiplies.
>
> So your insn should look like:
>
> (define_insn "*shadd1_si"
>  [(set (match_operand:SI 0 "register_operand" "r")
>        (plus:SI (mult:SI (match_operand:SI "register_operand" "r")
>                          (const_int 2))
>                 (match_operand:SI "register_operand" "0")))]
>  ""
>  "shadd1 %1,%0")
>
> This should match even if your target doesn't support a
> hardware multiply insn.
>
> See also the shift-add patterns on the Alpha port.  There we
> have 2 & 3 bit shifts.  Search for const48_operand to find
> those patterns easily.
>
    The target that i am working on has 1 & 2 bit shift-add patterns.
GCC is not generating shift-add patterns when the shift count is 1. It
is currently generating add operations. What should be done to
generate shift-add pattern instead of add-add pattern?

Another issue is that shift-add pattern will work only with address
registers. So if i have constraints for only address register in the
pattern there will be cases when the normal shift and add instructions
are more profitable than reloading into address registers and doing
sift-add instruction. Am i right ? So what i did was to have both
address register and data registers as constraints and then have a
define split after reload to split shift-add to shift and add when
registers are data registers. But the problem is i cant make the
allocator to allocate address registers for simple cases.

For the following program

extern int a, b;

int foo ()
{
  a = a + (b << 2) ;
  return a;
}

the complier should generate with address registers so that shift-add
pattern can be used. But i cant make the compiler to generate those.
It is generating with data registers. Here is the pattern that i have
written:


(define_insn "*saddl"
  [(set (match_operand:SI 0 "register_operand" "=r,d")
	(plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r,d")
			  (match_operand:SI 2 "const24_operand" "J,J"))
		 (match_operand:SI 3 "register_operand" "0,0")))]

How can i do this. Will the constraint modifiers '?' or '!' help?
How can make GCC generate shift and add sequence when the shift count is 1?

Regards,
Shafi

  reply	other threads:[~2009-11-06 13:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28 19:56 Mohamed Shafi
2009-08-28 23:49 ` Richard Henderson
2009-11-06 13:30   ` Mohamed Shafi [this message]
2009-11-06 15:34     ` Ian Lance Taylor
2009-11-09 12:53       ` Mohamed Shafi
2009-11-09 15:26         ` Ian Lance Taylor
2009-11-06 16:17     ` Richard Henderson
2009-11-09 12:49       ` Mohamed Shafi

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=ba0bd44d0911060529r5f6b9a3al83a8dea954a836a5@mail.gmail.com \
    --to=shafitvm@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=rth@redhat.com \
    /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).