public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: "Peryt, Sebastian" <sebastian.peryt@intel.com>,
	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: Question regarding preventing optimizing out of register in expansion
Date: Thu, 21 Jun 2018 13:12:00 -0000	[thread overview]
Message-ID: <568618ea-c8e3-c44a-5b48-89a8623bc29d@acm.org> (raw)
In-Reply-To: <17623B198193D741876BD81A6E3AE5AD3C7B98EE@irsmsx111.ger.corp.intel.com>

On 06/21/2018 05:20 AM, Peryt, Sebastian wrote:
> Hi,
> 
> I'd appreciate if someone could advise me in builtin expansion I'm currently writing.
> 
> High level description for what I want to do:
> 
> I have 2 operands in my builtin.

IIUC you're defining an UNSPEC.

> First I set register (reg1) with value from operand1 (op1);
> Second I call my instruction (reg1 is called implicitly and updated);

Here is your error -- NEVER have implicit register settings.  The data 
flow analysers need accurate information.


> Simplified implementation in i386.c I have:
> 
> reg1 = gen_reg_rtx (mode);
> emit_insn (gen_rtx_SET (reg1, op1); 
> emit_clobber (reg1);

At this point reg1 is dead.  That means the previous set of reg1 from 
op1 is unneeded and can be deleted.

> emit_insn (gen_myinstruction ());

This instruction has no inputs or outputs, and is not marked volatile(?) 
so can be deleted.

> emit_insn (gen_rtx_SET (op2,reg1));

And this is storing a value from a dead register.

You need something like:
   rtx reg1 = force_reg (op1);
   rtx reg2 = gen_reg_rtx (mode);
   emit_insn (gen_my_insn (reg2, reg1));
   emit insn (gen_rtx_SET (op2, reg2));

your instruction should be an UNSPEC showing what the inputs and outputs 
are.  That tells the optimizers what depends on what, but the compiler 
has no clue about what the transform is.

nathan
-- 
Nathan Sidwell

  reply	other threads:[~2018-06-21 11:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21 11:42 Peryt, Sebastian
2018-06-21 13:12 ` Nathan Sidwell [this message]
2018-06-21 14:06   ` Peryt, Sebastian
2018-06-26  9:26   ` Peryt, Sebastian
2018-06-26 19:20     ` Peter Bergner
2018-06-26 19:46       ` Peryt, Sebastian
2018-06-27 10:26         ` Jeff Law

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=568618ea-c8e3-c44a-5b48-89a8623bc29d@acm.org \
    --to=nathan@acm.org \
    --cc=gcc@gcc.gnu.org \
    --cc=sebastian.peryt@intel.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).