public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Mikael Pettersson <mikpelinux@gmail.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Avoid ICE on m68k -fzero-call-used-regs -fpic [PR110934]
Date: Fri, 19 Jan 2024 16:21:34 -0700	[thread overview]
Message-ID: <8a2551f1-37d3-45f8-90ad-9a17217a4a18@gmail.com> (raw)
In-Reply-To: <20240117172527.27233-1-mikpelinux@gmail.com>



On 1/17/24 10:03, Mikael Pettersson wrote:
> PR110934 is a problem on m68k where -fzero-call-used-regs -fpic ICEs
> when clearing an FP register.
> 
> The generic code generates an XFmode move of zero to that register,
> which becomes an XFmode load from initialized data, which due to -fpic
> uses a non-constant address, which the backend rejects.  The
> zero-call-used-regs pass runs very late, after register allocation and
> frame layout, and at that point we can't allow new uses of the PIC
> register or new pseudos.
> 
> To clear an FP register on m68k it's enough to do the move in SFmode,
> but the generic code can't be told to do that, so this patch updates
> m68k to use its own TARGET_ZERO_CALL_USED_REGS.
> 
> Bootstrapped and regression tested on m68k-linux-gnu.
> 
> Ok for master? (I don't have commit rights.)
We can certainly have new uses of the PIC register after reload.  What 
we can't do is allocate a new scratch register after reload to hold the 
address of the object from the GOT.  It's a subtle difference.

Because we're zeroing call used registers and we only do this at return 
points, we could (in theory) use one of the call-used address registers 
as a scratch.  Doing that requires (AFAICT) defining the same target 
hook you're using, so it's not any cleaner from that point of view.

> 

> +/* Implement TARGET_ZERO_CALL_USED_REGS.  */
> +
> +static HARD_REG_SET
> +m68k_zero_call_used_regs (HARD_REG_SET need_zeroed_hardregs)
> +{
> +  rtx zero_fpreg = NULL_RTX;
> +
> +  for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
> +    if (TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
> +      {
> +	rtx reg, zero;
> +
> +	if (INT_REGNO_P (regno))
> +	  {
> +	    reg = regno_reg_rtx[regno];
> +	    zero = CONST0_RTX (SImode);
> +	  }
> +	else if (FP_REGNO_P (regno))
> +	  {
> +	    reg = gen_raw_REG (SFmode, regno);
> +	    if (zero_fpreg == NULL_RTX)
> +	      {
> +		/* On the 040/060 clearing an FP reg loads a large
> +		   immediate.  To reduce code size use the first
> +		   cleared FP reg to clear remaing ones.  Don't do
Minor typo.  s/remaing/remaining/

I'll fix that and push the patch to the trunk.  It's as clean as other 
approaches I pondered would likely be.

Jeff

      reply	other threads:[~2024-01-19 23:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17 17:03 Mikael Pettersson
2024-01-19 23:21 ` Jeff Law [this message]

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=8a2551f1-37d3-45f8-90ad-9a17217a4a18@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mikpelinux@gmail.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).