public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Koning <paulkoning@comcast.net>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: GCC Development <gcc@gcc.gnu.org>
Subject: Re: How do I stop gcc from loading data into registers when that's not needed?
Date: Wed, 23 May 2018 00:50:00 -0000	[thread overview]
Message-ID: <50B057F6-F0AB-4213-91DE-2A988C72436F@comcast.net> (raw)
In-Reply-To: <20180522192609.GQ17342@gate.crashing.org>



> On May 22, 2018, at 3:26 PM, Segher Boessenkool <segher@kernel.crashing.org> wrote:
> 
> 
> -fdump-rtl-combine-all (or just -da or -dap), and then look at the dump
> file.  Does combine try this combination?  If so, it will tell you what
> the resulting costs are.  If not, why does it not try it?
> 
>> Sorry, I'm not very familiar with this area of GCC either.  Did you confirm
>> that combine at least tries to merge the memory ops into the instruction?
> 
> It should, it's a simple reg dependency.  In many cases it will even do
> it if it is not single-use (via a 3->2 combination).

I examined what gcc does with two simple functions:

void c2(void)
{
    if (x < y)
        z = 1;
    else if (x != y)
        z = 42;
    else
        z = 9;
}

void c3(void)
{
    if (x < y)
        z = 1;
    else
        z = 9;
}

Two things popped out.

1. The original RTL (from the expand phase) has a memory->register move for x and y in c2, but it doesn't for c3 (it simply generates a memory/memory compare there).  What triggers the different choice in that phase?

2. The reported costs for the various insns are
	r22:HI=['x']		6
	cmp(r22:HI,r23:HI)	4
	cmp(['x'],['y'])	16
   so the added cost for the memory argument in the cmp is 6 -- the same as the whole cost for the mov.  That certainly explains the behavior.  It isn't what I want it to be.  Which target hook(s) are involved in these numbers?  I don't see them in my rtx_costs hook.

	paul

  reply	other threads:[~2018-05-23  0:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 18:03 Paul Koning
2018-05-18 18:07 ` Richard Biener
     [not found]   ` <018C29D6-6245-4D31-B43B-623E080A6F87@comcast.net>
2018-05-22  8:49     ` Richard Biener
2018-05-22 19:26       ` Segher Boessenkool
2018-05-23  0:50         ` Paul Koning [this message]
2018-05-23  9:47           ` Richard Biener
2018-05-24  0:33             ` Paul Koning
2018-05-24 18:25               ` Segher Boessenkool

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=50B057F6-F0AB-4213-91DE-2A988C72436F@comcast.net \
    --to=paulkoning@comcast.net \
    --cc=gcc@gcc.gnu.org \
    --cc=segher@kernel.crashing.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).