public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Kito Cheng <kito.cheng@gmail.com>,
	Tsukasa OI <research_trasio@irq.a4lg.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
	Andrew Waterman <andrew@sifive.com>,
	Jim Wilson <jim.wilson.gcc@gmail.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] RISC-V: Fix Zicond ICE on large constants
Date: Mon, 4 Sep 2023 23:27:08 -0600	[thread overview]
Message-ID: <c040fb0a-0b9f-4e86-8102-292daf3a659c@gmail.com> (raw)
In-Reply-To: <CA+yXCZBMbxuMhaR=YdouRTjuAUPbM6+-m32gBri3v4jMSROMpw@mail.gmail.com>



On 9/4/23 00:45, Kito Cheng wrote:
> Maybe move the check logic a bit forward? My thought is the logic is
> already specialized into a few catalogs, (imm, imm), (imm, reg), (reg,
> reg)... and the logic you put is already in (imm, reg), but it should
> really move into (reg, reg) case IMO? and move that forward we could
> prevent add too much logic to redirect the case.
> 
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index 2db9c81ac8b..c84509c393b 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -3892,6 +3892,12 @@ riscv_expand_conditional_move (rtx dest, rtx
> op, rtx cons, rtx alt)
>           op1 = XEXP (op, 1);
>         }
> 
> +      /* CONS might not fit into a signed 12 bit immediate suitable
> +        for an addi instruction.  If that's the case, force it into
> +        a register.  */
> +      if (CONST_INT_P (cons) && !SMALL_OPERAND (INTVAL (cons)))
> +       cons = force_reg (mode, cons);
> +
>        /* 0, reg or 0, imm */
>        if (cons == CONST0_RTX (mode)
>           && (REG_P (alt)
But for the imm, imm case if we force things into regs too early, then 
we'll lose if alt - cons and cons fit in a 12 bit immediate but alt does 
not.

I think Tsukasa is on the right path here.  I should have checked 
riscv_emit_binary -- I though it handled the out-of-range constant case, 
but looking at it now, it clearly does not.

I think this implies we need a similar blob of code for the imm, imm 
case for cons.

Jeff


  reply	other threads:[~2023-09-05  5:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  0:20 Tsukasa OI
2023-09-04  6:45 ` Kito Cheng
2023-09-05  5:27   ` Jeff Law [this message]
2023-09-05  5:30     ` Tsukasa OI
2023-09-05 12:08 ` [PATCH v2] " Tsukasa OI
2023-09-06  1:22   ` Jeff Law
2023-09-06  1:59     ` Tsukasa OI

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=c040fb0a-0b9f-4e86-8102-292daf3a659c@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=andrew@sifive.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jim.wilson.gcc@gmail.com \
    --cc=kito.cheng@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=research_trasio@irq.a4lg.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).